#include <iostream>
#include <vector>
using namespace std;
vector <int> v;
vector <vector <int>> c;
int a;
vector <int> vis;
int r=0;
void DFS(int n,int h)
{
if(r<h) r=h;
for(int i=0;i<c[n].size();i++)
{
if(vis[c[n][i]]==0)
{
vis[c[n][i]]=1;
DFS(c[n][i],h+1);
}
}
}
int main() {
int x,y;
cin >>a;
v.resize(a+1);
c.resize(a+1);
vis.resize(a+1,0);
for(int i=1;i<a;i++)
{
cin >>x>>y;
c[x].push_back(y);
c[y].push_back(x);
}
vis[1]=1;
DFS(1,0);
cout<<r;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: