标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3949 | Accepted: 2375 |
10
1 2
2 3
3 4
4 5
6 7
7 8
8 9
9 10
3 8
3
8
#include <iostream> #include <cstdio> #include <cstring> #define REP(i, s, n) for(int i = s; i <= n; i ++) #define REP_(i, s, n) for(int i = n; i >= s; i --) #define MAX_N 10000 + 10 using namespace std; int n, u, v; struct node1{int v, next;} E[MAX_N << 1]; struct node2{int sum, cnt;} N[MAX_N]; int head[MAX_N], top = 0; void add(int u, int v){ E[++ top].v = v; E[top].next = head[u]; head[u] = top; } int Gao(int x, int last){ N[x].sum = 1; N[x].cnt = 0; for(int i = head[x]; i; i = E[i].next){ if(E[i].v != last){ int t = Gao(E[i].v, x); N[x].sum += t; N[x].cnt = max(N[x].cnt, t); } } return N[x].sum; } int main(){ scanf("%d", &n); REP(i, 1, n - 1){ scanf("%d%d", &u, &v); add(u, v); add(v, u); } Gao(1, 0); int res = 99999999; REP(i, 1, n){ N[i].cnt = max(N[i].cnt, n - N[i].sum); if(res > N[i].cnt) res = N[i].cnt; } if(res <= n / 2){ REP(i, 1, n) if(N[i].cnt == res) printf("%d\n", i); } else printf("NONE\n"); return 0; }
标签:
原文地址:http://www.cnblogs.com/ALXPCUN/p/4567054.html