#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define taskname ""
#define int ll
using namespace std;
ll sz[200009],ma[200009],pre[200009],i,m,n,u,v,ans[200009],check[200009],maxdepth;
vector<int>g[200009];
void dfs(int id,int par){
sz[id]=1;
for(int x:g[id]){
if(x==par||check[x]) continue;
dfs(x,id);
sz[id]+=sz[x];
}
}
int centroid(int id,int par,int siz){
for(int u:g[id]){
if(u==par||check[u]) continue;
if(sz[u]*2>=siz) return centroid(u,id,siz);
}return id;
}
void dfs2(int id,int par,int h,int siz){
ma[sz[id]]=max(ma[sz[id]],h);
for(int u:g[id]){
if(u==par||check[u]) continue;
dfs2(u,id,h+1,siz);
}
}
void solve(int id){
dfs(id,0);
int c=centroid(id,0,sz[id]);
check[c]=1;
dfs(c,0);
maxdepth=0;
for(int u:g[c]){
if(check[u]) continue;
dfs2(u,c,1,sz[c]-sz[u]);
maxdepth=max(maxdepth,sz[u]);
for(int i=sz[u]-1;i>=1;i--) ma[i]=max(ma[i],ma[i+1]);
for(int i=sz[u];i>=1;i--){
ans[i*2]=max(ans[i*2],ma[i]+max(pre[i],1ll));
pre[i]=max(pre[i],ma[i]+1);
}
for(int i=1;i<=sz[u];i++) ma[i]=0;
}
for(int i=1;i<=maxdepth;i++) pre[i]=0;
for(int u:g[c]){
if(check[u]) continue;
solve(u);
}
}
signed main() {
if (fopen(taskname".inp","r")) {
freopen(taskname".inp","r",stdin);
freopen(taskname".out","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(i=1;i<n;i++){
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
solve(1);
for(i=1;i<=n;i++){
if(!ans[i]) cout<<1<<"\n";
else cout<<ans[i]<<"\n";
}
return 0;
}
Compilation message
meetings2.cpp: In function 'int main()':
meetings2.cpp:60:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen(taskname".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
meetings2.cpp:61:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen(taskname".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
3 |
Correct |
2 ms |
10832 KB |
Output is correct |
4 |
Correct |
2 ms |
11004 KB |
Output is correct |
5 |
Correct |
2 ms |
10856 KB |
Output is correct |
6 |
Correct |
2 ms |
10832 KB |
Output is correct |
7 |
Correct |
2 ms |
11000 KB |
Output is correct |
8 |
Correct |
2 ms |
10832 KB |
Output is correct |
9 |
Correct |
2 ms |
10832 KB |
Output is correct |
10 |
Correct |
2 ms |
10832 KB |
Output is correct |
11 |
Correct |
2 ms |
10832 KB |
Output is correct |
12 |
Correct |
2 ms |
10832 KB |
Output is correct |
13 |
Correct |
2 ms |
10832 KB |
Output is correct |
14 |
Correct |
2 ms |
10832 KB |
Output is correct |
15 |
Correct |
2 ms |
10832 KB |
Output is correct |
16 |
Correct |
2 ms |
10832 KB |
Output is correct |
17 |
Correct |
2 ms |
10832 KB |
Output is correct |
18 |
Correct |
2 ms |
10832 KB |
Output is correct |
19 |
Correct |
2 ms |
10832 KB |
Output is correct |
20 |
Correct |
2 ms |
10832 KB |
Output is correct |
21 |
Correct |
2 ms |
10832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
3 |
Correct |
2 ms |
10832 KB |
Output is correct |
4 |
Correct |
2 ms |
11004 KB |
Output is correct |
5 |
Correct |
2 ms |
10856 KB |
Output is correct |
6 |
Correct |
2 ms |
10832 KB |
Output is correct |
7 |
Correct |
2 ms |
11000 KB |
Output is correct |
8 |
Correct |
2 ms |
10832 KB |
Output is correct |
9 |
Correct |
2 ms |
10832 KB |
Output is correct |
10 |
Correct |
2 ms |
10832 KB |
Output is correct |
11 |
Correct |
2 ms |
10832 KB |
Output is correct |
12 |
Correct |
2 ms |
10832 KB |
Output is correct |
13 |
Correct |
2 ms |
10832 KB |
Output is correct |
14 |
Correct |
2 ms |
10832 KB |
Output is correct |
15 |
Correct |
2 ms |
10832 KB |
Output is correct |
16 |
Correct |
2 ms |
10832 KB |
Output is correct |
17 |
Correct |
2 ms |
10832 KB |
Output is correct |
18 |
Correct |
2 ms |
10832 KB |
Output is correct |
19 |
Correct |
2 ms |
10832 KB |
Output is correct |
20 |
Correct |
2 ms |
10832 KB |
Output is correct |
21 |
Correct |
2 ms |
10832 KB |
Output is correct |
22 |
Correct |
3 ms |
11088 KB |
Output is correct |
23 |
Correct |
3 ms |
10832 KB |
Output is correct |
24 |
Correct |
4 ms |
10832 KB |
Output is correct |
25 |
Correct |
4 ms |
10832 KB |
Output is correct |
26 |
Correct |
4 ms |
10832 KB |
Output is correct |
27 |
Correct |
4 ms |
10832 KB |
Output is correct |
28 |
Correct |
4 ms |
11088 KB |
Output is correct |
29 |
Correct |
4 ms |
10832 KB |
Output is correct |
30 |
Correct |
4 ms |
11088 KB |
Output is correct |
31 |
Correct |
4 ms |
11088 KB |
Output is correct |
32 |
Correct |
5 ms |
11088 KB |
Output is correct |
33 |
Correct |
5 ms |
11088 KB |
Output is correct |
34 |
Correct |
4 ms |
10832 KB |
Output is correct |
35 |
Correct |
4 ms |
10832 KB |
Output is correct |
36 |
Correct |
4 ms |
10856 KB |
Output is correct |
37 |
Correct |
3 ms |
11088 KB |
Output is correct |
38 |
Correct |
3 ms |
11108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
3 |
Correct |
2 ms |
10832 KB |
Output is correct |
4 |
Correct |
2 ms |
11004 KB |
Output is correct |
5 |
Correct |
2 ms |
10856 KB |
Output is correct |
6 |
Correct |
2 ms |
10832 KB |
Output is correct |
7 |
Correct |
2 ms |
11000 KB |
Output is correct |
8 |
Correct |
2 ms |
10832 KB |
Output is correct |
9 |
Correct |
2 ms |
10832 KB |
Output is correct |
10 |
Correct |
2 ms |
10832 KB |
Output is correct |
11 |
Correct |
2 ms |
10832 KB |
Output is correct |
12 |
Correct |
2 ms |
10832 KB |
Output is correct |
13 |
Correct |
2 ms |
10832 KB |
Output is correct |
14 |
Correct |
2 ms |
10832 KB |
Output is correct |
15 |
Correct |
2 ms |
10832 KB |
Output is correct |
16 |
Correct |
2 ms |
10832 KB |
Output is correct |
17 |
Correct |
2 ms |
10832 KB |
Output is correct |
18 |
Correct |
2 ms |
10832 KB |
Output is correct |
19 |
Correct |
2 ms |
10832 KB |
Output is correct |
20 |
Correct |
2 ms |
10832 KB |
Output is correct |
21 |
Correct |
2 ms |
10832 KB |
Output is correct |
22 |
Correct |
3 ms |
11088 KB |
Output is correct |
23 |
Correct |
3 ms |
10832 KB |
Output is correct |
24 |
Correct |
4 ms |
10832 KB |
Output is correct |
25 |
Correct |
4 ms |
10832 KB |
Output is correct |
26 |
Correct |
4 ms |
10832 KB |
Output is correct |
27 |
Correct |
4 ms |
10832 KB |
Output is correct |
28 |
Correct |
4 ms |
11088 KB |
Output is correct |
29 |
Correct |
4 ms |
10832 KB |
Output is correct |
30 |
Correct |
4 ms |
11088 KB |
Output is correct |
31 |
Correct |
4 ms |
11088 KB |
Output is correct |
32 |
Correct |
5 ms |
11088 KB |
Output is correct |
33 |
Correct |
5 ms |
11088 KB |
Output is correct |
34 |
Correct |
4 ms |
10832 KB |
Output is correct |
35 |
Correct |
4 ms |
10832 KB |
Output is correct |
36 |
Correct |
4 ms |
10856 KB |
Output is correct |
37 |
Correct |
3 ms |
11088 KB |
Output is correct |
38 |
Correct |
3 ms |
11108 KB |
Output is correct |
39 |
Correct |
203 ms |
19504 KB |
Output is correct |
40 |
Correct |
172 ms |
19184 KB |
Output is correct |
41 |
Correct |
160 ms |
19272 KB |
Output is correct |
42 |
Correct |
164 ms |
19528 KB |
Output is correct |
43 |
Correct |
161 ms |
19476 KB |
Output is correct |
44 |
Correct |
153 ms |
19456 KB |
Output is correct |
45 |
Correct |
296 ms |
23584 KB |
Output is correct |
46 |
Correct |
227 ms |
25928 KB |
Output is correct |
47 |
Correct |
72 ms |
18620 KB |
Output is correct |
48 |
Correct |
55 ms |
19640 KB |
Output is correct |
49 |
Correct |
187 ms |
20020 KB |
Output is correct |
50 |
Correct |
78 ms |
20156 KB |
Output is correct |
51 |
Correct |
162 ms |
25532 KB |
Output is correct |