#include <bits/stdc++.h>
#define int long long
#define USE_FREOPEN
//#define MUL_TEST
#define FILENAME "query"
using namespace std;
int dep[500005];
vector<int> G[500005];
int deg[500005];

void dfs(int x,int fa)
{
	dep[x] = dep[fa] + 1;
	int l = G[x].size();
	for (int i = 0; i < l; i++)
		if (G[x][i] != fa)
			dfs(G[x][i],x);
}

void solve()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int u,v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
		deg[u]++;deg[v]++;
	}
	bool flag = 1;
	if (deg[1] != 1) flag = 0;
	for (int i = 2; i <= n; i++)
		if (deg[i] != 2)
		{
			flag = 0;
			break;
		}
	if (flag)
	{
		dfs(1,0);
	}
}

signed main()
{
	#ifdef USE_FREOPEN
		freopen(FILENAME ".in","r",stdin);
		freopen(FILENAME ".out","w",stdout);
	#endif
	int _ = 1;
	#ifdef MUL_TEST
		cin >> _;
	#endif
	while (_--)
		solve();
	_^=_;
	return (0^_^0);
}

