#include<bits/stdc++.h>
#define MAXN 300007
using namespace std;
struct dude{
int h,l;
};
int n,a,b,sz[MAXN],root,parent[MAXN],pt[MAXN],ans[MAXN];
int dist[MAXN],maxs,dep[MAXN],from,to,diameter,curr;
vector<int> v[MAXN];
vector<int> rem[MAXN],s;
bool used[MAXN],in[MAXN];
unordered_set<int> active;
queue<int> q[MAXN];
void dfs(int x,int p,int d){
sz[x]=1; parent[x]=p; dep[x]=d;
for(int i=0;i<v[x].size();i++){
if(v[x][i]==p)continue;
dfs(v[x][i],x,d+1);
sz[x]+=sz[v[x][i]];
}
}
int dp[MAXN][20];
bool li[MAXN][20];
int ff(int x,int p){
if(p==0)return parent[x];
if(x==0)return 0;
if(li[x][p])return dp[x][p];
li[x][p]=true;
dp[x][p]=ff(ff(x,p-1),p-1);
return dp[x][p];
}
int getdist(int x,int y){
int res=0;
if(dep[x]<dep[y])swap(x,y);
for(int i=19;i>=0;i--){
if((1<<i)<=dep[x]-dep[y]){
x=ff(x,i);
res+=(1<<i);
}
}
for(int i=19;i>=0;i--){
if(ff(x,i)!=0 and ff(y,i)!=0 and ff(x,i)!=ff(y,i)){
res+=2*(1<<i);
x=ff(x,i); y=ff(y,i);
}
}
if(x!=y)res+=2;
return res;
}
int centroid(int x,int p){
for(int i=0;i<v[x].size();i++){
if(v[x][i]==p)continue;
if(sz[v[x][i]]>n/2){
return centroid(v[x][i],x);
}
}
return x;
}
void dfs1(int x,int p,int d){
diameter=max(diameter,d);
for(int i=0;i<v[x].size();i++){
if(v[x][i]==p or !in[v[x][i]])continue;
dfs1(v[x][i],x,d+1);
}
}
void add(int x){
in[x]=true;
if(from==0){
from=to=x;
diameter=0;
return;
}
for(int i=0;i<v[x].size();i++){
if(in[v[x][i]]){
curr=getdist(x,from);
if(curr>diameter){
diameter=curr;
to=x;
}
curr=getdist(x,to);
if(curr>diameter){
diameter=curr;
from=x;
}
}
}
}
int main(){
//ios_base::sync_with_stdio(0);
//cin.tie(0);
//cout.tie(0);
cin>>n;
for(int i=1;i<=n-1;i++){
cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
}
dfs(1,0,0);
root=centroid(1,0);
dfs(root,0,0);
for(int i=1;i<=n;i++){
pt[i]=i;
if(v[i].size()==1){
q[1].push(i);
}
}
for(int k=1;k<=n/2;k++){
while(!q[k-1].empty()){
curr=q[k-1].front();
if(used[curr]){
q[k-1].pop();
continue;
}
rem[k].push_back(curr);
used[curr]=true;
q[sz[parent[curr]]].push(parent[curr]);
q[k-1].pop();
}
reverse(rem[k].begin(),rem[k].end());
}
add(root);
for(int i=1;i<=n;i++){
if(!used[i] and i!=root){
add(i);
}
}
for(int k=n/2;k>=1;k--){
ans[2*k]=diameter+1;
for(int f:rem[k]){
add(f);
}
}
for(int i=1;i<=n;i++){
if(i%2==1)cout<<"1\n";
else cout<<ans[i]<<"\n";
}
return 0;
}
Compilation message
meetings2.cpp: In function 'void dfs(int, int, int)':
meetings2.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
meetings2.cpp: In function 'int centroid(int, int)':
meetings2.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
meetings2.cpp: In function 'void dfs1(int, int, int)':
meetings2.cpp:80:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
meetings2.cpp: In function 'void add(int)':
meetings2.cpp:95:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
221820 KB |
Output is correct |
2 |
Correct |
124 ms |
226104 KB |
Output is correct |
3 |
Correct |
124 ms |
225872 KB |
Output is correct |
4 |
Correct |
122 ms |
226128 KB |
Output is correct |
5 |
Correct |
127 ms |
226080 KB |
Output is correct |
6 |
Correct |
126 ms |
225876 KB |
Output is correct |
7 |
Correct |
123 ms |
225876 KB |
Output is correct |
8 |
Correct |
131 ms |
226128 KB |
Output is correct |
9 |
Correct |
130 ms |
225852 KB |
Output is correct |
10 |
Correct |
127 ms |
225872 KB |
Output is correct |
11 |
Correct |
126 ms |
225932 KB |
Output is correct |
12 |
Correct |
130 ms |
226404 KB |
Output is correct |
13 |
Correct |
123 ms |
225876 KB |
Output is correct |
14 |
Correct |
123 ms |
225972 KB |
Output is correct |
15 |
Correct |
125 ms |
225876 KB |
Output is correct |
16 |
Correct |
133 ms |
226140 KB |
Output is correct |
17 |
Correct |
123 ms |
225916 KB |
Output is correct |
18 |
Correct |
124 ms |
225876 KB |
Output is correct |
19 |
Correct |
123 ms |
225860 KB |
Output is correct |
20 |
Correct |
128 ms |
226100 KB |
Output is correct |
21 |
Correct |
125 ms |
226020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
221820 KB |
Output is correct |
2 |
Correct |
124 ms |
226104 KB |
Output is correct |
3 |
Correct |
124 ms |
225872 KB |
Output is correct |
4 |
Correct |
122 ms |
226128 KB |
Output is correct |
5 |
Correct |
127 ms |
226080 KB |
Output is correct |
6 |
Correct |
126 ms |
225876 KB |
Output is correct |
7 |
Correct |
123 ms |
225876 KB |
Output is correct |
8 |
Correct |
131 ms |
226128 KB |
Output is correct |
9 |
Correct |
130 ms |
225852 KB |
Output is correct |
10 |
Correct |
127 ms |
225872 KB |
Output is correct |
11 |
Correct |
126 ms |
225932 KB |
Output is correct |
12 |
Correct |
130 ms |
226404 KB |
Output is correct |
13 |
Correct |
123 ms |
225876 KB |
Output is correct |
14 |
Correct |
123 ms |
225972 KB |
Output is correct |
15 |
Correct |
125 ms |
225876 KB |
Output is correct |
16 |
Correct |
133 ms |
226140 KB |
Output is correct |
17 |
Correct |
123 ms |
225916 KB |
Output is correct |
18 |
Correct |
124 ms |
225876 KB |
Output is correct |
19 |
Correct |
123 ms |
225860 KB |
Output is correct |
20 |
Correct |
128 ms |
226100 KB |
Output is correct |
21 |
Correct |
125 ms |
226020 KB |
Output is correct |
22 |
Correct |
127 ms |
226320 KB |
Output is correct |
23 |
Correct |
137 ms |
226580 KB |
Output is correct |
24 |
Correct |
130 ms |
226340 KB |
Output is correct |
25 |
Correct |
126 ms |
226132 KB |
Output is correct |
26 |
Correct |
130 ms |
226192 KB |
Output is correct |
27 |
Correct |
135 ms |
226600 KB |
Output is correct |
28 |
Correct |
130 ms |
226132 KB |
Output is correct |
29 |
Correct |
126 ms |
226344 KB |
Output is correct |
30 |
Correct |
127 ms |
226304 KB |
Output is correct |
31 |
Correct |
134 ms |
226296 KB |
Output is correct |
32 |
Correct |
128 ms |
226480 KB |
Output is correct |
33 |
Correct |
128 ms |
226500 KB |
Output is correct |
34 |
Correct |
142 ms |
226384 KB |
Output is correct |
35 |
Correct |
145 ms |
226640 KB |
Output is correct |
36 |
Correct |
129 ms |
226384 KB |
Output is correct |
37 |
Correct |
149 ms |
226400 KB |
Output is correct |
38 |
Correct |
134 ms |
226644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
221820 KB |
Output is correct |
2 |
Correct |
124 ms |
226104 KB |
Output is correct |
3 |
Correct |
124 ms |
225872 KB |
Output is correct |
4 |
Correct |
122 ms |
226128 KB |
Output is correct |
5 |
Correct |
127 ms |
226080 KB |
Output is correct |
6 |
Correct |
126 ms |
225876 KB |
Output is correct |
7 |
Correct |
123 ms |
225876 KB |
Output is correct |
8 |
Correct |
131 ms |
226128 KB |
Output is correct |
9 |
Correct |
130 ms |
225852 KB |
Output is correct |
10 |
Correct |
127 ms |
225872 KB |
Output is correct |
11 |
Correct |
126 ms |
225932 KB |
Output is correct |
12 |
Correct |
130 ms |
226404 KB |
Output is correct |
13 |
Correct |
123 ms |
225876 KB |
Output is correct |
14 |
Correct |
123 ms |
225972 KB |
Output is correct |
15 |
Correct |
125 ms |
225876 KB |
Output is correct |
16 |
Correct |
133 ms |
226140 KB |
Output is correct |
17 |
Correct |
123 ms |
225916 KB |
Output is correct |
18 |
Correct |
124 ms |
225876 KB |
Output is correct |
19 |
Correct |
123 ms |
225860 KB |
Output is correct |
20 |
Correct |
128 ms |
226100 KB |
Output is correct |
21 |
Correct |
125 ms |
226020 KB |
Output is correct |
22 |
Correct |
127 ms |
226320 KB |
Output is correct |
23 |
Correct |
137 ms |
226580 KB |
Output is correct |
24 |
Correct |
130 ms |
226340 KB |
Output is correct |
25 |
Correct |
126 ms |
226132 KB |
Output is correct |
26 |
Correct |
130 ms |
226192 KB |
Output is correct |
27 |
Correct |
135 ms |
226600 KB |
Output is correct |
28 |
Correct |
130 ms |
226132 KB |
Output is correct |
29 |
Correct |
126 ms |
226344 KB |
Output is correct |
30 |
Correct |
127 ms |
226304 KB |
Output is correct |
31 |
Correct |
134 ms |
226296 KB |
Output is correct |
32 |
Correct |
128 ms |
226480 KB |
Output is correct |
33 |
Correct |
128 ms |
226500 KB |
Output is correct |
34 |
Correct |
142 ms |
226384 KB |
Output is correct |
35 |
Correct |
145 ms |
226640 KB |
Output is correct |
36 |
Correct |
129 ms |
226384 KB |
Output is correct |
37 |
Correct |
149 ms |
226400 KB |
Output is correct |
38 |
Correct |
134 ms |
226644 KB |
Output is correct |
39 |
Correct |
449 ms |
254272 KB |
Output is correct |
40 |
Correct |
435 ms |
256468 KB |
Output is correct |
41 |
Correct |
433 ms |
256684 KB |
Output is correct |
42 |
Correct |
418 ms |
256788 KB |
Output is correct |
43 |
Correct |
449 ms |
256980 KB |
Output is correct |
44 |
Correct |
451 ms |
256976 KB |
Output is correct |
45 |
Correct |
713 ms |
262144 KB |
Output is correct |
46 |
Runtime error |
276 ms |
262144 KB |
Execution killed with signal 9 |
47 |
Halted |
0 ms |
0 KB |
- |