답안 #724977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724977 2023-04-16T12:06:31 Z piOOE Meetings 2 (JOI21_meetings2) C++17
20 / 100
4000 ms 39172 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<vector<int>> adj(n);
    vector<int> parent(n), siz(n), depth(n);

    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        a -= 1, b -= 1;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    auto hld = [&](auto self, int v) -> void {
        siz[v] = 1;
        for (int &to : adj[v]) {
            adj[to].erase(find(adj[to].begin(), adj[to].end(), v));
            depth[to] = depth[v] + 1;
            self(self, to);

            siz[v] += siz[to];
            if (siz[to] > siz[adj[v][0]]) {
                swap(to, adj[v][0]);
            }
        }
    };

    hld(hld, 0);

    vector<map<int, int>> st(n);

    auto insert = [&](map<int, int> &mp, int x, int y) -> void {
        auto it = mp.lower_bound(x);
        if (it != mp.end() && it->second >= y) {
            return;
        }

        mp[x] = y;

        while (true) {
            it = mp.lower_bound(x);
            if (it == mp.begin() || prev(it)->second > y) {
                break;
            }
            mp.erase(prev(it));
        }
    };

    constexpr int inf = 1e8 + 7;

    auto query = [&](map<int, int> &mp, int x) {
        auto it = mp.lower_bound(x);
        return it == mp.end() ? -inf : it->second;
    };

    vector<int> best(n + 1);

    auto dfs = [&](auto self, int v) -> void {
        if (adj[v].empty()) {
            insert(st[v], 1, depth[v]);
            return;
        }

        for (int to : adj[v]) {
            self(self, to);
        }

        int x = adj[v][0];
        int now = min(siz[x], n - siz[x]);
        int nxt = 0;

        for (int s = now; s > nxt; --s) {
            int d = query(st[x], s);
            best[min(s, n - siz[x])] = max(best[min(s, n - siz[x])], d - depth[v] + 1);
        }

        swap(st[v], st[x]);

        for (int to : adj[v]) {
            if (to == x) {
                continue;
            }
            for (int s = 1; s <= siz[to]; ++s) {
                int d = query(st[to], s);
                best[s] = max(best[s], d + query(st[v], s) - depth[v] * 2 + 1);
                best[min(s, n - siz[to])] = max(best[min(s, n - siz[to])], d - depth[v] + 1);
            }
            for (auto [a, b] : st[to]) {
                insert(st[v], a, b);
            }
            st[to].clear();
        }

        insert(st[v], siz[v], depth[v]);
    };

    dfs(dfs, 0);

    vector<int> ans(n + 1, 1);

    for (int i = 1; i <= n / 2; ++i) {
        ans[i * 2] = max(1, best[i]);
    }

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

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 3 ms 840 KB Output is correct
23 Correct 3 ms 852 KB Output is correct
24 Correct 4 ms 844 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 3 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 3 ms 852 KB Output is correct
30 Correct 3 ms 852 KB Output is correct
31 Correct 3 ms 852 KB Output is correct
32 Correct 59 ms 1176 KB Output is correct
33 Correct 96 ms 1436 KB Output is correct
34 Correct 3 ms 980 KB Output is correct
35 Correct 3 ms 980 KB Output is correct
36 Correct 4 ms 852 KB Output is correct
37 Correct 2 ms 852 KB Output is correct
38 Correct 22 ms 1044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 3 ms 840 KB Output is correct
23 Correct 3 ms 852 KB Output is correct
24 Correct 4 ms 844 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 3 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 3 ms 852 KB Output is correct
30 Correct 3 ms 852 KB Output is correct
31 Correct 3 ms 852 KB Output is correct
32 Correct 59 ms 1176 KB Output is correct
33 Correct 96 ms 1436 KB Output is correct
34 Correct 3 ms 980 KB Output is correct
35 Correct 3 ms 980 KB Output is correct
36 Correct 4 ms 852 KB Output is correct
37 Correct 2 ms 852 KB Output is correct
38 Correct 22 ms 1044 KB Output is correct
39 Correct 232 ms 27140 KB Output is correct
40 Correct 222 ms 26660 KB Output is correct
41 Correct 218 ms 27276 KB Output is correct
42 Correct 219 ms 27716 KB Output is correct
43 Correct 223 ms 27712 KB Output is correct
44 Correct 212 ms 27664 KB Output is correct
45 Execution timed out 4075 ms 39172 KB Time limit exceeded
46 Halted 0 ms 0 KB -