DFS 深度优先遍历
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+20;
ll a[maxn];
int n,x,y;
vector<int>t[1010];
int md=1;
void dfs(int x,int depth)
{
if(depth>md)
{
md=depth;
}
for(int i=0;i<t[x].size();i++)
{
dfs(t[x][i],depth+1);
}
}
int main()
{
cin>>n;
for(int i=0;i<n-1;i++)
{
cin>>x>>y;
t[x].push_back(y);
}
dfs(1,1);
cout<<md;
return 0;
}