#include <bits/stdc++.h>
#define SIZE 200005
#define BT 21
using namespace std;
typedef pair <int, int> P;
vector <int> vec[SIZE];
vector <int> vt[SIZE];
int nd[SIZE], ans[SIZE];
P centroid(int v, int p, int all) {
P ret = P(all, v);
int mx = 0;
nd[v] = 1;
for(int i=0; i < vec[v].size(); i++) {
int to = vec[v][i];
if(to != p) {
ret = min(ret, centroid(to, v, all));
nd[v] += nd[to];
mx = max(mx, nd[to]);
}
}
mx = max(mx, all - nd[v]);
ret = min(ret, P(mx, v));
return ret;
}
int par[SIZE][BT], dep[SIZE];
void dfs(int v, int p, int d) {
dep[v] = d;
par[v][0] = p;
nd[v] = 1;
for(int i = 0; i < vec[v].size(); i++) {
int to = vec[v][i];
if(to != p) {
dfs(to, v, d + 1);
nd[v] += nd[to];
}
}
}
void build(int n) {
for(int i = 0; i + 1 < BT; i++) {
for(int j = 0; j < n; j++) {
if(par[j][i] != -1) par[j][i + 1] = par[par[j][i]][i];
else par[j][i + 1] = -1;
}
}
}
int LCA(int a, int b) {
if(dep[a] > dep[b]) swap(a, b);
for(int i = BT - 1; i >= 0; i--) {
if(par[b][i] != -1 && dep[par[b][i]] >= dep[a]) b = par[b][i];
}
if(a == b) return a;
for(int i = BT - 1; i >= 0; i--) {
if(par[a][i] != par[b][i]) {
a = par[a][i], b = par[b][i];
}
}
return par[a][0];
}
int dist(int a, int b) {
return dep[a] + dep[b] - 2 * dep[LCA(a, b)];
}
int main() {
int n;
scanf("%d", &n);
for(int i = 0; i < n - 1; i++) {
int a, b;
scanf("%d %d", &a, &b);
a--, b--;
vec[a].push_back(b);
vec[b].push_back(a);
}
int rt = centroid(0, -1, n).second;
dfs(rt, -1, 0);
build(n);
for(int i = 0; i < n; i++) vt[nd[i]].push_back(i);
int a = rt, b = rt, c = 0;
for(int i = n / 2; i >= 1; i--) {
for(int j = 0; j < vt[i].size(); j++) {
int v = vt[i][j];
int d = dist(a, v), e = dist(b, v);
if(c < d) b = v, c = d;
else if(c < e) a = v, c = e;
}
ans[i] = c;
}
for(int i = 1; i <= n; i++) {
if(i % 2 == 1) printf("%d\n", 1);
else printf("%d\n", ans[i / 2] + 1);
}
}
Compilation message
meetings2.cpp: In function 'P centroid(int, int, int)':
meetings2.cpp:14:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i=0; i < vec[v].size(); i++) {
| ~~^~~~~~~~~~~~~~~
meetings2.cpp: In function 'void dfs(int, int, int)':
meetings2.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 0; i < vec[v].size(); i++) {
| ~~^~~~~~~~~~~~~~~
meetings2.cpp: In function 'int main()':
meetings2.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int j = 0; j < vt[i].size(); j++) {
| ~~^~~~~~~~~~~~~~
meetings2.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
65 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
meetings2.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
68 | scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
8 ms |
9708 KB |
Output is correct |
9 |
Correct |
8 ms |
9708 KB |
Output is correct |
10 |
Correct |
7 ms |
9708 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
12 |
Correct |
8 ms |
9708 KB |
Output is correct |
13 |
Correct |
7 ms |
9708 KB |
Output is correct |
14 |
Correct |
7 ms |
9708 KB |
Output is correct |
15 |
Correct |
7 ms |
9708 KB |
Output is correct |
16 |
Correct |
8 ms |
9836 KB |
Output is correct |
17 |
Correct |
7 ms |
9708 KB |
Output is correct |
18 |
Correct |
7 ms |
9708 KB |
Output is correct |
19 |
Correct |
8 ms |
9708 KB |
Output is correct |
20 |
Correct |
7 ms |
9708 KB |
Output is correct |
21 |
Correct |
7 ms |
9708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
8 ms |
9708 KB |
Output is correct |
9 |
Correct |
8 ms |
9708 KB |
Output is correct |
10 |
Correct |
7 ms |
9708 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
12 |
Correct |
8 ms |
9708 KB |
Output is correct |
13 |
Correct |
7 ms |
9708 KB |
Output is correct |
14 |
Correct |
7 ms |
9708 KB |
Output is correct |
15 |
Correct |
7 ms |
9708 KB |
Output is correct |
16 |
Correct |
8 ms |
9836 KB |
Output is correct |
17 |
Correct |
7 ms |
9708 KB |
Output is correct |
18 |
Correct |
7 ms |
9708 KB |
Output is correct |
19 |
Correct |
8 ms |
9708 KB |
Output is correct |
20 |
Correct |
7 ms |
9708 KB |
Output is correct |
21 |
Correct |
7 ms |
9708 KB |
Output is correct |
22 |
Correct |
11 ms |
10220 KB |
Output is correct |
23 |
Correct |
11 ms |
10220 KB |
Output is correct |
24 |
Correct |
11 ms |
10220 KB |
Output is correct |
25 |
Correct |
11 ms |
10220 KB |
Output is correct |
26 |
Correct |
11 ms |
10220 KB |
Output is correct |
27 |
Correct |
11 ms |
10220 KB |
Output is correct |
28 |
Correct |
11 ms |
10220 KB |
Output is correct |
29 |
Correct |
11 ms |
10220 KB |
Output is correct |
30 |
Correct |
11 ms |
10220 KB |
Output is correct |
31 |
Correct |
11 ms |
10220 KB |
Output is correct |
32 |
Correct |
11 ms |
10476 KB |
Output is correct |
33 |
Correct |
12 ms |
10604 KB |
Output is correct |
34 |
Correct |
10 ms |
10220 KB |
Output is correct |
35 |
Correct |
10 ms |
10220 KB |
Output is correct |
36 |
Correct |
11 ms |
10220 KB |
Output is correct |
37 |
Correct |
11 ms |
10220 KB |
Output is correct |
38 |
Correct |
11 ms |
10348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
8 ms |
9708 KB |
Output is correct |
9 |
Correct |
8 ms |
9708 KB |
Output is correct |
10 |
Correct |
7 ms |
9708 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
12 |
Correct |
8 ms |
9708 KB |
Output is correct |
13 |
Correct |
7 ms |
9708 KB |
Output is correct |
14 |
Correct |
7 ms |
9708 KB |
Output is correct |
15 |
Correct |
7 ms |
9708 KB |
Output is correct |
16 |
Correct |
8 ms |
9836 KB |
Output is correct |
17 |
Correct |
7 ms |
9708 KB |
Output is correct |
18 |
Correct |
7 ms |
9708 KB |
Output is correct |
19 |
Correct |
8 ms |
9708 KB |
Output is correct |
20 |
Correct |
7 ms |
9708 KB |
Output is correct |
21 |
Correct |
7 ms |
9708 KB |
Output is correct |
22 |
Correct |
11 ms |
10220 KB |
Output is correct |
23 |
Correct |
11 ms |
10220 KB |
Output is correct |
24 |
Correct |
11 ms |
10220 KB |
Output is correct |
25 |
Correct |
11 ms |
10220 KB |
Output is correct |
26 |
Correct |
11 ms |
10220 KB |
Output is correct |
27 |
Correct |
11 ms |
10220 KB |
Output is correct |
28 |
Correct |
11 ms |
10220 KB |
Output is correct |
29 |
Correct |
11 ms |
10220 KB |
Output is correct |
30 |
Correct |
11 ms |
10220 KB |
Output is correct |
31 |
Correct |
11 ms |
10220 KB |
Output is correct |
32 |
Correct |
11 ms |
10476 KB |
Output is correct |
33 |
Correct |
12 ms |
10604 KB |
Output is correct |
34 |
Correct |
10 ms |
10220 KB |
Output is correct |
35 |
Correct |
10 ms |
10220 KB |
Output is correct |
36 |
Correct |
11 ms |
10220 KB |
Output is correct |
37 |
Correct |
11 ms |
10220 KB |
Output is correct |
38 |
Correct |
11 ms |
10348 KB |
Output is correct |
39 |
Correct |
333 ms |
35688 KB |
Output is correct |
40 |
Correct |
318 ms |
34920 KB |
Output is correct |
41 |
Correct |
329 ms |
35696 KB |
Output is correct |
42 |
Correct |
330 ms |
36116 KB |
Output is correct |
43 |
Correct |
331 ms |
36096 KB |
Output is correct |
44 |
Correct |
352 ms |
35996 KB |
Output is correct |
45 |
Correct |
580 ms |
44516 KB |
Output is correct |
46 |
Correct |
447 ms |
50796 KB |
Output is correct |
47 |
Correct |
285 ms |
36448 KB |
Output is correct |
48 |
Correct |
236 ms |
36444 KB |
Output is correct |
49 |
Correct |
394 ms |
36764 KB |
Output is correct |
50 |
Correct |
240 ms |
36576 KB |
Output is correct |
51 |
Correct |
333 ms |
48100 KB |
Output is correct |