#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c2V0Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IHYgPSAxMDsKdmVjdG9yIDx2ZWN0b3I8aW50Pj4gYWRqZWNhbmN5KHYgKyAxKTsgCgp2b2lkIGFkZEVkZ2UoaW50IHgsaW50IHkpIAp7CglhZGplY2FuY3lbeF0ucHVzaF9iYWNrKHkpOwoJYWRqZWNhbmN5W3ldLnB1c2hfYmFjayh4KTsKfQoKaW50IG14LCBhdDsKCnZvaWQgZGZzKGludCB2LGludCBwLGludCBjb3N0KQp7CglpZiAoY29zdCA+IG14KQoJewoJCW14ID0gY29zdDsKCQlhdCA9IHY7Cgl9CgoJZm9yIChpbnQgaSA6IGFkamVjYW5jeVt2XSkKCQlpZiAoaSE9cCkKCQkJZGZzKGksdixjb3N0KzEpOwoKfQoKaW50IG1haW4oKQp7Cglpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CgljaW4udGllKDApOyBjb3V0LnRpZSgwKTsKCglpbnQgbjsKCWNpbiA+PiBuOwoJaW50IHgsIHk7CgkKCXdoaWxlIChuLS0pCgl7CgkJY2luID4+IHggPj4geTsKCQlhZGRFZGdlKHgsIHkpOwoJfQoKCW14ID0gLTEsIGF0ID0gLTE7CglkZnMoMSwtMSwwKTsKCWludCBmcm9tID0gYXQ7CgoJbXggPSAtMSwgYXQgPSAtMTsKCWRmcyhmcm9tLC0xLDApOwoJaW50IHRvID0gYXQ7CgoJY291dCA8PCAidGhlIGxvbmdlc3QgcGF0aGUgPSAiIDw8IG14IDw8IGVuZGwgCgkJIDw8ICJmcm9tIG5vZGUgIiA8PCBmcm9tIDw8ICIgdG8gbm9kZSAiIDw8IHRvOwoKfQo=