Submission #896631

# Submission time Handle Problem Language Result Execution time Memory
896631 2024-01-01T19:37:52 Z juliany2 Meetings 2 (JOI21_meetings2) C++17
20 / 100
4000 ms 21988 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()

const int N = 2e5 + 7;
int n;
vector<int> adj[N], s[N];
bool col[N];
int sz[N], dist[N], bst;
int ans[N];

void dfs(int v = 1, int p = 0) {
    sz[v] = 1;
    for (int u : adj[v]) {
        if (u != p) {
            dfs(u, v);
            sz[v] += sz[u];
        }
    }

    s[sz[v]].push_back(v);
}

void calc(int v = 1, int p = 0) {
    if (col[v]) {
        dist[v] = max(dist[v], 0);
        bst = max(bst, dist[v] + 1);
    }

    for (int u : adj[v]) {
        if (u != p) {
            dist[u] = max(dist[u], dist[v] + 1);
            calc(u, v);
        }
    }
}

int upd(int s) {
    col[s] = 1;
    memset(dist, -1, sizeof(dist));

    int ret = 0;

    queue<int> q;
    q.push(s);
    dist[s] = 0;

    while (q.size()) {
        int v = q.front();
        q.pop();

        if (col[v])
            ret = max(ret, dist[v] + 1);

        for (int u : adj[v]) {
            if (dist[u] < 0) {
                dist[u] = dist[v] + 1;
                q.push(u);
            }
        }
    }

    return ret;
}

int main() {
    cin.tie(0)->sync_with_stdio(false);

    cin >> n;

    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs();

    for (int i = n; i >= 1; i--) {
        if (i % 2)
            ans[i] = 1;
        else {
            for (int x : s[i / 2])
                ans[i] = max(ans[i], upd(x));
            for (int x : s[n - i / 2])
                ans[i] = max(ans[i], upd(x));

            fill(dist + 1, dist + n + 1, (int) -1e9);
            bst = 0;
            calc();

            ans[i] = max(ans[i], bst + 1);
            ans[i] = max(ans[i], ans[i + 2]);
        }
    }

    for (int i = 1; i <= n; i++)
        cout << ans[i] << '\n';

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 12120 KB Output is correct
2 Correct 2 ms 12120 KB Output is correct
3 Correct 3 ms 12100 KB Output is correct
4 Correct 3 ms 11984 KB Output is correct
5 Correct 3 ms 12124 KB Output is correct
6 Correct 3 ms 12124 KB Output is correct
7 Correct 3 ms 12124 KB Output is correct
8 Correct 3 ms 12124 KB Output is correct
9 Correct 3 ms 12124 KB Output is correct
10 Correct 3 ms 12120 KB Output is correct
11 Correct 3 ms 12124 KB Output is correct
12 Correct 3 ms 12124 KB Output is correct
13 Correct 3 ms 12124 KB Output is correct
14 Correct 3 ms 12124 KB Output is correct
15 Correct 4 ms 12124 KB Output is correct
16 Correct 3 ms 12124 KB Output is correct
17 Correct 3 ms 12124 KB Output is correct
18 Correct 3 ms 12124 KB Output is correct
19 Correct 3 ms 12164 KB Output is correct
20 Correct 3 ms 12120 KB Output is correct
21 Correct 3 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12120 KB Output is correct
2 Correct 2 ms 12120 KB Output is correct
3 Correct 3 ms 12100 KB Output is correct
4 Correct 3 ms 11984 KB Output is correct
5 Correct 3 ms 12124 KB Output is correct
6 Correct 3 ms 12124 KB Output is correct
7 Correct 3 ms 12124 KB Output is correct
8 Correct 3 ms 12124 KB Output is correct
9 Correct 3 ms 12124 KB Output is correct
10 Correct 3 ms 12120 KB Output is correct
11 Correct 3 ms 12124 KB Output is correct
12 Correct 3 ms 12124 KB Output is correct
13 Correct 3 ms 12124 KB Output is correct
14 Correct 3 ms 12124 KB Output is correct
15 Correct 4 ms 12124 KB Output is correct
16 Correct 3 ms 12124 KB Output is correct
17 Correct 3 ms 12124 KB Output is correct
18 Correct 3 ms 12124 KB Output is correct
19 Correct 3 ms 12164 KB Output is correct
20 Correct 3 ms 12120 KB Output is correct
21 Correct 3 ms 12124 KB Output is correct
22 Correct 282 ms 12400 KB Output is correct
23 Correct 287 ms 12424 KB Output is correct
24 Correct 272 ms 12408 KB Output is correct
25 Correct 274 ms 12380 KB Output is correct
26 Correct 274 ms 12424 KB Output is correct
27 Correct 283 ms 12376 KB Output is correct
28 Correct 294 ms 12628 KB Output is correct
29 Correct 286 ms 12404 KB Output is correct
30 Correct 284 ms 12424 KB Output is correct
31 Correct 285 ms 12408 KB Output is correct
32 Correct 359 ms 12380 KB Output is correct
33 Correct 271 ms 12624 KB Output is correct
34 Correct 227 ms 12416 KB Output is correct
35 Correct 186 ms 12436 KB Output is correct
36 Correct 236 ms 12432 KB Output is correct
37 Correct 187 ms 12372 KB Output is correct
38 Correct 232 ms 12516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12120 KB Output is correct
2 Correct 2 ms 12120 KB Output is correct
3 Correct 3 ms 12100 KB Output is correct
4 Correct 3 ms 11984 KB Output is correct
5 Correct 3 ms 12124 KB Output is correct
6 Correct 3 ms 12124 KB Output is correct
7 Correct 3 ms 12124 KB Output is correct
8 Correct 3 ms 12124 KB Output is correct
9 Correct 3 ms 12124 KB Output is correct
10 Correct 3 ms 12120 KB Output is correct
11 Correct 3 ms 12124 KB Output is correct
12 Correct 3 ms 12124 KB Output is correct
13 Correct 3 ms 12124 KB Output is correct
14 Correct 3 ms 12124 KB Output is correct
15 Correct 4 ms 12124 KB Output is correct
16 Correct 3 ms 12124 KB Output is correct
17 Correct 3 ms 12124 KB Output is correct
18 Correct 3 ms 12124 KB Output is correct
19 Correct 3 ms 12164 KB Output is correct
20 Correct 3 ms 12120 KB Output is correct
21 Correct 3 ms 12124 KB Output is correct
22 Correct 282 ms 12400 KB Output is correct
23 Correct 287 ms 12424 KB Output is correct
24 Correct 272 ms 12408 KB Output is correct
25 Correct 274 ms 12380 KB Output is correct
26 Correct 274 ms 12424 KB Output is correct
27 Correct 283 ms 12376 KB Output is correct
28 Correct 294 ms 12628 KB Output is correct
29 Correct 286 ms 12404 KB Output is correct
30 Correct 284 ms 12424 KB Output is correct
31 Correct 285 ms 12408 KB Output is correct
32 Correct 359 ms 12380 KB Output is correct
33 Correct 271 ms 12624 KB Output is correct
34 Correct 227 ms 12416 KB Output is correct
35 Correct 186 ms 12436 KB Output is correct
36 Correct 236 ms 12432 KB Output is correct
37 Correct 187 ms 12372 KB Output is correct
38 Correct 232 ms 12516 KB Output is correct
39 Execution timed out 4038 ms 21988 KB Time limit exceeded
40 Halted 0 ms 0 KB -