#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;

int v = 10;
vector <vector<int>> adjecancy(v + 1); 

void addEdge(int x,int y) 
{
	adjecancy[x].push_back(y);
	adjecancy[y].push_back(x);
}

int mx, at;

void dfs(int v,int p,int cost)
{
	if (cost > mx)
	{
		mx = cost;
		at = v;
	}

	for (int i : adjecancy[v])
		if (i!=p)
			dfs(i,v,cost+1);

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int n;
	cin >> n;
	int x, y;
	
	while (n--)
	{
		cin >> x >> y;
		addEdge(x, y);
	}

	mx = -1, at = -1;
	dfs(1,-1,0);
	int from = at;

	mx = -1, at = -1;
	dfs(from,-1,0);
	int to = at;

	cout << "the longest pathe = " << mx << endl 
		 << "from node " << from << " to node " << to;

}
