# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
403474 | 2021-05-13T08:26:49 Z | shenxy | 족보 (KOI18_family) | C++11 | 47 ms | 34884 KB |
#include <cstdio> #include <algorithm> #include <vector> using namespace std; typedef pair<int, int> ii; struct UFDS { vector<int> parent, size; UFDS(int N) { for (int i = 0; i < N; ++i) parent.push_back(i), size.push_back(1); } int find_parent(int i) { if (parent[i] == i) return i; return parent[i] = find_parent(parent[i]); } int get_size(int i) { return size[find_parent(i)]; } void union_set(int u, int v) { u = find_parent(u), v = find_parent(v); if (u == v) return; if (size[u] < size[v]) parent[u] = v, size[v] += size[u]; else parent[v] = u, size[u] += size[v]; } }; vector<int> children[10000], leaf[10000]; void dfs(int v) { for (int i: children[v]) { dfs(i); for (int j: leaf[i]) leaf[v].push_back(j); } } int main() { int N1, N2, K, p, r1, r2; scanf("%d %d %d", &N1, &N2, &K); for (int i = 0; i < K; ++i) leaf[i].push_back(i); for (int i = 0; i < N1; ++i) { scanf("%d", &p); if (p != 0) children[p - 1].push_back(i); else r1 = i; } for (int i = 0; i < K; ++i) { scanf("%d", &p); children[N1 + p - K - 1].push_back(i); } for (int i = 0; i < N2 - K; ++i) { scanf("%d", &p); if (p != 0) children[N1 + p - K - 1].push_back(N1 + i); else r2 = N1 + i; } dfs(r1); dfs(r2); ii srt[N1 + N2 - K]; for (int i = 0; i < N1 + N2 - K; ++i) srt[i] = ii(leaf[i].size(), i); sort(srt, srt + N1 + N2 - K); UFDS sets(K); for (int i = 0; i < N1 + N2 - K; ++i) { int x = srt[i].second; for (int i = 1; i < leaf[x].size(); ++i) sets.union_set(leaf[x][i - 1], leaf[x][i]); if (sets.get_size(leaf[x][0]) != leaf[x].size()) { printf("NO"); return 0; } } printf("YES"); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 716 KB | Output is correct |
2 | Correct | 1 ms | 716 KB | Output is correct |
3 | Correct | 1 ms | 716 KB | Output is correct |
4 | Correct | 1 ms | 716 KB | Output is correct |
5 | Correct | 1 ms | 752 KB | Output is correct |
6 | Correct | 1 ms | 716 KB | Output is correct |
7 | Correct | 1 ms | 716 KB | Output is correct |
8 | Correct | 1 ms | 716 KB | Output is correct |
9 | Correct | 1 ms | 716 KB | Output is correct |
10 | Correct | 1 ms | 716 KB | Output is correct |
11 | Correct | 1 ms | 716 KB | Output is correct |
12 | Correct | 1 ms | 716 KB | Output is correct |
13 | Correct | 1 ms | 716 KB | Output is correct |
14 | Correct | 1 ms | 716 KB | Output is correct |
15 | Correct | 2 ms | 716 KB | Output is correct |
16 | Correct | 1 ms | 716 KB | Output is correct |
17 | Correct | 1 ms | 716 KB | Output is correct |
18 | Correct | 1 ms | 716 KB | Output is correct |
19 | Correct | 2 ms | 716 KB | Output is correct |
20 | Correct | 1 ms | 716 KB | Output is correct |
21 | Correct | 1 ms | 716 KB | Output is correct |
22 | Correct | 1 ms | 716 KB | Output is correct |
23 | Correct | 1 ms | 716 KB | Output is correct |
24 | Correct | 1 ms | 716 KB | Output is correct |
25 | Correct | 1 ms | 716 KB | Output is correct |
26 | Correct | 1 ms | 716 KB | Output is correct |
27 | Correct | 1 ms | 716 KB | Output is correct |
28 | Correct | 1 ms | 716 KB | Output is correct |
29 | Correct | 1 ms | 716 KB | Output is correct |
30 | Correct | 1 ms | 716 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 716 KB | Output is correct |
2 | Correct | 1 ms | 716 KB | Output is correct |
3 | Correct | 1 ms | 716 KB | Output is correct |
4 | Correct | 1 ms | 716 KB | Output is correct |
5 | Correct | 1 ms | 752 KB | Output is correct |
6 | Correct | 1 ms | 716 KB | Output is correct |
7 | Correct | 1 ms | 716 KB | Output is correct |
8 | Correct | 1 ms | 716 KB | Output is correct |
9 | Correct | 1 ms | 716 KB | Output is correct |
10 | Correct | 1 ms | 716 KB | Output is correct |
11 | Correct | 1 ms | 716 KB | Output is correct |
12 | Correct | 1 ms | 716 KB | Output is correct |
13 | Correct | 1 ms | 716 KB | Output is correct |
14 | Correct | 1 ms | 716 KB | Output is correct |
15 | Correct | 2 ms | 716 KB | Output is correct |
16 | Correct | 1 ms | 716 KB | Output is correct |
17 | Correct | 1 ms | 716 KB | Output is correct |
18 | Correct | 1 ms | 716 KB | Output is correct |
19 | Correct | 2 ms | 716 KB | Output is correct |
20 | Correct | 1 ms | 716 KB | Output is correct |
21 | Correct | 1 ms | 716 KB | Output is correct |
22 | Correct | 1 ms | 716 KB | Output is correct |
23 | Correct | 1 ms | 716 KB | Output is correct |
24 | Correct | 1 ms | 716 KB | Output is correct |
25 | Correct | 1 ms | 716 KB | Output is correct |
26 | Correct | 1 ms | 716 KB | Output is correct |
27 | Correct | 1 ms | 716 KB | Output is correct |
28 | Correct | 1 ms | 716 KB | Output is correct |
29 | Correct | 1 ms | 716 KB | Output is correct |
30 | Correct | 1 ms | 716 KB | Output is correct |
31 | Correct | 1 ms | 716 KB | Output is correct |
32 | Correct | 1 ms | 716 KB | Output is correct |
33 | Correct | 1 ms | 716 KB | Output is correct |
34 | Correct | 1 ms | 716 KB | Output is correct |
35 | Correct | 1 ms | 716 KB | Output is correct |
36 | Correct | 1 ms | 716 KB | Output is correct |
37 | Correct | 1 ms | 716 KB | Output is correct |
38 | Correct | 1 ms | 716 KB | Output is correct |
39 | Correct | 1 ms | 716 KB | Output is correct |
40 | Correct | 1 ms | 716 KB | Output is correct |
41 | Correct | 1 ms | 716 KB | Output is correct |
42 | Correct | 1 ms | 716 KB | Output is correct |
43 | Correct | 1 ms | 716 KB | Output is correct |
44 | Correct | 1 ms | 716 KB | Output is correct |
45 | Correct | 1 ms | 716 KB | Output is correct |
46 | Correct | 1 ms | 716 KB | Output is correct |
47 | Correct | 1 ms | 716 KB | Output is correct |
48 | Correct | 1 ms | 716 KB | Output is correct |
49 | Correct | 1 ms | 716 KB | Output is correct |
50 | Correct | 1 ms | 716 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 716 KB | Output is correct |
2 | Correct | 1 ms | 716 KB | Output is correct |
3 | Correct | 1 ms | 716 KB | Output is correct |
4 | Correct | 1 ms | 716 KB | Output is correct |
5 | Correct | 1 ms | 752 KB | Output is correct |
6 | Correct | 1 ms | 716 KB | Output is correct |
7 | Correct | 1 ms | 716 KB | Output is correct |
8 | Correct | 1 ms | 716 KB | Output is correct |
9 | Correct | 1 ms | 716 KB | Output is correct |
10 | Correct | 1 ms | 716 KB | Output is correct |
11 | Correct | 1 ms | 716 KB | Output is correct |
12 | Correct | 1 ms | 716 KB | Output is correct |
13 | Correct | 1 ms | 716 KB | Output is correct |
14 | Correct | 1 ms | 716 KB | Output is correct |
15 | Correct | 2 ms | 716 KB | Output is correct |
16 | Correct | 1 ms | 716 KB | Output is correct |
17 | Correct | 1 ms | 716 KB | Output is correct |
18 | Correct | 1 ms | 716 KB | Output is correct |
19 | Correct | 2 ms | 716 KB | Output is correct |
20 | Correct | 1 ms | 716 KB | Output is correct |
21 | Correct | 1 ms | 716 KB | Output is correct |
22 | Correct | 1 ms | 716 KB | Output is correct |
23 | Correct | 1 ms | 716 KB | Output is correct |
24 | Correct | 1 ms | 716 KB | Output is correct |
25 | Correct | 1 ms | 716 KB | Output is correct |
26 | Correct | 1 ms | 716 KB | Output is correct |
27 | Correct | 1 ms | 716 KB | Output is correct |
28 | Correct | 1 ms | 716 KB | Output is correct |
29 | Correct | 1 ms | 716 KB | Output is correct |
30 | Correct | 1 ms | 716 KB | Output is correct |
31 | Correct | 1 ms | 716 KB | Output is correct |
32 | Correct | 1 ms | 716 KB | Output is correct |
33 | Correct | 1 ms | 716 KB | Output is correct |
34 | Correct | 1 ms | 716 KB | Output is correct |
35 | Correct | 1 ms | 716 KB | Output is correct |
36 | Correct | 1 ms | 716 KB | Output is correct |
37 | Correct | 1 ms | 716 KB | Output is correct |
38 | Correct | 1 ms | 716 KB | Output is correct |
39 | Correct | 1 ms | 716 KB | Output is correct |
40 | Correct | 1 ms | 716 KB | Output is correct |
41 | Correct | 1 ms | 716 KB | Output is correct |
42 | Correct | 1 ms | 716 KB | Output is correct |
43 | Correct | 1 ms | 716 KB | Output is correct |
44 | Correct | 1 ms | 716 KB | Output is correct |
45 | Correct | 1 ms | 716 KB | Output is correct |
46 | Correct | 1 ms | 716 KB | Output is correct |
47 | Correct | 1 ms | 716 KB | Output is correct |
48 | Correct | 1 ms | 716 KB | Output is correct |
49 | Correct | 1 ms | 716 KB | Output is correct |
50 | Correct | 1 ms | 716 KB | Output is correct |
51 | Correct | 5 ms | 1868 KB | Output is correct |
52 | Correct | 10 ms | 3240 KB | Output is correct |
53 | Correct | 10 ms | 3404 KB | Output is correct |
54 | Correct | 6 ms | 2124 KB | Output is correct |
55 | Correct | 4 ms | 1484 KB | Output is correct |
56 | Correct | 6 ms | 2124 KB | Output is correct |
57 | Correct | 5 ms | 1612 KB | Output is correct |
58 | Correct | 6 ms | 1868 KB | Output is correct |
59 | Correct | 6 ms | 1996 KB | Output is correct |
60 | Correct | 4 ms | 1356 KB | Output is correct |
61 | Correct | 46 ms | 34872 KB | Output is correct |
62 | Correct | 47 ms | 34884 KB | Output is correct |
63 | Correct | 6 ms | 1484 KB | Output is correct |
64 | Correct | 5 ms | 2036 KB | Output is correct |
65 | Correct | 2 ms | 716 KB | Output is correct |
66 | Correct | 6 ms | 2416 KB | Output is correct |
67 | Correct | 5 ms | 1768 KB | Output is correct |
68 | Correct | 5 ms | 1868 KB | Output is correct |
69 | Correct | 7 ms | 2636 KB | Output is correct |
70 | Correct | 4 ms | 1740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 716 KB | Output is correct |
2 | Correct | 1 ms | 716 KB | Output is correct |
3 | Correct | 1 ms | 716 KB | Output is correct |
4 | Correct | 1 ms | 716 KB | Output is correct |
5 | Correct | 1 ms | 752 KB | Output is correct |
6 | Correct | 1 ms | 716 KB | Output is correct |
7 | Correct | 1 ms | 716 KB | Output is correct |
8 | Correct | 1 ms | 716 KB | Output is correct |
9 | Correct | 1 ms | 716 KB | Output is correct |
10 | Correct | 1 ms | 716 KB | Output is correct |
11 | Correct | 1 ms | 716 KB | Output is correct |
12 | Correct | 1 ms | 716 KB | Output is correct |
13 | Correct | 1 ms | 716 KB | Output is correct |
14 | Correct | 1 ms | 716 KB | Output is correct |
15 | Correct | 2 ms | 716 KB | Output is correct |
16 | Correct | 1 ms | 716 KB | Output is correct |
17 | Correct | 1 ms | 716 KB | Output is correct |
18 | Correct | 1 ms | 716 KB | Output is correct |
19 | Correct | 2 ms | 716 KB | Output is correct |
20 | Correct | 1 ms | 716 KB | Output is correct |
21 | Correct | 1 ms | 716 KB | Output is correct |
22 | Correct | 1 ms | 716 KB | Output is correct |
23 | Correct | 1 ms | 716 KB | Output is correct |
24 | Correct | 1 ms | 716 KB | Output is correct |
25 | Correct | 1 ms | 716 KB | Output is correct |
26 | Correct | 1 ms | 716 KB | Output is correct |
27 | Correct | 1 ms | 716 KB | Output is correct |
28 | Correct | 1 ms | 716 KB | Output is correct |
29 | Correct | 1 ms | 716 KB | Output is correct |
30 | Correct | 1 ms | 716 KB | Output is correct |
31 | Correct | 1 ms | 716 KB | Output is correct |
32 | Correct | 1 ms | 716 KB | Output is correct |
33 | Correct | 1 ms | 716 KB | Output is correct |
34 | Correct | 1 ms | 716 KB | Output is correct |
35 | Correct | 1 ms | 716 KB | Output is correct |
36 | Correct | 1 ms | 716 KB | Output is correct |
37 | Correct | 1 ms | 716 KB | Output is correct |
38 | Correct | 1 ms | 716 KB | Output is correct |
39 | Correct | 1 ms | 716 KB | Output is correct |
40 | Correct | 1 ms | 716 KB | Output is correct |
41 | Correct | 1 ms | 716 KB | Output is correct |
42 | Correct | 1 ms | 716 KB | Output is correct |
43 | Correct | 1 ms | 716 KB | Output is correct |
44 | Correct | 1 ms | 716 KB | Output is correct |
45 | Correct | 1 ms | 716 KB | Output is correct |
46 | Correct | 1 ms | 716 KB | Output is correct |
47 | Correct | 1 ms | 716 KB | Output is correct |
48 | Correct | 1 ms | 716 KB | Output is correct |
49 | Correct | 1 ms | 716 KB | Output is correct |
50 | Correct | 1 ms | 716 KB | Output is correct |
51 | Correct | 5 ms | 1868 KB | Output is correct |
52 | Correct | 10 ms | 3240 KB | Output is correct |
53 | Correct | 10 ms | 3404 KB | Output is correct |
54 | Correct | 6 ms | 2124 KB | Output is correct |
55 | Correct | 4 ms | 1484 KB | Output is correct |
56 | Correct | 6 ms | 2124 KB | Output is correct |
57 | Correct | 5 ms | 1612 KB | Output is correct |
58 | Correct | 6 ms | 1868 KB | Output is correct |
59 | Correct | 6 ms | 1996 KB | Output is correct |
60 | Correct | 4 ms | 1356 KB | Output is correct |
61 | Correct | 46 ms | 34872 KB | Output is correct |
62 | Correct | 47 ms | 34884 KB | Output is correct |
63 | Correct | 6 ms | 1484 KB | Output is correct |
64 | Correct | 5 ms | 2036 KB | Output is correct |
65 | Correct | 2 ms | 716 KB | Output is correct |
66 | Correct | 6 ms | 2416 KB | Output is correct |
67 | Correct | 5 ms | 1768 KB | Output is correct |
68 | Correct | 5 ms | 1868 KB | Output is correct |
69 | Correct | 7 ms | 2636 KB | Output is correct |
70 | Correct | 4 ms | 1740 KB | Output is correct |
71 | Runtime error | 3 ms | 1868 KB | Execution killed with signal 11 |
72 | Halted | 0 ms | 0 KB | - |