#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> g[n + 1];
for (int i = 1; i < n; i++){
int x, y; cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
vector<vector<int>> dist(n + 1, vector<int>(n + 1));
function<void(int, int, int, int&)> fill = [&](int v, int pr, int d, int& u){
dist[u][v] = d++;
for (int i: g[v]){
if (i == pr) continue;
fill(i, v, d, u);
}
};
for (int i = 1; i <= n; i++) fill(i, 0, 0, i);
vector<vector<int>> sz(n + 1, vector<int>(n + 1));
function<void(int, int, int&)> fill_sz = [&](int v, int pr, int& u){
sz[u][v] = 1;
for (int i: g[v]){
if (i == pr) continue;
fill_sz(i, v, u);
sz[u][v] += sz[u][i];
}
};
for (int i = 1; i <= n; i++) fill_sz(i, 0, i);
vector<int> p(n + 1, 1);
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
int s = min(sz[i][j], sz[j][i]);
p[s] = max(p[s], dist[i][j] + 1);
}
}
for (int i = n - 1; i > 0; i--) p[i] = max(p[i], p[i + 1]);
for (int x = 1; x <= n; x++){
if (x % 2){
cout<<1<<"\n";
continue;
}
cout<<p[x / 2]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
376 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
376 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
540 ms |
125348 KB |
Output is correct |
23 |
Correct |
519 ms |
125308 KB |
Output is correct |
24 |
Correct |
522 ms |
122704 KB |
Output is correct |
25 |
Correct |
492 ms |
123696 KB |
Output is correct |
26 |
Correct |
484 ms |
122960 KB |
Output is correct |
27 |
Correct |
519 ms |
126292 KB |
Output is correct |
28 |
Correct |
534 ms |
126292 KB |
Output is correct |
29 |
Correct |
575 ms |
126548 KB |
Output is correct |
30 |
Correct |
541 ms |
126288 KB |
Output is correct |
31 |
Correct |
650 ms |
126292 KB |
Output is correct |
32 |
Correct |
617 ms |
126292 KB |
Output is correct |
33 |
Correct |
632 ms |
126548 KB |
Output is correct |
34 |
Correct |
519 ms |
126216 KB |
Output is correct |
35 |
Correct |
502 ms |
126292 KB |
Output is correct |
36 |
Correct |
545 ms |
126292 KB |
Output is correct |
37 |
Correct |
500 ms |
126236 KB |
Output is correct |
38 |
Correct |
560 ms |
126292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
376 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
540 ms |
125348 KB |
Output is correct |
23 |
Correct |
519 ms |
125308 KB |
Output is correct |
24 |
Correct |
522 ms |
122704 KB |
Output is correct |
25 |
Correct |
492 ms |
123696 KB |
Output is correct |
26 |
Correct |
484 ms |
122960 KB |
Output is correct |
27 |
Correct |
519 ms |
126292 KB |
Output is correct |
28 |
Correct |
534 ms |
126292 KB |
Output is correct |
29 |
Correct |
575 ms |
126548 KB |
Output is correct |
30 |
Correct |
541 ms |
126288 KB |
Output is correct |
31 |
Correct |
650 ms |
126292 KB |
Output is correct |
32 |
Correct |
617 ms |
126292 KB |
Output is correct |
33 |
Correct |
632 ms |
126548 KB |
Output is correct |
34 |
Correct |
519 ms |
126216 KB |
Output is correct |
35 |
Correct |
502 ms |
126292 KB |
Output is correct |
36 |
Correct |
545 ms |
126292 KB |
Output is correct |
37 |
Correct |
500 ms |
126236 KB |
Output is correct |
38 |
Correct |
560 ms |
126292 KB |
Output is correct |
39 |
Runtime error |
150 ms |
262144 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |