记录编号 |
388901 |
评测结果 |
AAAAAAAA |
题目名称 |
[石门中学 2009]切割树 |
最终得分 |
100 |
用户昵称 |
kZime |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.005 s |
提交时间 |
2017-03-30 07:57:47 |
内存使用 |
0.66 MiB |
显示代码纯文本
/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <algorithm>
#define MAXN 10023
using namespace std;
inline int read() {
int k = 0, f = 1; char c = getchar();
for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
return k * f;
}
/*-----------------------------------------------------------------------------*/
int a[MAXN], ans, cnt, n, head[MAXN], s[MAXN];
struct edge {
int fr, to, ne;
edge(){;}
inline edge(int f, int t, int n) {
fr = f;
to = t;
ne = n;
}
}e[MAXN << 1];
void add_edge(int f, int t) {
e[++cnt] = edge(f, t, head[f]), head[f] = cnt;
e[++cnt] = edge(t, f, head[t]), head[t] = cnt;
}
void dp(int k, int fa) {
if(s[k]) return;
for(int i = head[k];i; i = e[i].ne) {
int to = e[i].to;
if(to == fa) continue;
dp(to, k);
s[k] += s[to];
}
s[k]++;
// printf("%d\n", s[k]);
if(n - s[k] <= n / 2) {
for(int i = head[k];i; i = e[i].ne) {
if(s[e[i].to] > n / 2) return;
}
a[ans++] = k;
}
}
int main() {
#ifndef MYLAB
freopen("treecut.in", "r", stdin);
freopen("treecut.out", "w", stdout);
#else
// freopen("in.txt", "r", stdin);
#endif
n = read();
for(int i = 1; i < n; i++) {
add_edge(read(), read());
}
dp(1, 0);
sort(a, a + ans);
for(int i = 0; i < ans; i++) {
printf("%d\n", a[i]);
}
return 0;
}