# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
112593 | 2019-05-20T18:40:22 Z | Bruteforceman | Mergers (JOI19_mergers) | C++11 | 1398 ms | 126668 KB |
#include "bits/stdc++.h" using namespace std; int city[500010]; int cnt[500010]; vector <int> g[500010]; int P[500010]; int root(int x) { if(x == P[x]) return P[x]; return P[x] = root(P[x]); } void join(int x, int y) { x = root(x); y = root(y); if(x != y) { P[x] = y; } } void dfs(int x, int par, map <int, int> &s) { if(cnt[city[x]] > 1) { s[city[x]] = 1; } for(auto i : g[x]) { if(i - par) { map <int, int> t; dfs(i, x, t); if(t.size() > s.size()) s.swap(t); for(auto j : t) { s[j.first] += j.second; if(cnt[j.first] == s[j.first]) { s.erase(j.first); } } } } if(!s.empty()) { join(x, par); } } int l[500010], r[500010]; int deg[500010]; int main(int argc, char const *argv[]) { int n, m; scanf("%d %d", &n, &m); for(int i = 1; i < n; i++) { int p, q; scanf("%d %d", &p, &q); g[p].push_back(q); g[q].push_back(p); l[i] = p; r[i] = q; } for(int i = 1; i <= n; i++) { scanf("%d", &city[i]); cnt[city[i]] += 1; P[i] = i; } map <int, int> s; dfs(1, 0, s); set <int> node; for(int i = 1; i <= n; i++) { node.insert(root(i)); } for(int i = 1; i < n; i++) { if(root(l[i]) != root(r[i])) { ++deg[root(l[i])]; ++deg[root(r[i])]; } } int ans = 0; for(auto i : node) { if(deg[i] <= 1) { ++ans; } } if(ans > 1) { ans = (ans + 1) / 2; } else { ans = 0; } printf("%d\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12032 KB | Output is correct |
2 | Correct | 12 ms | 12032 KB | Output is correct |
3 | Correct | 11 ms | 12160 KB | Output is correct |
4 | Correct | 14 ms | 12160 KB | Output is correct |
5 | Correct | 11 ms | 12236 KB | Output is correct |
6 | Correct | 12 ms | 12160 KB | Output is correct |
7 | Correct | 12 ms | 12032 KB | Output is correct |
8 | Correct | 12 ms | 12160 KB | Output is correct |
9 | Correct | 12 ms | 12032 KB | Output is correct |
10 | Correct | 12 ms | 12160 KB | Output is correct |
11 | Correct | 12 ms | 12160 KB | Output is correct |
12 | Correct | 12 ms | 12160 KB | Output is correct |
13 | Correct | 12 ms | 12132 KB | Output is correct |
14 | Correct | 12 ms | 12160 KB | Output is correct |
15 | Correct | 13 ms | 12160 KB | Output is correct |
16 | Correct | 11 ms | 12160 KB | Output is correct |
17 | Correct | 11 ms | 12160 KB | Output is correct |
18 | Correct | 11 ms | 12160 KB | Output is correct |
19 | Correct | 11 ms | 12032 KB | Output is correct |
20 | Correct | 12 ms | 12132 KB | Output is correct |
21 | Correct | 13 ms | 12160 KB | Output is correct |
22 | Correct | 11 ms | 12160 KB | Output is correct |
23 | Correct | 11 ms | 12160 KB | Output is correct |
24 | Correct | 12 ms | 12160 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12032 KB | Output is correct |
2 | Correct | 12 ms | 12032 KB | Output is correct |
3 | Correct | 11 ms | 12160 KB | Output is correct |
4 | Correct | 14 ms | 12160 KB | Output is correct |
5 | Correct | 11 ms | 12236 KB | Output is correct |
6 | Correct | 12 ms | 12160 KB | Output is correct |
7 | Correct | 12 ms | 12032 KB | Output is correct |
8 | Correct | 12 ms | 12160 KB | Output is correct |
9 | Correct | 12 ms | 12032 KB | Output is correct |
10 | Correct | 12 ms | 12160 KB | Output is correct |
11 | Correct | 12 ms | 12160 KB | Output is correct |
12 | Correct | 12 ms | 12160 KB | Output is correct |
13 | Correct | 12 ms | 12132 KB | Output is correct |
14 | Correct | 12 ms | 12160 KB | Output is correct |
15 | Correct | 13 ms | 12160 KB | Output is correct |
16 | Correct | 11 ms | 12160 KB | Output is correct |
17 | Correct | 11 ms | 12160 KB | Output is correct |
18 | Correct | 11 ms | 12160 KB | Output is correct |
19 | Correct | 11 ms | 12032 KB | Output is correct |
20 | Correct | 12 ms | 12132 KB | Output is correct |
21 | Correct | 13 ms | 12160 KB | Output is correct |
22 | Correct | 11 ms | 12160 KB | Output is correct |
23 | Correct | 11 ms | 12160 KB | Output is correct |
24 | Correct | 12 ms | 12160 KB | Output is correct |
25 | Correct | 20 ms | 12032 KB | Output is correct |
26 | Correct | 15 ms | 12332 KB | Output is correct |
27 | Correct | 14 ms | 12288 KB | Output is correct |
28 | Correct | 14 ms | 12672 KB | Output is correct |
29 | Correct | 14 ms | 12416 KB | Output is correct |
30 | Correct | 15 ms | 12288 KB | Output is correct |
31 | Correct | 12 ms | 12152 KB | Output is correct |
32 | Correct | 15 ms | 12672 KB | Output is correct |
33 | Correct | 12 ms | 12160 KB | Output is correct |
34 | Correct | 14 ms | 12288 KB | Output is correct |
35 | Correct | 14 ms | 12388 KB | Output is correct |
36 | Correct | 15 ms | 12288 KB | Output is correct |
37 | Correct | 15 ms | 12288 KB | Output is correct |
38 | Correct | 12 ms | 12160 KB | Output is correct |
39 | Correct | 15 ms | 12416 KB | Output is correct |
40 | Correct | 14 ms | 12288 KB | Output is correct |
41 | Correct | 14 ms | 12288 KB | Output is correct |
42 | Correct | 14 ms | 12416 KB | Output is correct |
43 | Correct | 14 ms | 12972 KB | Output is correct |
44 | Correct | 13 ms | 12160 KB | Output is correct |
45 | Correct | 14 ms | 12416 KB | Output is correct |
46 | Correct | 15 ms | 12288 KB | Output is correct |
47 | Correct | 12 ms | 12160 KB | Output is correct |
48 | Correct | 14 ms | 12288 KB | Output is correct |
49 | Correct | 14 ms | 12416 KB | Output is correct |
50 | Correct | 15 ms | 12544 KB | Output is correct |
51 | Correct | 14 ms | 12288 KB | Output is correct |
52 | Correct | 13 ms | 12288 KB | Output is correct |
53 | Correct | 15 ms | 12288 KB | Output is correct |
54 | Correct | 14 ms | 12288 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12032 KB | Output is correct |
2 | Correct | 12 ms | 12032 KB | Output is correct |
3 | Correct | 11 ms | 12160 KB | Output is correct |
4 | Correct | 14 ms | 12160 KB | Output is correct |
5 | Correct | 11 ms | 12236 KB | Output is correct |
6 | Correct | 12 ms | 12160 KB | Output is correct |
7 | Correct | 12 ms | 12032 KB | Output is correct |
8 | Correct | 12 ms | 12160 KB | Output is correct |
9 | Correct | 12 ms | 12032 KB | Output is correct |
10 | Correct | 12 ms | 12160 KB | Output is correct |
11 | Correct | 12 ms | 12160 KB | Output is correct |
12 | Correct | 12 ms | 12160 KB | Output is correct |
13 | Correct | 12 ms | 12132 KB | Output is correct |
14 | Correct | 12 ms | 12160 KB | Output is correct |
15 | Correct | 13 ms | 12160 KB | Output is correct |
16 | Correct | 11 ms | 12160 KB | Output is correct |
17 | Correct | 11 ms | 12160 KB | Output is correct |
18 | Correct | 11 ms | 12160 KB | Output is correct |
19 | Correct | 11 ms | 12032 KB | Output is correct |
20 | Correct | 12 ms | 12132 KB | Output is correct |
21 | Correct | 13 ms | 12160 KB | Output is correct |
22 | Correct | 11 ms | 12160 KB | Output is correct |
23 | Correct | 11 ms | 12160 KB | Output is correct |
24 | Correct | 12 ms | 12160 KB | Output is correct |
25 | Correct | 12 ms | 12160 KB | Output is correct |
26 | Correct | 85 ms | 18604 KB | Output is correct |
27 | Correct | 142 ms | 18512 KB | Output is correct |
28 | Correct | 14 ms | 12416 KB | Output is correct |
29 | Correct | 12 ms | 12032 KB | Output is correct |
30 | Correct | 11 ms | 12160 KB | Output is correct |
31 | Correct | 116 ms | 18680 KB | Output is correct |
32 | Correct | 13 ms | 12288 KB | Output is correct |
33 | Correct | 138 ms | 38580 KB | Output is correct |
34 | Correct | 136 ms | 18296 KB | Output is correct |
35 | Correct | 14 ms | 12288 KB | Output is correct |
36 | Correct | 134 ms | 20728 KB | Output is correct |
37 | Correct | 14 ms | 12288 KB | Output is correct |
38 | Correct | 14 ms | 12288 KB | Output is correct |
39 | Correct | 101 ms | 18688 KB | Output is correct |
40 | Correct | 14 ms | 12928 KB | Output is correct |
41 | Correct | 128 ms | 18272 KB | Output is correct |
42 | Correct | 137 ms | 25080 KB | Output is correct |
43 | Correct | 12 ms | 12160 KB | Output is correct |
44 | Correct | 143 ms | 39416 KB | Output is correct |
45 | Correct | 137 ms | 30072 KB | Output is correct |
46 | Correct | 13 ms | 12288 KB | Output is correct |
47 | Correct | 14 ms | 12288 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 89 ms | 18672 KB | Output is correct |
2 | Correct | 102 ms | 24532 KB | Output is correct |
3 | Correct | 15 ms | 12388 KB | Output is correct |
4 | Correct | 14 ms | 12416 KB | Output is correct |
5 | Correct | 12 ms | 12160 KB | Output is correct |
6 | Correct | 11 ms | 12160 KB | Output is correct |
7 | Correct | 13 ms | 12288 KB | Output is correct |
8 | Correct | 153 ms | 19704 KB | Output is correct |
9 | Correct | 14 ms | 12288 KB | Output is correct |
10 | Correct | 122 ms | 18936 KB | Output is correct |
11 | Correct | 13 ms | 12160 KB | Output is correct |
12 | Correct | 134 ms | 18956 KB | Output is correct |
13 | Correct | 137 ms | 20088 KB | Output is correct |
14 | Correct | 121 ms | 24224 KB | Output is correct |
15 | Correct | 88 ms | 18544 KB | Output is correct |
16 | Correct | 15 ms | 12416 KB | Output is correct |
17 | Correct | 15 ms | 12152 KB | Output is correct |
18 | Correct | 112 ms | 23524 KB | Output is correct |
19 | Correct | 152 ms | 32888 KB | Output is correct |
20 | Correct | 15 ms | 12416 KB | Output is correct |
21 | Correct | 11 ms | 12032 KB | Output is correct |
22 | Correct | 121 ms | 20340 KB | Output is correct |
23 | Correct | 14 ms | 12288 KB | Output is correct |
24 | Correct | 173 ms | 19320 KB | Output is correct |
25 | Correct | 145 ms | 29944 KB | Output is correct |
26 | Correct | 14 ms | 12416 KB | Output is correct |
27 | Correct | 15 ms | 12544 KB | Output is correct |
28 | Correct | 14 ms | 12288 KB | Output is correct |
29 | Correct | 14 ms | 12288 KB | Output is correct |
30 | Correct | 16 ms | 12384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12032 KB | Output is correct |
2 | Correct | 12 ms | 12032 KB | Output is correct |
3 | Correct | 11 ms | 12160 KB | Output is correct |
4 | Correct | 14 ms | 12160 KB | Output is correct |
5 | Correct | 11 ms | 12236 KB | Output is correct |
6 | Correct | 12 ms | 12160 KB | Output is correct |
7 | Correct | 12 ms | 12032 KB | Output is correct |
8 | Correct | 12 ms | 12160 KB | Output is correct |
9 | Correct | 12 ms | 12032 KB | Output is correct |
10 | Correct | 12 ms | 12160 KB | Output is correct |
11 | Correct | 12 ms | 12160 KB | Output is correct |
12 | Correct | 12 ms | 12160 KB | Output is correct |
13 | Correct | 12 ms | 12132 KB | Output is correct |
14 | Correct | 12 ms | 12160 KB | Output is correct |
15 | Correct | 13 ms | 12160 KB | Output is correct |
16 | Correct | 11 ms | 12160 KB | Output is correct |
17 | Correct | 11 ms | 12160 KB | Output is correct |
18 | Correct | 11 ms | 12160 KB | Output is correct |
19 | Correct | 11 ms | 12032 KB | Output is correct |
20 | Correct | 12 ms | 12132 KB | Output is correct |
21 | Correct | 13 ms | 12160 KB | Output is correct |
22 | Correct | 11 ms | 12160 KB | Output is correct |
23 | Correct | 11 ms | 12160 KB | Output is correct |
24 | Correct | 12 ms | 12160 KB | Output is correct |
25 | Correct | 20 ms | 12032 KB | Output is correct |
26 | Correct | 15 ms | 12332 KB | Output is correct |
27 | Correct | 14 ms | 12288 KB | Output is correct |
28 | Correct | 14 ms | 12672 KB | Output is correct |
29 | Correct | 14 ms | 12416 KB | Output is correct |
30 | Correct | 15 ms | 12288 KB | Output is correct |
31 | Correct | 12 ms | 12152 KB | Output is correct |
32 | Correct | 15 ms | 12672 KB | Output is correct |
33 | Correct | 12 ms | 12160 KB | Output is correct |
34 | Correct | 14 ms | 12288 KB | Output is correct |
35 | Correct | 14 ms | 12388 KB | Output is correct |
36 | Correct | 15 ms | 12288 KB | Output is correct |
37 | Correct | 15 ms | 12288 KB | Output is correct |
38 | Correct | 12 ms | 12160 KB | Output is correct |
39 | Correct | 15 ms | 12416 KB | Output is correct |
40 | Correct | 14 ms | 12288 KB | Output is correct |
41 | Correct | 14 ms | 12288 KB | Output is correct |
42 | Correct | 14 ms | 12416 KB | Output is correct |
43 | Correct | 14 ms | 12972 KB | Output is correct |
44 | Correct | 13 ms | 12160 KB | Output is correct |
45 | Correct | 14 ms | 12416 KB | Output is correct |
46 | Correct | 15 ms | 12288 KB | Output is correct |
47 | Correct | 12 ms | 12160 KB | Output is correct |
48 | Correct | 14 ms | 12288 KB | Output is correct |
49 | Correct | 14 ms | 12416 KB | Output is correct |
50 | Correct | 15 ms | 12544 KB | Output is correct |
51 | Correct | 14 ms | 12288 KB | Output is correct |
52 | Correct | 13 ms | 12288 KB | Output is correct |
53 | Correct | 15 ms | 12288 KB | Output is correct |
54 | Correct | 14 ms | 12288 KB | Output is correct |
55 | Correct | 12 ms | 12160 KB | Output is correct |
56 | Correct | 85 ms | 18604 KB | Output is correct |
57 | Correct | 142 ms | 18512 KB | Output is correct |
58 | Correct | 14 ms | 12416 KB | Output is correct |
59 | Correct | 12 ms | 12032 KB | Output is correct |
60 | Correct | 11 ms | 12160 KB | Output is correct |
61 | Correct | 116 ms | 18680 KB | Output is correct |
62 | Correct | 13 ms | 12288 KB | Output is correct |
63 | Correct | 138 ms | 38580 KB | Output is correct |
64 | Correct | 136 ms | 18296 KB | Output is correct |
65 | Correct | 14 ms | 12288 KB | Output is correct |
66 | Correct | 134 ms | 20728 KB | Output is correct |
67 | Correct | 14 ms | 12288 KB | Output is correct |
68 | Correct | 14 ms | 12288 KB | Output is correct |
69 | Correct | 101 ms | 18688 KB | Output is correct |
70 | Correct | 14 ms | 12928 KB | Output is correct |
71 | Correct | 128 ms | 18272 KB | Output is correct |
72 | Correct | 137 ms | 25080 KB | Output is correct |
73 | Correct | 12 ms | 12160 KB | Output is correct |
74 | Correct | 143 ms | 39416 KB | Output is correct |
75 | Correct | 137 ms | 30072 KB | Output is correct |
76 | Correct | 13 ms | 12288 KB | Output is correct |
77 | Correct | 14 ms | 12288 KB | Output is correct |
78 | Correct | 89 ms | 18672 KB | Output is correct |
79 | Correct | 102 ms | 24532 KB | Output is correct |
80 | Correct | 15 ms | 12388 KB | Output is correct |
81 | Correct | 14 ms | 12416 KB | Output is correct |
82 | Correct | 12 ms | 12160 KB | Output is correct |
83 | Correct | 11 ms | 12160 KB | Output is correct |
84 | Correct | 13 ms | 12288 KB | Output is correct |
85 | Correct | 153 ms | 19704 KB | Output is correct |
86 | Correct | 14 ms | 12288 KB | Output is correct |
87 | Correct | 122 ms | 18936 KB | Output is correct |
88 | Correct | 13 ms | 12160 KB | Output is correct |
89 | Correct | 134 ms | 18956 KB | Output is correct |
90 | Correct | 137 ms | 20088 KB | Output is correct |
91 | Correct | 121 ms | 24224 KB | Output is correct |
92 | Correct | 88 ms | 18544 KB | Output is correct |
93 | Correct | 15 ms | 12416 KB | Output is correct |
94 | Correct | 15 ms | 12152 KB | Output is correct |
95 | Correct | 112 ms | 23524 KB | Output is correct |
96 | Correct | 152 ms | 32888 KB | Output is correct |
97 | Correct | 15 ms | 12416 KB | Output is correct |
98 | Correct | 11 ms | 12032 KB | Output is correct |
99 | Correct | 121 ms | 20340 KB | Output is correct |
100 | Correct | 14 ms | 12288 KB | Output is correct |
101 | Correct | 173 ms | 19320 KB | Output is correct |
102 | Correct | 145 ms | 29944 KB | Output is correct |
103 | Correct | 14 ms | 12416 KB | Output is correct |
104 | Correct | 15 ms | 12544 KB | Output is correct |
105 | Correct | 14 ms | 12288 KB | Output is correct |
106 | Correct | 14 ms | 12288 KB | Output is correct |
107 | Correct | 16 ms | 12384 KB | Output is correct |
108 | Correct | 955 ms | 55116 KB | Output is correct |
109 | Correct | 849 ms | 95204 KB | Output is correct |
110 | Correct | 873 ms | 126668 KB | Output is correct |
111 | Correct | 900 ms | 123196 KB | Output is correct |
112 | Correct | 808 ms | 92536 KB | Output is correct |
113 | Correct | 628 ms | 70240 KB | Output is correct |
114 | Correct | 752 ms | 43772 KB | Output is correct |
115 | Correct | 765 ms | 43824 KB | Output is correct |
116 | Correct | 1118 ms | 48908 KB | Output is correct |
117 | Correct | 829 ms | 73556 KB | Output is correct |
118 | Correct | 780 ms | 45708 KB | Output is correct |
119 | Correct | 793 ms | 73528 KB | Output is correct |
120 | Correct | 872 ms | 104988 KB | Output is correct |
121 | Correct | 846 ms | 73380 KB | Output is correct |
122 | Correct | 1398 ms | 57912 KB | Output is correct |
123 | Correct | 582 ms | 74980 KB | Output is correct |
124 | Correct | 846 ms | 64932 KB | Output is correct |