C++ 代码
#include <iostream>
#include <vector>
using namespace std;
int n;
vector<vector<int>> d;
int dfs(int i, int p){
int res = 0;
for(auto x: d[i])
if(x != p){
res += dfs(x, i);
}
return res + 1;
}
int main()
{
cin >> n;
d.resize(n + 1);
for(int i = 1; i < n; ++ i) {
int x, y;
cin >> x >> y;
d[x].push_back(y);
d[y].push_back(x);
}
int ret = 0;
for(auto& x : d[1])
ret = max(ret, dfs(x, 1));
cout << ret << endl;
return 0;
}