QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574432 | #3100. Meetings 2 | JWRuixi | 0 | 0ms | 0kb | C++20 | 2.1kb | 2024-09-18 22:06:10 | 2024-09-18 22:06:12 |
answer
#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
using vi = vector<int>;
#endif
constexpr int N = 2e5 + 9;
int n, deg[N], sz[N], ns[N];
vi g[N], e[N / 2];
bool vis[N];
int dfn[N], dfc, st[18][N], d[N];
void dfs (int u, int f) {
d[u] = d[f] + 1;
st[0][dfn[u] = ++dfc] = f;
for (int v : g[u]) {
if (v ^ f) {
dfs(v, u);
}
}
}
IL int cp (int x, int y) {
return dfn[x] < dfn[y] ? x : y;
}
IL int lca (int x, int y) {
if (x == y) {
return x;
}
if ((x = dfn[x]) > (y = dfn[y])) {
swap(x, y);
}
int i = __lg(y - x++);
return cp(st[i][x], st[i][y - (1 << i) + 1]);
}
IL int dis (int x, int y) {
return d[x] + d[y] - 2 * d[lca(x, y)];
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
L (i, 1, n - 1) {
int u, v;
cin >> u >> v;
g[u].eb(v);
g[v].eb(u);
}
dfs(1, 0);
L (i, 1, 17) {
L (j, 1, n - (1 << i) + 1) {
st[i][j] = cp(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
}
}
L (i, 1, n) {
deg[i] = sz(g[i]);
}
priority_queue<pair<int, int>> q;
L (i, 1, n) {
sz[i] = 1;
if (deg[i] == 1) {
q.emplace(-sz[i], i);
}
}
while (-q.top().first <= n / 2) {
int u = q.top().second;
q.pop();
vis[u] = true;
for (int v : g[u]) {
if (!vis[v]) {
e[sz[u] + 1].eb(u);
sz[v] += sz[u];
}
if ((--deg[v]) == 1) {
q.emplace(-sz[v], v);
}
}
}
int L, R;
L = R = q.top().second;
R (i, n / 2 + 1, 1) {
ns[i] = dis(L, R);
for (auto u : e[i]) {
if (dis(L, u) > dis(L, R)) {
R = u;
}
if (dis(u, R) > dis(L, R)) {
L = u;
}
}
}
L (i, 1, n) {
cout << (i & 1 ? 1 : ns[i / 2] + 1) << '\n';
}
}
// I love WHQ!
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%