답안 #564224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564224 2022-05-18T19:19:56 Z nikatamliani Meetings 2 (JOI21_meetings2) C++14
20 / 100
4000 ms 21560 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
vector<int> g[N], subs[N];
int n, c, sub[N], done[N], f[N], ans[N], par[N], exc[N];
int maxi;
int upper;
void add(int x, int y) {
    // x = upper - x + 1;
    // assert(x > 0);
    // while (x <= upper) {
    //     f[x] = max(f[x], y);
    //     x += x & -x;
    // }
    f[x] = max(f[x], y);
}
int get(int x) {
    // int ans = -N;
    // x = upper - x + 1;
    // while (x > 0) {
    //     ans = max(ans, f[x]);
    //     x -= x & -x;
    // }
    // return ans;
    int ans = -1e9;
    for (int i = x; i <= upper; ++i) {
        ans = max(ans, f[i]);
    }
    return ans;
}
int find_centroid(int x, int p, int sz) {
    for (int to : g[x]) {
        if (!done[to] && to != p && sub[to] > sz / 2) {
            return find_centroid(to, x, sz);
        }
    }
    return x;
}
void calc(int x, int p) {
    sub[x] = 1;
    for (int to : g[x]) {
        if (!done[to] && p != to) {
            calc(to, x);
            sub[x] += sub[to];
        }
    }
}
int excSize(int x, int dir) {
    if (par[x] == dir) {
        return exc[x];
    }
    return n - exc[dir]; 
}
void insert(int x, int p, int anc, int pos, int depth = 1) {
    for (int to : g[x]) {
        if (to != p && !done[to]) {
            insert(to, x, anc, pos, depth + 1);
        }
    }
    int sub_size = excSize(x, p);
    if (pos == 1) {
        add(sub_size, depth);
    } else {
        ans[sub_size] = max(ans[sub_size], depth + get(sub_size) + 1);
        int v = min(sub_size, excSize(c, anc));
        ans[v] = max(ans[v], depth + 1);
    }
}
void find_par(int x, int p) {
    par[x] = p;
    exc[x] = 1;
    for (int to : g[x]) {
        if (to != p) {
            find_par(to, x);
            exc[x] += exc[to];
        }
    }
}
void decomp(int x, int p, int sz) {
    calc(x, p);
    c = find_centroid(x, -1, sz);
    upper = n;
    calc(c, p);
    for (int to : g[c]) {
        if (done[to]) continue;
        insert(to, c, to, 0); 
        insert(to, c, to, 1);
    }
    for (int i = 1; i <= upper; ++i) {
        f[i] = -1e9;
    }
    reverse(g[c].begin(), g[c].end());
    for (int to : g[c]) {
        if (done[to]) continue;
        insert(to, c, to, 0);
        insert(to, c, to, 1);
    }
    for (int i = 1; i <= upper; ++i) {
        f[i] = -1e9;
    }
    done[c] = 1;
    for (int to : g[c]) {
        if (!done[to]) {
            decomp(to, c, sub[to]);
        }
    }
}
int main() {
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 1; i <= n; ++i) {
        f[i] = -1e9;
    }
    find_par(1, 0);
    decomp(1, 0, n);
    ans[n] = 1;
    for (int i = n; i >= 1; --i) {
        ans[i] = max(ans[i], ans[i + 1]);
    }
    for (int i = 1; i <= n; ++i) {
        if (i % 2 == 0) {
            cout << ans[i / 2] << '\n';
        } else {
            cout << "1\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9708 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9644 KB Output is correct
6 Correct 5 ms 9696 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9668 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 7 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 5 ms 9608 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9624 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 5 ms 9620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9708 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9644 KB Output is correct
6 Correct 5 ms 9696 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9668 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 7 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 5 ms 9608 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9624 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 5 ms 9620 KB Output is correct
22 Correct 214 ms 9940 KB Output is correct
23 Correct 217 ms 9920 KB Output is correct
24 Correct 223 ms 9924 KB Output is correct
25 Correct 200 ms 9924 KB Output is correct
26 Correct 200 ms 9912 KB Output is correct
27 Correct 203 ms 9812 KB Output is correct
28 Correct 212 ms 9904 KB Output is correct
29 Correct 205 ms 9932 KB Output is correct
30 Correct 219 ms 9916 KB Output is correct
31 Correct 202 ms 9904 KB Output is correct
32 Correct 262 ms 10024 KB Output is correct
33 Correct 211 ms 10100 KB Output is correct
34 Correct 66 ms 9900 KB Output is correct
35 Correct 61 ms 9936 KB Output is correct
36 Correct 220 ms 9940 KB Output is correct
37 Correct 115 ms 9920 KB Output is correct
38 Correct 131 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9708 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9644 KB Output is correct
6 Correct 5 ms 9696 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9668 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 7 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 5 ms 9608 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9624 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 5 ms 9620 KB Output is correct
22 Correct 214 ms 9940 KB Output is correct
23 Correct 217 ms 9920 KB Output is correct
24 Correct 223 ms 9924 KB Output is correct
25 Correct 200 ms 9924 KB Output is correct
26 Correct 200 ms 9912 KB Output is correct
27 Correct 203 ms 9812 KB Output is correct
28 Correct 212 ms 9904 KB Output is correct
29 Correct 205 ms 9932 KB Output is correct
30 Correct 219 ms 9916 KB Output is correct
31 Correct 202 ms 9904 KB Output is correct
32 Correct 262 ms 10024 KB Output is correct
33 Correct 211 ms 10100 KB Output is correct
34 Correct 66 ms 9900 KB Output is correct
35 Correct 61 ms 9936 KB Output is correct
36 Correct 220 ms 9940 KB Output is correct
37 Correct 115 ms 9920 KB Output is correct
38 Correct 131 ms 9940 KB Output is correct
39 Execution timed out 4069 ms 21560 KB Time limit exceeded
40 Halted 0 ms 0 KB -