/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 2e5 + 10;
int n;
vector < int > adj[maxn];
int order[maxn], tin[maxn], tout[maxn];
int timer, depth[maxn], sub[maxn];
void euler(int v, int p)
{
order[++ timer] = v;
tin[v] = timer;
sub[v] = 1;
for (int u : adj[v])
{
if (u == p)
continue;
depth[u] = depth[v] + 1;
euler(u, v);
sub[v] += sub[u];
}
tout[v] = timer;
}
vector < int > path;
int max_chain[maxn], virtual_depth[maxn], virtual_sub[maxn];
int act[maxn];
void dfs(int v, int p)
{
for (int cur : path)
{
int id = 2 * min(virtual_sub[cur], sub[v]);
max_chain[id] = max(max_chain[id], depth[v] - depth[cur]);
///cout << "here " << v << " " << cur << " " << virtual_sub[cur] << " " << sub[v] << endl;
}
path.push_back(v);
virtual_depth[v] = -depth[v];
int max_len = -1;
for (int i = 1; i <= n; i ++)
{
if (act[i] && sub[i] >= sub[v])
{
max_len = max(max_len, depth[v] + virtual_depth[i]);
///int id = 2 * min(sub[v], sub[order[i]]);
//cout << v << " : " << order[i] << " " << depth[v] + virtual_depth[order[i]] << " " << id << endl;
///max_chain[id] = max(max_chain[id], depth[v] + virtual_depth[order[i]]);
}
}
max_chain[2 * sub[v]] = max(max_chain[2 * sub[v]], max_len);
for (int u : adj[v])
{
if (u == p)
continue;
virtual_sub[v] = n - sub[u];
dfs(u, v);
}
for (int i = tin[v]; i <= tout[v]; i ++)
virtual_depth[order[i]] += 2;
path.pop_back();
act[v] = 1;
}
void solve()
{
cin >> n;
for (int i = 1; i < n; i ++)
{
int v, u;
cin >> v >> u;
adj[v].push_back(u);
adj[u].push_back(v);
}
euler(1, 0);
for (int i = 1; i <= n; i ++)
{
max_chain[i] = -1;
}
dfs(1, 0);
for (int i = 1; i <= n; i ++)
{
act[i] = 0;
reverse(adj[i].begin(), adj[i].end());
}
euler(1, 0);
dfs(1, 0);
for (int i = n; i > 0; i --)
{
max_chain[i] = max(max_chain[i], max_chain[i + 1]);
}
for (int i = 1; i <= n; i ++)
{
if (i % 2 == 1)
cout << 1 << endl;
else
cout << max_chain[i] + 1 << endl;
}
}
int main()
{
speed();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9816 KB |
Output is correct |
2 |
Correct |
2 ms |
9816 KB |
Output is correct |
3 |
Correct |
2 ms |
9820 KB |
Output is correct |
4 |
Correct |
2 ms |
9820 KB |
Output is correct |
5 |
Correct |
2 ms |
9816 KB |
Output is correct |
6 |
Correct |
2 ms |
9816 KB |
Output is correct |
7 |
Correct |
2 ms |
9816 KB |
Output is correct |
8 |
Correct |
3 ms |
9820 KB |
Output is correct |
9 |
Correct |
2 ms |
9816 KB |
Output is correct |
10 |
Correct |
2 ms |
9816 KB |
Output is correct |
11 |
Correct |
2 ms |
10272 KB |
Output is correct |
12 |
Correct |
2 ms |
9820 KB |
Output is correct |
13 |
Correct |
2 ms |
9816 KB |
Output is correct |
14 |
Correct |
2 ms |
9816 KB |
Output is correct |
15 |
Correct |
2 ms |
9820 KB |
Output is correct |
16 |
Correct |
2 ms |
9816 KB |
Output is correct |
17 |
Correct |
2 ms |
9816 KB |
Output is correct |
18 |
Correct |
2 ms |
9816 KB |
Output is correct |
19 |
Correct |
2 ms |
9816 KB |
Output is correct |
20 |
Correct |
2 ms |
9820 KB |
Output is correct |
21 |
Correct |
2 ms |
9816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9816 KB |
Output is correct |
2 |
Correct |
2 ms |
9816 KB |
Output is correct |
3 |
Correct |
2 ms |
9820 KB |
Output is correct |
4 |
Correct |
2 ms |
9820 KB |
Output is correct |
5 |
Correct |
2 ms |
9816 KB |
Output is correct |
6 |
Correct |
2 ms |
9816 KB |
Output is correct |
7 |
Correct |
2 ms |
9816 KB |
Output is correct |
8 |
Correct |
3 ms |
9820 KB |
Output is correct |
9 |
Correct |
2 ms |
9816 KB |
Output is correct |
10 |
Correct |
2 ms |
9816 KB |
Output is correct |
11 |
Correct |
2 ms |
10272 KB |
Output is correct |
12 |
Correct |
2 ms |
9820 KB |
Output is correct |
13 |
Correct |
2 ms |
9816 KB |
Output is correct |
14 |
Correct |
2 ms |
9816 KB |
Output is correct |
15 |
Correct |
2 ms |
9820 KB |
Output is correct |
16 |
Correct |
2 ms |
9816 KB |
Output is correct |
17 |
Correct |
2 ms |
9816 KB |
Output is correct |
18 |
Correct |
2 ms |
9816 KB |
Output is correct |
19 |
Correct |
2 ms |
9816 KB |
Output is correct |
20 |
Correct |
2 ms |
9820 KB |
Output is correct |
21 |
Correct |
2 ms |
9816 KB |
Output is correct |
22 |
Correct |
89 ms |
10172 KB |
Output is correct |
23 |
Correct |
90 ms |
10072 KB |
Output is correct |
24 |
Correct |
92 ms |
10172 KB |
Output is correct |
25 |
Correct |
92 ms |
10320 KB |
Output is correct |
26 |
Correct |
87 ms |
10072 KB |
Output is correct |
27 |
Correct |
90 ms |
10156 KB |
Output is correct |
28 |
Correct |
92 ms |
10328 KB |
Output is correct |
29 |
Correct |
90 ms |
10072 KB |
Output is correct |
30 |
Correct |
90 ms |
10072 KB |
Output is correct |
31 |
Correct |
93 ms |
10172 KB |
Output is correct |
32 |
Correct |
80 ms |
10072 KB |
Output is correct |
33 |
Correct |
78 ms |
10368 KB |
Output is correct |
34 |
Correct |
72 ms |
10072 KB |
Output is correct |
35 |
Correct |
52 ms |
10188 KB |
Output is correct |
36 |
Correct |
70 ms |
10176 KB |
Output is correct |
37 |
Correct |
52 ms |
10184 KB |
Output is correct |
38 |
Correct |
64 ms |
10072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9816 KB |
Output is correct |
2 |
Correct |
2 ms |
9816 KB |
Output is correct |
3 |
Correct |
2 ms |
9820 KB |
Output is correct |
4 |
Correct |
2 ms |
9820 KB |
Output is correct |
5 |
Correct |
2 ms |
9816 KB |
Output is correct |
6 |
Correct |
2 ms |
9816 KB |
Output is correct |
7 |
Correct |
2 ms |
9816 KB |
Output is correct |
8 |
Correct |
3 ms |
9820 KB |
Output is correct |
9 |
Correct |
2 ms |
9816 KB |
Output is correct |
10 |
Correct |
2 ms |
9816 KB |
Output is correct |
11 |
Correct |
2 ms |
10272 KB |
Output is correct |
12 |
Correct |
2 ms |
9820 KB |
Output is correct |
13 |
Correct |
2 ms |
9816 KB |
Output is correct |
14 |
Correct |
2 ms |
9816 KB |
Output is correct |
15 |
Correct |
2 ms |
9820 KB |
Output is correct |
16 |
Correct |
2 ms |
9816 KB |
Output is correct |
17 |
Correct |
2 ms |
9816 KB |
Output is correct |
18 |
Correct |
2 ms |
9816 KB |
Output is correct |
19 |
Correct |
2 ms |
9816 KB |
Output is correct |
20 |
Correct |
2 ms |
9820 KB |
Output is correct |
21 |
Correct |
2 ms |
9816 KB |
Output is correct |
22 |
Correct |
89 ms |
10172 KB |
Output is correct |
23 |
Correct |
90 ms |
10072 KB |
Output is correct |
24 |
Correct |
92 ms |
10172 KB |
Output is correct |
25 |
Correct |
92 ms |
10320 KB |
Output is correct |
26 |
Correct |
87 ms |
10072 KB |
Output is correct |
27 |
Correct |
90 ms |
10156 KB |
Output is correct |
28 |
Correct |
92 ms |
10328 KB |
Output is correct |
29 |
Correct |
90 ms |
10072 KB |
Output is correct |
30 |
Correct |
90 ms |
10072 KB |
Output is correct |
31 |
Correct |
93 ms |
10172 KB |
Output is correct |
32 |
Correct |
80 ms |
10072 KB |
Output is correct |
33 |
Correct |
78 ms |
10368 KB |
Output is correct |
34 |
Correct |
72 ms |
10072 KB |
Output is correct |
35 |
Correct |
52 ms |
10188 KB |
Output is correct |
36 |
Correct |
70 ms |
10176 KB |
Output is correct |
37 |
Correct |
52 ms |
10184 KB |
Output is correct |
38 |
Correct |
64 ms |
10072 KB |
Output is correct |
39 |
Execution timed out |
4019 ms |
18256 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |