#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));
#define mod 1000000007
inline int add(int a,int b){
int r=a+b;
while(r>=mod)r-=mod;
while(r<0)r+=mod;
return r;
}
inline int mult(int a,int b){
return (int)(((ll)(a*b))%mod);
}
inline int rd(){
int x=0;
char ch=getchar_unlocked();
while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
x=(x<<3)+(x<<1)+(ch&15);
ch=getchar_unlocked();
}
return x;
}
#define maxn 200005
int n,par[maxn][20],d[maxn],sub[maxn],ans[maxn];
vector<int> AL[maxn],stuff[maxn];
void dfs(int u){
sub[u]=1;
for(int v:AL[u]){
if(par[u][0]==v)continue;
par[v][0]=u;
d[v]=d[u]+1;
dfs(v);
sub[u]+=sub[v];
}
}
int lca(int a,int b){
if(d[a]<d[b])swap(a,b);
for(int k=19;k>=0;--k){
if(par[a][k]!=0&&d[par[a][k]]>=d[b])a=par[a][k];
}
if(a==b)return a;
for(int k=19;k>=0;--k){
if(par[a][k]!=par[b][k])a=par[a][k],b=par[b][k];
}
return par[a][0];
}
int dist(int a,int b){
return d[a]+d[b]-2*d[lca(a,b)];
}
int main(){
sf("%d",&n);
for(int i=0;i<n-1;++i){
int a,b;sf("%d%d",&a,&b);
AL[a].pb(b);AL[b].pb(a);
}
dfs(1);
int rt=0;
for(int u=1;u<=n;++u){
bool can=true;
if(n-sub[u]>n/2)can=false;
for(int v:AL[u]){
if(v==par[u][0])continue;
if(sub[v]>n/2)can=false;
}
if(can)rt=u;
}
d[rt]=0;par[rt][0]=0;
dfs(rt);
for(int k=1;k<20;++k){
for(int i=1;i<=n;++i){
if(par[i][k-1]==0)par[i][k]=0;;
par[i][k]=par[par[i][k-1]][k-1];
}
}
for(int i=1;i<=n;++i)stuff[sub[i]].pb(i);
int a=rt,b=rt,mx=0;
for(int i=n/2;i>=1;--i){
for(int x:stuff[i]){
int d1=dist(a,x),d2=dist(b,x);
if(d1>=d2&&d1>mx)b=x,mx=d1;
else if(d2>=d1&&d2>mx)a=x,mx=d2;
}
ans[i]=mx+1;
}
for(int i=1;i<=n;++i){
if(i%2)pf("1\n");
else pf("%d\n",ans[i/2]);
}
}
Compilation message
meetings2.cpp: In function 'int main()':
meetings2.cpp:90:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | sf("%d",&n);
| ^
meetings2.cpp:92:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | int a,b;sf("%d%d",&a,&b);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9692 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9660 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9700 KB |
Output is correct |
8 |
Correct |
7 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9728 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
5 ms |
9684 KB |
Output is correct |
14 |
Correct |
5 ms |
9604 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
6 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9604 KB |
Output is correct |
18 |
Correct |
6 ms |
9644 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
4 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9692 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9660 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9700 KB |
Output is correct |
8 |
Correct |
7 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9728 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
5 ms |
9684 KB |
Output is correct |
14 |
Correct |
5 ms |
9604 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
6 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9604 KB |
Output is correct |
18 |
Correct |
6 ms |
9644 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
4 ms |
9684 KB |
Output is correct |
22 |
Correct |
9 ms |
10220 KB |
Output is correct |
23 |
Correct |
10 ms |
10196 KB |
Output is correct |
24 |
Correct |
9 ms |
10224 KB |
Output is correct |
25 |
Correct |
8 ms |
10196 KB |
Output is correct |
26 |
Correct |
9 ms |
10196 KB |
Output is correct |
27 |
Correct |
9 ms |
10196 KB |
Output is correct |
28 |
Correct |
7 ms |
10196 KB |
Output is correct |
29 |
Correct |
9 ms |
10196 KB |
Output is correct |
30 |
Correct |
8 ms |
10196 KB |
Output is correct |
31 |
Correct |
7 ms |
10140 KB |
Output is correct |
32 |
Correct |
8 ms |
10380 KB |
Output is correct |
33 |
Correct |
8 ms |
10452 KB |
Output is correct |
34 |
Correct |
10 ms |
10196 KB |
Output is correct |
35 |
Correct |
7 ms |
10240 KB |
Output is correct |
36 |
Correct |
8 ms |
10148 KB |
Output is correct |
37 |
Correct |
7 ms |
10168 KB |
Output is correct |
38 |
Correct |
7 ms |
10324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9692 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9660 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9700 KB |
Output is correct |
8 |
Correct |
7 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9728 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
5 ms |
9684 KB |
Output is correct |
14 |
Correct |
5 ms |
9604 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
6 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9604 KB |
Output is correct |
18 |
Correct |
6 ms |
9644 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
4 ms |
9684 KB |
Output is correct |
22 |
Correct |
9 ms |
10220 KB |
Output is correct |
23 |
Correct |
10 ms |
10196 KB |
Output is correct |
24 |
Correct |
9 ms |
10224 KB |
Output is correct |
25 |
Correct |
8 ms |
10196 KB |
Output is correct |
26 |
Correct |
9 ms |
10196 KB |
Output is correct |
27 |
Correct |
9 ms |
10196 KB |
Output is correct |
28 |
Correct |
7 ms |
10196 KB |
Output is correct |
29 |
Correct |
9 ms |
10196 KB |
Output is correct |
30 |
Correct |
8 ms |
10196 KB |
Output is correct |
31 |
Correct |
7 ms |
10140 KB |
Output is correct |
32 |
Correct |
8 ms |
10380 KB |
Output is correct |
33 |
Correct |
8 ms |
10452 KB |
Output is correct |
34 |
Correct |
10 ms |
10196 KB |
Output is correct |
35 |
Correct |
7 ms |
10240 KB |
Output is correct |
36 |
Correct |
8 ms |
10148 KB |
Output is correct |
37 |
Correct |
7 ms |
10168 KB |
Output is correct |
38 |
Correct |
7 ms |
10324 KB |
Output is correct |
39 |
Correct |
276 ms |
37160 KB |
Output is correct |
40 |
Correct |
255 ms |
36408 KB |
Output is correct |
41 |
Correct |
275 ms |
37360 KB |
Output is correct |
42 |
Correct |
238 ms |
37700 KB |
Output is correct |
43 |
Correct |
285 ms |
37716 KB |
Output is correct |
44 |
Correct |
274 ms |
37760 KB |
Output is correct |
45 |
Correct |
423 ms |
44352 KB |
Output is correct |
46 |
Correct |
350 ms |
48716 KB |
Output is correct |
47 |
Correct |
202 ms |
38176 KB |
Output is correct |
48 |
Correct |
202 ms |
38088 KB |
Output is correct |
49 |
Correct |
295 ms |
38452 KB |
Output is correct |
50 |
Correct |
184 ms |
38180 KB |
Output is correct |
51 |
Correct |
250 ms |
46608 KB |
Output is correct |