Submission #642173

# Submission time Handle Problem Language Result Execution time Memory
642173 2022-09-18T15:37:41 Z skittles1412 Meetings 2 (JOI21_meetings2) C++17
20 / 100
4000 ms 37584 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
    cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t << " | ";
    dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
         << ": ";                                          \
    dbgh(__VA_ARGS__)
#else
#define cerr   \
    if (false) \
    cerr
#define dbg(...)
#endif

#define endl "\n"
#define mp make_pair
#define long int64_t
#define sz(x) int(std::size(x))

constexpr int maxn = 2e5 + 5;

bool vis[maxn];
int n, siz[maxn], depth[maxn], ans[maxn];
vector<int> graph[maxn], siz1[maxn];

void pdfs(int u, int p = -1) {
    siz[u] = 1;
    for (auto& v : graph[u]) {
        if (v != p) {
            pdfs(v, u);
            siz[u] += siz[v];
            siz1[u].push_back(siz[v]);
        } else {
            siz1[u].push_back(-1);
        }
    }
    if (p != -1) {
        *find(begin(siz1[u]), end(siz1[u]), -1) = n - siz[u];
    }
}

void go(int u) {
    struct DepthDfs {
        void dfs(int u, int p = -1, int d = 0) {
            depth[u] = d;
            for (auto& v : graph[u]) {
                if (!vis[v] && v != p) {
                    dfs(v, u, d + 1);
                }
            }
        }
        
        static void solve(int u) {
            DepthDfs().dfs(u);
        }
    };
    DepthDfs::solve(u);
    
    struct Dfs {
        vector<pair<int, int>> ch;

        void dfs(int u, int p) {
            ch.emplace_back(
                n - siz1[u][find(begin(graph[u]), end(graph[u]), p) -
                            graph[u].begin()],
                depth[u]);
            for (auto& v : graph[u]) {
                if (!vis[v] && v != p) {
                    dfs(v, u);
                }
            }
        }
        
        static vector<pair<int, int>> solve(int u, int p) {
            Dfs d;
            d.dfs(u, p);
            return d.ch;
        }
    };

    for (int _i = 0; _i < 2; _i++) {
        map<int, int> copt;
        auto query = [&](int x, int d) -> void {
            auto it = copt.lower_bound(x);
            if (it != copt.end()) {
                ans[x] = max(ans[x], d + it->second);
            }
        };
        auto update = [&](int x, int d) -> void {
            auto it = copt.lower_bound(x);
            if (it != copt.end() && it->second >= d) {
                return;
            }
            while (it != copt.begin() && d >= (--it)->second) {
                it = copt.erase(it);
            }
            copt[x] = d;
        };

        for (int i = 0; i < sz(graph[u]); i++) {
            int v = graph[u][i], csz = n - siz1[u][i];
            if (!u) {
                dbg(csz);
            }
            if (vis[v]) {
                continue;
            }
            auto&& cv = Dfs::solve(v, u);
            for (auto& [x, d] : cv) {
                query(x, d);
                ans[min(x, csz)] = max(ans[min(x, csz)], d);
            }
            for (auto& [x, d] : cv) {
                update(x, d);
            }
        }

        reverse(begin(graph[u]), end(graph[u]));
        reverse(begin(siz1[u]), end(siz1[u]));
    }
}

void dfs(int u) {
    while (true) {
        pair<int, int> mx {-1, -1};
        for (auto& v : graph[u]) {
            if (!vis[v]) {
                mx = max(mx, mp(siz[v], v));
            }
        }
        if (mx.first <= n / 2) {
            break;
        }
        int v = mx.second;
        siz[u] -= siz[v];
        siz[v] += siz[u];
        u = v;
    }
    go(u);
    vis[u] = true;
    for (auto& v : graph[u]) {
        if (!vis[v]) {
            dfs(v);
        }
    }
}

void solve() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    pdfs(0);
    dfs(0);
    for (int i = n; i >= 0; i--) {
        ans[i] = max(ans[i], ans[i + 1]);
    }
    for (int i = 1; i <= n; i++) {
        if (i & 1) {
            cout << 1 << endl;
        } else {
            cout << ans[i / 2] + 1 << endl;
        }
    }
}

int main() {
    cin.tie(nullptr);
    cin.exceptions(ios::failbit);
    ios_base::sync_with_stdio(false);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9628 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9724 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 6 ms 9728 KB Output is correct
8 Correct 5 ms 9724 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9728 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9728 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9728 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 7 ms 9684 KB Output is correct
19 Correct 5 ms 9620 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 6 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9628 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9724 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 6 ms 9728 KB Output is correct
8 Correct 5 ms 9724 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9728 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9728 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9728 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 7 ms 9684 KB Output is correct
19 Correct 5 ms 9620 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 6 ms 9684 KB Output is correct
22 Correct 12 ms 10128 KB Output is correct
23 Correct 12 ms 10128 KB Output is correct
24 Correct 13 ms 10068 KB Output is correct
25 Correct 12 ms 10124 KB Output is correct
26 Correct 11 ms 10068 KB Output is correct
27 Correct 11 ms 10068 KB Output is correct
28 Correct 13 ms 10132 KB Output is correct
29 Correct 13 ms 10124 KB Output is correct
30 Correct 15 ms 10124 KB Output is correct
31 Correct 12 ms 10120 KB Output is correct
32 Correct 461 ms 10296 KB Output is correct
33 Correct 972 ms 10452 KB Output is correct
34 Correct 8 ms 10068 KB Output is correct
35 Correct 9 ms 10116 KB Output is correct
36 Correct 25 ms 10176 KB Output is correct
37 Correct 9 ms 10084 KB Output is correct
38 Correct 245 ms 10252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9628 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9724 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 6 ms 9728 KB Output is correct
8 Correct 5 ms 9724 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9728 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9728 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9728 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 7 ms 9684 KB Output is correct
19 Correct 5 ms 9620 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 6 ms 9684 KB Output is correct
22 Correct 12 ms 10128 KB Output is correct
23 Correct 12 ms 10128 KB Output is correct
24 Correct 13 ms 10068 KB Output is correct
25 Correct 12 ms 10124 KB Output is correct
26 Correct 11 ms 10068 KB Output is correct
27 Correct 11 ms 10068 KB Output is correct
28 Correct 13 ms 10132 KB Output is correct
29 Correct 13 ms 10124 KB Output is correct
30 Correct 15 ms 10124 KB Output is correct
31 Correct 12 ms 10120 KB Output is correct
32 Correct 461 ms 10296 KB Output is correct
33 Correct 972 ms 10452 KB Output is correct
34 Correct 8 ms 10068 KB Output is correct
35 Correct 9 ms 10116 KB Output is correct
36 Correct 25 ms 10176 KB Output is correct
37 Correct 9 ms 10084 KB Output is correct
38 Correct 245 ms 10252 KB Output is correct
39 Correct 717 ms 29268 KB Output is correct
40 Correct 655 ms 28352 KB Output is correct
41 Correct 687 ms 28860 KB Output is correct
42 Correct 652 ms 28884 KB Output is correct
43 Correct 686 ms 29904 KB Output is correct
44 Correct 681 ms 28960 KB Output is correct
45 Execution timed out 4089 ms 37584 KB Time limit exceeded
46 Halted 0 ms 0 KB -