#include "bits/stdc++.h"
using namespace std;
const int N=2e5+1;
int n;
vector<int> adj[N];
bool vis[N];
int sz[N];
int ans[N];
int dist[N];
int root[N];
void dfs(int x){
vis[x]=1;
sz[x]=1;
for(int k:adj[x]){
if(!vis[k]){
dist[k]=dist[x]+1;
root[k]=(root[x]?root[x]:k);
dfs(k);
sz[x]+=sz[k];
}
}
}
void ckmx(int &a, int b){ a=max(a,b); }
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1; i<n; i++){
int u,v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++) vis[j]=0;
dist[i]=root[i]=0;
dfs(i);
for(int j=1; j<=n; j++){
if(j==i) continue;
ckmx(ans[2*min(sz[j], n-sz[root[j]])], dist[j]);
}
}
for(int i=n; i>=1; i--) ans[i]=max(ans[i], ans[i+2]);
for(int i=1; i<=n; i++){
if(i&1) cout << "1\n";
else cout << ans[i]+1 << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5016 KB |
Output is correct |
13 |
Correct |
3 ms |
5020 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
3 ms |
5024 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5028 KB |
Output is correct |
20 |
Correct |
3 ms |
5024 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5016 KB |
Output is correct |
13 |
Correct |
3 ms |
5020 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
3 ms |
5024 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5028 KB |
Output is correct |
20 |
Correct |
3 ms |
5024 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
365 ms |
5252 KB |
Output is correct |
23 |
Correct |
386 ms |
5256 KB |
Output is correct |
24 |
Correct |
351 ms |
5260 KB |
Output is correct |
25 |
Correct |
361 ms |
5244 KB |
Output is correct |
26 |
Correct |
362 ms |
5324 KB |
Output is correct |
27 |
Correct |
367 ms |
5256 KB |
Output is correct |
28 |
Correct |
375 ms |
5264 KB |
Output is correct |
29 |
Correct |
378 ms |
5252 KB |
Output is correct |
30 |
Correct |
386 ms |
5248 KB |
Output is correct |
31 |
Correct |
378 ms |
5324 KB |
Output is correct |
32 |
Correct |
367 ms |
5392 KB |
Output is correct |
33 |
Correct |
331 ms |
5500 KB |
Output is correct |
34 |
Correct |
336 ms |
5204 KB |
Output is correct |
35 |
Correct |
237 ms |
5264 KB |
Output is correct |
36 |
Correct |
291 ms |
5288 KB |
Output is correct |
37 |
Correct |
234 ms |
5272 KB |
Output is correct |
38 |
Correct |
290 ms |
5452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5016 KB |
Output is correct |
13 |
Correct |
3 ms |
5020 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
3 ms |
5024 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5028 KB |
Output is correct |
20 |
Correct |
3 ms |
5024 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
365 ms |
5252 KB |
Output is correct |
23 |
Correct |
386 ms |
5256 KB |
Output is correct |
24 |
Correct |
351 ms |
5260 KB |
Output is correct |
25 |
Correct |
361 ms |
5244 KB |
Output is correct |
26 |
Correct |
362 ms |
5324 KB |
Output is correct |
27 |
Correct |
367 ms |
5256 KB |
Output is correct |
28 |
Correct |
375 ms |
5264 KB |
Output is correct |
29 |
Correct |
378 ms |
5252 KB |
Output is correct |
30 |
Correct |
386 ms |
5248 KB |
Output is correct |
31 |
Correct |
378 ms |
5324 KB |
Output is correct |
32 |
Correct |
367 ms |
5392 KB |
Output is correct |
33 |
Correct |
331 ms |
5500 KB |
Output is correct |
34 |
Correct |
336 ms |
5204 KB |
Output is correct |
35 |
Correct |
237 ms |
5264 KB |
Output is correct |
36 |
Correct |
291 ms |
5288 KB |
Output is correct |
37 |
Correct |
234 ms |
5272 KB |
Output is correct |
38 |
Correct |
290 ms |
5452 KB |
Output is correct |
39 |
Execution timed out |
4049 ms |
16344 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |