답안 #873058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873058 2023-11-14T11:42:25 Z sleepntsheep Meetings 2 (JOI21_meetings2) C++17
0 / 100
1 ms 4492 KB
#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using i64 = long long;
using f80 = long double;
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false)

#define N 200000
#define ALL(x) x.begin(), x.end()

int n, ne, h[N], a[N], b[N], c[N], sz[N], sts[N], alloc, ans[N+1], dd[N];
struct { int v, l; } g[2*N-1];

inline __attribute__((always_inline)) void add_edge(int u, int v)
{
    g[++ne] = {v, h[u]}; h[u] = ne;
}

void dfsd(int u, int p)
{
    for (auto j = h[u]; j; j = g[j].l) if (g[j].v != p) 
        dd[g[j].v] = dd[u] + 1, dfsd(g[j].v, u);
}

void dfs0(int u, int p)
{
    sz[u] = 1;
    for (auto j = h[u]; j; j = g[j].l) if (g[j].v != p) 
    {
        int v = g[j].v;
        dfs0(v, u);
        sz[u] += sz[v];
        if (a[v] + 1 >= a[u]) c[u] = a[u], a[u] = a[v] + 1;
        else if (a[v] + 1 >= c[u]) c[u] = a[v] + 1;
    }
}

void dfs1(int u, int p)
{
    for (auto j = h[u]; j; j = g[j].l) if (g[j].v != p)
    {
        int v = g[j].v;
        b[v] = b[u] + 1;
        if (a[v] + 1 != a[u]) b[v] = max(b[v], a[u] + 1);
        else b[v] = max(b[v], c[u] + 1);
        dfs1(v, u);
    }
}

void init()
{
    ShinLena;
    cin >> n;
    for (int u, v, i = 1; i < n; ++i) cin >> u >> v, --u, --v, add_edge(u, v), add_edge(v, u);

    dfsd(0, 0);
    int root = 0, rootdep = -1;
    for (int i = 0; i < n; ++i) if (dd[i] > rootdep) rootdep = dd[i], root = i;
    dfsd(root, root);
    root = 0, rootdep = -1;
    for (int i = 0; i < n; ++i) if (dd[i] > rootdep) rootdep = dd[i], root = i;

    dfs0(root, root);
    dfs1(root, root);
    for (int i = 0; i < n; ++i)
        ans[sz[i]] = max(ans[sz[i]], b[i]);
    for (int i = n; i--;) ans[i] = max(ans[i], ans[i+1]);
}

void answer()
{
    for (int i = 1; i <= n; ++i)
    {
        if (i&1) cout << "1\n";
        else cout << ans[i/2] + 2 - i/ 2<< '\n';
    }
}

int main()
{
    init();
    answer();

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4492 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4492 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4492 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -