#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8284 KB |
Output is correct |
2 |
Correct |
4 ms |
8280 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
3 ms |
8284 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
2 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8284 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
10 |
Correct |
3 ms |
8284 KB |
Output is correct |
11 |
Correct |
2 ms |
8268 KB |
Output is correct |
12 |
Correct |
3 ms |
8284 KB |
Output is correct |
13 |
Correct |
2 ms |
8280 KB |
Output is correct |
14 |
Correct |
2 ms |
8284 KB |
Output is correct |
15 |
Correct |
2 ms |
8280 KB |
Output is correct |
16 |
Correct |
2 ms |
8284 KB |
Output is correct |
17 |
Correct |
2 ms |
8308 KB |
Output is correct |
18 |
Correct |
2 ms |
8284 KB |
Output is correct |
19 |
Correct |
3 ms |
8284 KB |
Output is correct |
20 |
Correct |
2 ms |
8228 KB |
Output is correct |
21 |
Correct |
3 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8284 KB |
Output is correct |
2 |
Correct |
4 ms |
8280 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
3 ms |
8284 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
2 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8284 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
10 |
Correct |
3 ms |
8284 KB |
Output is correct |
11 |
Correct |
2 ms |
8268 KB |
Output is correct |
12 |
Correct |
3 ms |
8284 KB |
Output is correct |
13 |
Correct |
2 ms |
8280 KB |
Output is correct |
14 |
Correct |
2 ms |
8284 KB |
Output is correct |
15 |
Correct |
2 ms |
8280 KB |
Output is correct |
16 |
Correct |
2 ms |
8284 KB |
Output is correct |
17 |
Correct |
2 ms |
8308 KB |
Output is correct |
18 |
Correct |
2 ms |
8284 KB |
Output is correct |
19 |
Correct |
3 ms |
8284 KB |
Output is correct |
20 |
Correct |
2 ms |
8228 KB |
Output is correct |
21 |
Correct |
3 ms |
8284 KB |
Output is correct |
22 |
Correct |
4 ms |
8408 KB |
Output is correct |
23 |
Correct |
4 ms |
8284 KB |
Output is correct |
24 |
Correct |
4 ms |
8284 KB |
Output is correct |
25 |
Correct |
4 ms |
8284 KB |
Output is correct |
26 |
Correct |
4 ms |
8408 KB |
Output is correct |
27 |
Correct |
4 ms |
8488 KB |
Output is correct |
28 |
Correct |
4 ms |
8412 KB |
Output is correct |
29 |
Correct |
4 ms |
8408 KB |
Output is correct |
30 |
Correct |
4 ms |
8284 KB |
Output is correct |
31 |
Correct |
5 ms |
8280 KB |
Output is correct |
32 |
Correct |
5 ms |
8540 KB |
Output is correct |
33 |
Correct |
5 ms |
8536 KB |
Output is correct |
34 |
Correct |
3 ms |
8536 KB |
Output is correct |
35 |
Correct |
3 ms |
8280 KB |
Output is correct |
36 |
Correct |
4 ms |
8284 KB |
Output is correct |
37 |
Correct |
3 ms |
8284 KB |
Output is correct |
38 |
Correct |
4 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8284 KB |
Output is correct |
2 |
Correct |
4 ms |
8280 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
3 ms |
8284 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
2 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8284 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
10 |
Correct |
3 ms |
8284 KB |
Output is correct |
11 |
Correct |
2 ms |
8268 KB |
Output is correct |
12 |
Correct |
3 ms |
8284 KB |
Output is correct |
13 |
Correct |
2 ms |
8280 KB |
Output is correct |
14 |
Correct |
2 ms |
8284 KB |
Output is correct |
15 |
Correct |
2 ms |
8280 KB |
Output is correct |
16 |
Correct |
2 ms |
8284 KB |
Output is correct |
17 |
Correct |
2 ms |
8308 KB |
Output is correct |
18 |
Correct |
2 ms |
8284 KB |
Output is correct |
19 |
Correct |
3 ms |
8284 KB |
Output is correct |
20 |
Correct |
2 ms |
8228 KB |
Output is correct |
21 |
Correct |
3 ms |
8284 KB |
Output is correct |
22 |
Correct |
4 ms |
8408 KB |
Output is correct |
23 |
Correct |
4 ms |
8284 KB |
Output is correct |
24 |
Correct |
4 ms |
8284 KB |
Output is correct |
25 |
Correct |
4 ms |
8284 KB |
Output is correct |
26 |
Correct |
4 ms |
8408 KB |
Output is correct |
27 |
Correct |
4 ms |
8488 KB |
Output is correct |
28 |
Correct |
4 ms |
8412 KB |
Output is correct |
29 |
Correct |
4 ms |
8408 KB |
Output is correct |
30 |
Correct |
4 ms |
8284 KB |
Output is correct |
31 |
Correct |
5 ms |
8280 KB |
Output is correct |
32 |
Correct |
5 ms |
8540 KB |
Output is correct |
33 |
Correct |
5 ms |
8536 KB |
Output is correct |
34 |
Correct |
3 ms |
8536 KB |
Output is correct |
35 |
Correct |
3 ms |
8280 KB |
Output is correct |
36 |
Correct |
4 ms |
8284 KB |
Output is correct |
37 |
Correct |
3 ms |
8284 KB |
Output is correct |
38 |
Correct |
4 ms |
8280 KB |
Output is correct |
39 |
Correct |
190 ms |
17636 KB |
Output is correct |
40 |
Correct |
177 ms |
17292 KB |
Output is correct |
41 |
Correct |
198 ms |
17692 KB |
Output is correct |
42 |
Correct |
177 ms |
17744 KB |
Output is correct |
43 |
Correct |
196 ms |
17720 KB |
Output is correct |
44 |
Correct |
171 ms |
17824 KB |
Output is correct |
45 |
Correct |
332 ms |
19712 KB |
Output is correct |
46 |
Correct |
252 ms |
21584 KB |
Output is correct |
47 |
Correct |
72 ms |
18116 KB |
Output is correct |
48 |
Correct |
56 ms |
18120 KB |
Output is correct |
49 |
Correct |
157 ms |
18384 KB |
Output is correct |
50 |
Correct |
99 ms |
18376 KB |
Output is correct |
51 |
Correct |
143 ms |
21176 KB |
Output is correct |