#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define pb push_back
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
#define fi first
#define se second
// mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
// int rand(int l,int r){return l+((hdp()%(r-l+1))+r-l+1)%(r-l+1);}
const int N = 2e5+5;
const int mod = 998244353;
const int SQ = 450;
vector<int> g[N];
int n,k,ans[N],a1[N],a2[N],sz[N],mx;
bool b[N];
int dfs(int u,int p=0)
{
sz[u]=1;
for(auto v:g[u]) if(v!=p&&!b[v]) sz[u]+=dfs(v,u);
return sz[u];
}
int find(int u,int s,int p=0)
{
for(auto v:g[u]) if(!b[v]&&v!=p&&sz[v]*2>s) return find(v,s,u);
return u;
}
void add(int u,int p,int l=2)
{
setmax(a2[sz[u]],l);
for(auto v:g[u]) if(!b[v]&&v!=p) add(v,u,l+1);
}
void solve(int u)
{
u=find(u,dfs(u));
dfs(u);
for(int i=1;i<=sz[u];i++) a1[i]=1;
for(auto v:g[u]) if(!b[v])
{
add(v,u);
int cur=0;
for(int i=sz[v];i>=1;i--)
{
setmax(cur,a2[i]);
setmax(ans[2*i],cur+a1[i]-1);
}
cur=0;
for(int i=sz[v];i>=1;i--)
{
setmax(cur,a2[i]);
a2[i]=0;
setmax(a1[i],cur);
}
}
b[u]=1;
for(auto v:g[u]) if(!b[v]) solve(v);
}
signed main()
{
fastIO
cin>>n;
for(int i=1;i<=n;i++) ans[i]=1;
for(int i=1;i<n;i++)
{
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
solve(1);
for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
2 ms |
8284 KB |
Output is correct |
5 |
Correct |
2 ms |
8284 KB |
Output is correct |
6 |
Correct |
2 ms |
8284 KB |
Output is correct |
7 |
Correct |
3 ms |
8284 KB |
Output is correct |
8 |
Correct |
2 ms |
8284 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
10 |
Correct |
2 ms |
8284 KB |
Output is correct |
11 |
Correct |
2 ms |
8284 KB |
Output is correct |
12 |
Correct |
2 ms |
8284 KB |
Output is correct |
13 |
Correct |
2 ms |
8284 KB |
Output is correct |
14 |
Correct |
2 ms |
8284 KB |
Output is correct |
15 |
Correct |
3 ms |
8284 KB |
Output is correct |
16 |
Correct |
2 ms |
8136 KB |
Output is correct |
17 |
Correct |
2 ms |
8284 KB |
Output is correct |
18 |
Correct |
2 ms |
8284 KB |
Output is correct |
19 |
Correct |
2 ms |
8284 KB |
Output is correct |
20 |
Correct |
2 ms |
8116 KB |
Output is correct |
21 |
Correct |
2 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
2 ms |
8284 KB |
Output is correct |
5 |
Correct |
2 ms |
8284 KB |
Output is correct |
6 |
Correct |
2 ms |
8284 KB |
Output is correct |
7 |
Correct |
3 ms |
8284 KB |
Output is correct |
8 |
Correct |
2 ms |
8284 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
10 |
Correct |
2 ms |
8284 KB |
Output is correct |
11 |
Correct |
2 ms |
8284 KB |
Output is correct |
12 |
Correct |
2 ms |
8284 KB |
Output is correct |
13 |
Correct |
2 ms |
8284 KB |
Output is correct |
14 |
Correct |
2 ms |
8284 KB |
Output is correct |
15 |
Correct |
3 ms |
8284 KB |
Output is correct |
16 |
Correct |
2 ms |
8136 KB |
Output is correct |
17 |
Correct |
2 ms |
8284 KB |
Output is correct |
18 |
Correct |
2 ms |
8284 KB |
Output is correct |
19 |
Correct |
2 ms |
8284 KB |
Output is correct |
20 |
Correct |
2 ms |
8116 KB |
Output is correct |
21 |
Correct |
2 ms |
8284 KB |
Output is correct |
22 |
Correct |
4 ms |
8284 KB |
Output is correct |
23 |
Correct |
5 ms |
8284 KB |
Output is correct |
24 |
Correct |
5 ms |
8284 KB |
Output is correct |
25 |
Correct |
4 ms |
8284 KB |
Output is correct |
26 |
Correct |
4 ms |
8284 KB |
Output is correct |
27 |
Correct |
5 ms |
8280 KB |
Output is correct |
28 |
Correct |
4 ms |
8284 KB |
Output is correct |
29 |
Correct |
4 ms |
8284 KB |
Output is correct |
30 |
Correct |
4 ms |
8284 KB |
Output is correct |
31 |
Correct |
4 ms |
8428 KB |
Output is correct |
32 |
Correct |
5 ms |
8284 KB |
Output is correct |
33 |
Correct |
4 ms |
8540 KB |
Output is correct |
34 |
Correct |
3 ms |
8284 KB |
Output is correct |
35 |
Correct |
3 ms |
8280 KB |
Output is correct |
36 |
Correct |
4 ms |
8536 KB |
Output is correct |
37 |
Correct |
3 ms |
8284 KB |
Output is correct |
38 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
2 ms |
8284 KB |
Output is correct |
5 |
Correct |
2 ms |
8284 KB |
Output is correct |
6 |
Correct |
2 ms |
8284 KB |
Output is correct |
7 |
Correct |
3 ms |
8284 KB |
Output is correct |
8 |
Correct |
2 ms |
8284 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
10 |
Correct |
2 ms |
8284 KB |
Output is correct |
11 |
Correct |
2 ms |
8284 KB |
Output is correct |
12 |
Correct |
2 ms |
8284 KB |
Output is correct |
13 |
Correct |
2 ms |
8284 KB |
Output is correct |
14 |
Correct |
2 ms |
8284 KB |
Output is correct |
15 |
Correct |
3 ms |
8284 KB |
Output is correct |
16 |
Correct |
2 ms |
8136 KB |
Output is correct |
17 |
Correct |
2 ms |
8284 KB |
Output is correct |
18 |
Correct |
2 ms |
8284 KB |
Output is correct |
19 |
Correct |
2 ms |
8284 KB |
Output is correct |
20 |
Correct |
2 ms |
8116 KB |
Output is correct |
21 |
Correct |
2 ms |
8284 KB |
Output is correct |
22 |
Correct |
4 ms |
8284 KB |
Output is correct |
23 |
Correct |
5 ms |
8284 KB |
Output is correct |
24 |
Correct |
5 ms |
8284 KB |
Output is correct |
25 |
Correct |
4 ms |
8284 KB |
Output is correct |
26 |
Correct |
4 ms |
8284 KB |
Output is correct |
27 |
Correct |
5 ms |
8280 KB |
Output is correct |
28 |
Correct |
4 ms |
8284 KB |
Output is correct |
29 |
Correct |
4 ms |
8284 KB |
Output is correct |
30 |
Correct |
4 ms |
8284 KB |
Output is correct |
31 |
Correct |
4 ms |
8428 KB |
Output is correct |
32 |
Correct |
5 ms |
8284 KB |
Output is correct |
33 |
Correct |
4 ms |
8540 KB |
Output is correct |
34 |
Correct |
3 ms |
8284 KB |
Output is correct |
35 |
Correct |
3 ms |
8280 KB |
Output is correct |
36 |
Correct |
4 ms |
8536 KB |
Output is correct |
37 |
Correct |
3 ms |
8284 KB |
Output is correct |
38 |
Correct |
4 ms |
8284 KB |
Output is correct |
39 |
Correct |
198 ms |
15012 KB |
Output is correct |
40 |
Correct |
188 ms |
14916 KB |
Output is correct |
41 |
Correct |
189 ms |
15080 KB |
Output is correct |
42 |
Correct |
168 ms |
15192 KB |
Output is correct |
43 |
Correct |
182 ms |
15188 KB |
Output is correct |
44 |
Correct |
209 ms |
15428 KB |
Output is correct |
45 |
Correct |
306 ms |
17236 KB |
Output is correct |
46 |
Correct |
246 ms |
19024 KB |
Output is correct |
47 |
Correct |
80 ms |
15564 KB |
Output is correct |
48 |
Correct |
71 ms |
15864 KB |
Output is correct |
49 |
Correct |
159 ms |
15696 KB |
Output is correct |
50 |
Correct |
70 ms |
15900 KB |
Output is correct |
51 |
Correct |
166 ms |
18640 KB |
Output is correct |