#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> g[n + 1];
for (int i = 1; i < n; i++){
int x, y; cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
vector<vector<int>> dist(n + 1, vector<int>(n + 1));
function<void(int, int, int, int&)> fill = [&](int v, int pr, int d, int& u){
dist[u][v] = d++;
for (int i: g[v]){
if (i == pr) continue;
fill(i, v, d, u);
}
};
for (int i = 1; i <= n; i++) fill(i, 0, 0, i);
vector<vector<int>> sz(n + 1, vector<int>(n + 1));
function<void(int, int, int&)> fill_sz = [&](int v, int pr, int& u){
sz[u][v] = 1;
for (int i: g[v]){
if (i == pr) continue;
fill_sz(i, v, u);
sz[u][v] += sz[u][i];
}
};
for (int i = 1; i <= n; i++) fill_sz(i, 0, i);
vector<int> p(n + 1);
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
int s = min(sz[i][j], sz[j][i]);
p[s] = max(p[s], dist[i][j] + 1);
}
}
for (int i = n - 1; i > 0; i--) p[i] = max(p[i], p[i + 1]);
for (int x = 1; x <= n; x++){
if (x % 2){
cout<<1<<"\n";
continue;
}
cout<<p[x / 2]<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |