답안 #564197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564197 2022-05-18T17:37:34 Z nikatamliani Meetings 2 (JOI21_meetings2) C++14
20 / 100
411 ms 5528 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
vector<int> g[N];
int n, sub[N], ans[N], depth[N], anc[N];
void dfs(int x, int p, int root) {
    depth[x] = depth[p] + 1;
    sub[x] = 1;
    if (p == root) {
        anc[x] = x;
    } else if (x != root) {
        anc[x] = anc[p];
    }
    for (int to : g[x]) {
        if (to != p) {
            dfs(to, x, root);
            sub[x] += sub[to];
        }
    }
}
int main() {
    cin >> n;
    if (n > 5000) {
        return 0;
    }
    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 root = 1; root <= n; ++root) {
        dfs(root, 0, root);
        for (int i = 1; i <= n; ++i) {
            int v = min(sub[i], n - sub[anc[i]]);
            if (n - sub[anc[i]] <= sub[i]) {
	            ans[v] = max(ans[v], depth[i]);
            }
        }
    }
    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) {
            cout << 1 << '\n';
        } else {
            cout << ans[i / 2] << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5004 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5004 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 392 ms 5224 KB Output is correct
23 Correct 375 ms 5228 KB Output is correct
24 Correct 411 ms 5224 KB Output is correct
25 Correct 376 ms 5224 KB Output is correct
26 Correct 366 ms 5240 KB Output is correct
27 Correct 389 ms 5232 KB Output is correct
28 Correct 403 ms 5452 KB Output is correct
29 Correct 377 ms 5224 KB Output is correct
30 Correct 370 ms 5220 KB Output is correct
31 Correct 394 ms 5220 KB Output is correct
32 Correct 364 ms 5400 KB Output is correct
33 Correct 327 ms 5528 KB Output is correct
34 Correct 335 ms 5224 KB Output is correct
35 Correct 228 ms 5232 KB Output is correct
36 Correct 269 ms 5252 KB Output is correct
37 Correct 222 ms 5240 KB Output is correct
38 Correct 275 ms 5380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5004 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 392 ms 5224 KB Output is correct
23 Correct 375 ms 5228 KB Output is correct
24 Correct 411 ms 5224 KB Output is correct
25 Correct 376 ms 5224 KB Output is correct
26 Correct 366 ms 5240 KB Output is correct
27 Correct 389 ms 5232 KB Output is correct
28 Correct 403 ms 5452 KB Output is correct
29 Correct 377 ms 5224 KB Output is correct
30 Correct 370 ms 5220 KB Output is correct
31 Correct 394 ms 5220 KB Output is correct
32 Correct 364 ms 5400 KB Output is correct
33 Correct 327 ms 5528 KB Output is correct
34 Correct 335 ms 5224 KB Output is correct
35 Correct 228 ms 5232 KB Output is correct
36 Correct 269 ms 5252 KB Output is correct
37 Correct 222 ms 5240 KB Output is correct
38 Correct 275 ms 5380 KB Output is correct
39 Incorrect 3 ms 4948 KB Output isn't correct
40 Halted 0 ms 0 KB -