#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define X first
#define Y second
#define PB push_back
using namespace std;
const int N = 2e5 + 500;
vector < int > v[N], skp;
int boja[N], siz[N], ans[N], dep[N], bio[N];
int n, m;
void rootaj(int x, int lst, int cur = 0){
boja[x] = cur; siz[x] = 1;
dep[x] = dep[lst] + 1;
skp.PB(x);
for(int y : v[x]){
if(bio[y] || y == lst) continue;
rootaj(y, x, cur ? cur : y);
siz[x] += siz[y];
}
}
int nadi_centroid(){
int nn = (int)skp.size();
int ret = skp[0];
for(int x : skp)
if(2 * siz[x] >= nn && siz[x] < siz[ret])
ret = x;
return ret;
}
inline void update(int x, int y){
ans[x] = max(ans[x], y);
}
bool cmp(int x, int y){
return siz[x] > siz[y];
}
void obradi(int x){
rootaj(x, x, 0);
x = nadi_centroid();
skp.clear(); dep[x] = -1;
rootaj(x, x, 0);
int nn = (int)skp.size();
for(int y : skp){
if(y != x){
update(min(siz[y], nn - siz[boja[y]]), dep[y]);
}
}
skp.erase(find(skp.begin(), skp.end(), x));
sort(skp.begin(), skp.end(), cmp);
int naj = -1, najj = -1;
for(int x : skp){
if(naj == -1){
naj = x; continue;
}
else if(najj == -1 && boja[x] != boja[naj]){
najj = x;
}
else if(najj == -1 && boja[x] == boja[naj] && dep[x] > dep[naj]){
naj = x; continue;
}
else if(najj == -1 && boja[x] == boja[naj]){
continue;
}
else if(dep[x] > dep[naj] && boja[x] != boja[naj]){
najj = naj; naj = x;
}
else if(dep[x] > dep[naj] && boja[x] == boja[naj]){
naj = x;
}
else if(dep[x] > dep[najj] && boja[x] != boja[naj]){
najj = x;
}
update(min(siz[naj], siz[najj]), dep[naj] + dep[najj]);
}
skp.clear();
bio[x] = 1;
for(int y : v[x])
if(!bio[y]) obradi(y);
}
int main(){
scanf("%d", &n);
for(int i = 1;i < n;i++){
int x, y; scanf("%d%d", &x, &y);
v[x].PB(y), v[y].PB(x);
}
obradi(1);
for(int i = n;i >= 0;i--)
update(i, ans[i + 1]);
for(int i = 1;i <= n;i++){
printf("%d\n", (i & 1) ? 1 : ans[i / 2] + 1);
}
return 0;
}
Compilation message
meetings2.cpp: In function 'int main()':
meetings2.cpp:92:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
92 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
meetings2.cpp:94:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
94 | int x, y; scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
5 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
4 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
5 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
4 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
8 ms |
5196 KB |
Output is correct |
23 |
Correct |
8 ms |
5196 KB |
Output is correct |
24 |
Correct |
8 ms |
5268 KB |
Output is correct |
25 |
Correct |
8 ms |
5204 KB |
Output is correct |
26 |
Correct |
8 ms |
5308 KB |
Output is correct |
27 |
Correct |
8 ms |
5196 KB |
Output is correct |
28 |
Correct |
10 ms |
5276 KB |
Output is correct |
29 |
Correct |
8 ms |
5216 KB |
Output is correct |
30 |
Correct |
8 ms |
5272 KB |
Output is correct |
31 |
Correct |
8 ms |
5196 KB |
Output is correct |
32 |
Correct |
10 ms |
5396 KB |
Output is correct |
33 |
Correct |
11 ms |
5472 KB |
Output is correct |
34 |
Correct |
6 ms |
5272 KB |
Output is correct |
35 |
Correct |
6 ms |
5204 KB |
Output is correct |
36 |
Correct |
9 ms |
5204 KB |
Output is correct |
37 |
Correct |
6 ms |
5204 KB |
Output is correct |
38 |
Correct |
8 ms |
5332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
5 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
4 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
8 ms |
5196 KB |
Output is correct |
23 |
Correct |
8 ms |
5196 KB |
Output is correct |
24 |
Correct |
8 ms |
5268 KB |
Output is correct |
25 |
Correct |
8 ms |
5204 KB |
Output is correct |
26 |
Correct |
8 ms |
5308 KB |
Output is correct |
27 |
Correct |
8 ms |
5196 KB |
Output is correct |
28 |
Correct |
10 ms |
5276 KB |
Output is correct |
29 |
Correct |
8 ms |
5216 KB |
Output is correct |
30 |
Correct |
8 ms |
5272 KB |
Output is correct |
31 |
Correct |
8 ms |
5196 KB |
Output is correct |
32 |
Correct |
10 ms |
5396 KB |
Output is correct |
33 |
Correct |
11 ms |
5472 KB |
Output is correct |
34 |
Correct |
6 ms |
5272 KB |
Output is correct |
35 |
Correct |
6 ms |
5204 KB |
Output is correct |
36 |
Correct |
9 ms |
5204 KB |
Output is correct |
37 |
Correct |
6 ms |
5204 KB |
Output is correct |
38 |
Correct |
8 ms |
5332 KB |
Output is correct |
39 |
Correct |
608 ms |
18876 KB |
Output is correct |
40 |
Correct |
577 ms |
18716 KB |
Output is correct |
41 |
Correct |
592 ms |
18992 KB |
Output is correct |
42 |
Correct |
626 ms |
19152 KB |
Output is correct |
43 |
Correct |
594 ms |
19176 KB |
Output is correct |
44 |
Correct |
582 ms |
19176 KB |
Output is correct |
45 |
Correct |
1105 ms |
24064 KB |
Output is correct |
46 |
Correct |
1105 ms |
28128 KB |
Output is correct |
47 |
Correct |
258 ms |
19560 KB |
Output is correct |
48 |
Correct |
170 ms |
19696 KB |
Output is correct |
49 |
Correct |
598 ms |
19804 KB |
Output is correct |
50 |
Correct |
229 ms |
19680 KB |
Output is correct |
51 |
Correct |
611 ms |
27116 KB |
Output is correct |