#include <bits/stdc++.h>
const int N = 1e5 + 10, M = 2 * N, mod = 1e9 + 7;
using namespace std;
int h[N], e[M], ne[M], idx = 0;
int n, s, siz[N];
bool st[N];
void add(int x, int y){
e[idx] = y, ne[idx] = h[x], h[x] = idx ++;
}
void dfs(int u, int fa){
siz[u] = 1;
for(int i = h[u]; i != -1; i = ne[i]){
int j = e[i];
if(j == fa) continue;
dfs(j, u);
if(siz[j] > n / 2) st[u] = false;
siz[u] += siz[j];
}
if(n - siz[u] > n / 2) st[u] = false;
}
int main()
{
memset(h, -1, sizeof h);
memset(st, true, sizeof st);
cin >> n;
for(int i = 1; i < n; i ++){
int x, y;
cin >> x >> y;
add(x, y), add(y, x);
}
dfs(1, -1);
bool flag = true;
for(int i = 1; i <= n; i ++){
if(st[i]){
cout << i << endl;
flag = false;
}
}
if(flag){
puts("NONE");
}
return 0;
}
/*
3 100
1 2 3
1 2
2 3
*/
标签:idx,int,siz,Tree,ne,dfs,st,cutting
From: https://www.cnblogs.com/acwhr/p/18004801