# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
102476 | 2019-03-25T08:48:21 Z | AngusRitossa | Mergers (JOI19_mergers) | C++14 | 1553 ms | 154716 KB |
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define D(x...) printf(x) #else #define D(x...) #endif int n, k, amof[500010], c[500010]; vector<int> adj[500010]; int leaves; int last; map<int, int>* ms[500010]; int dfs(int a, int p = -1) { int ambadchildren = 0; ms[a] = new map<int, int>(); (*ms[a])[c[a]]++; if ((*ms[a])[c[a]] == amof[c[a]]) ms[a]->erase(c[a]); for (auto b : adj[a]) { if (b != p) { int am = dfs(b, a); ambadchildren += am; if (ms[b]->size() > ms[a]->size()) swap(ms[a], ms[b]); for (auto c : *ms[b]) { (*ms[a])[c.first]+=c.second; if ((*ms[a])[c.first] == amof[c.first]) ms[a]->erase(c.first); } } } last = max(last, ambadchildren); if (p != -1) { int old = ambadchildren; ambadchildren = !ms[a]->size(); D("%d %d\n", a, ambadchildren); if (ambadchildren) last = 1; if (!old) leaves += ambadchildren; else ambadchildren = old; } else if (p == -1 && ambadchildren == 1) { leaves += last == 1; } return !!ambadchildren; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) scanf("%d", &c[i]), amof[c[i]]++; dfs(1); D("%d\n", leaves); printf("%d\n", (leaves+1)/2); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12204 KB | Output is correct |
2 | Correct | 15 ms | 12032 KB | Output is correct |
3 | Correct | 15 ms | 12160 KB | Output is correct |
4 | Correct | 12 ms | 12032 KB | Output is correct |
5 | Correct | 13 ms | 12160 KB | Output is correct |
6 | Correct | 13 ms | 12160 KB | Output is correct |
7 | Correct | 12 ms | 12160 KB | Output is correct |
8 | Correct | 14 ms | 12288 KB | Output is correct |
9 | Correct | 12 ms | 12132 KB | Output is correct |
10 | Correct | 16 ms | 12160 KB | Output is correct |
11 | Correct | 13 ms | 12032 KB | Output is correct |
12 | Correct | 15 ms | 12032 KB | Output is correct |
13 | Correct | 14 ms | 12160 KB | Output is correct |
14 | Correct | 13 ms | 12032 KB | Output is correct |
15 | Correct | 13 ms | 12184 KB | Output is correct |
16 | Correct | 13 ms | 12160 KB | Output is correct |
17 | Correct | 14 ms | 12160 KB | Output is correct |
18 | Correct | 17 ms | 12160 KB | Output is correct |
19 | Correct | 14 ms | 12160 KB | Output is correct |
20 | Correct | 15 ms | 12160 KB | Output is correct |
21 | Correct | 15 ms | 12076 KB | Output is correct |
22 | Correct | 14 ms | 12160 KB | Output is correct |
23 | Correct | 13 ms | 12160 KB | Output is correct |
24 | Correct | 14 ms | 12160 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12204 KB | Output is correct |
2 | Correct | 15 ms | 12032 KB | Output is correct |
3 | Correct | 15 ms | 12160 KB | Output is correct |
4 | Correct | 12 ms | 12032 KB | Output is correct |
5 | Correct | 13 ms | 12160 KB | Output is correct |
6 | Correct | 13 ms | 12160 KB | Output is correct |
7 | Correct | 12 ms | 12160 KB | Output is correct |
8 | Correct | 14 ms | 12288 KB | Output is correct |
9 | Correct | 12 ms | 12132 KB | Output is correct |
10 | Correct | 16 ms | 12160 KB | Output is correct |
11 | Correct | 13 ms | 12032 KB | Output is correct |
12 | Correct | 15 ms | 12032 KB | Output is correct |
13 | Correct | 14 ms | 12160 KB | Output is correct |
14 | Correct | 13 ms | 12032 KB | Output is correct |
15 | Correct | 13 ms | 12184 KB | Output is correct |
16 | Correct | 13 ms | 12160 KB | Output is correct |
17 | Correct | 14 ms | 12160 KB | Output is correct |
18 | Correct | 17 ms | 12160 KB | Output is correct |
19 | Correct | 14 ms | 12160 KB | Output is correct |
20 | Correct | 15 ms | 12160 KB | Output is correct |
21 | Correct | 15 ms | 12076 KB | Output is correct |
22 | Correct | 14 ms | 12160 KB | Output is correct |
23 | Correct | 13 ms | 12160 KB | Output is correct |
24 | Correct | 14 ms | 12160 KB | Output is correct |
25 | Correct | 12 ms | 12160 KB | Output is correct |
26 | Correct | 15 ms | 12416 KB | Output is correct |
27 | Correct | 18 ms | 12512 KB | Output is correct |
28 | Correct | 16 ms | 12664 KB | Output is correct |
29 | Correct | 16 ms | 12428 KB | Output is correct |
30 | Correct | 17 ms | 12800 KB | Output is correct |
31 | Correct | 15 ms | 12032 KB | Output is correct |
32 | Correct | 17 ms | 12672 KB | Output is correct |
33 | Correct | 15 ms | 12160 KB | Output is correct |
34 | Correct | 15 ms | 12544 KB | Output is correct |
35 | Correct | 16 ms | 12416 KB | Output is correct |
36 | Correct | 16 ms | 12544 KB | Output is correct |
37 | Correct | 16 ms | 12644 KB | Output is correct |
38 | Correct | 15 ms | 12160 KB | Output is correct |
39 | Correct | 20 ms | 12800 KB | Output is correct |
40 | Correct | 16 ms | 12544 KB | Output is correct |
41 | Correct | 15 ms | 12544 KB | Output is correct |
42 | Correct | 17 ms | 12544 KB | Output is correct |
43 | Correct | 15 ms | 12928 KB | Output is correct |
44 | Correct | 13 ms | 12032 KB | Output is correct |
45 | Correct | 17 ms | 12544 KB | Output is correct |
46 | Correct | 15 ms | 12672 KB | Output is correct |
47 | Correct | 13 ms | 12160 KB | Output is correct |
48 | Correct | 16 ms | 12544 KB | Output is correct |
49 | Correct | 18 ms | 12416 KB | Output is correct |
50 | Correct | 14 ms | 12544 KB | Output is correct |
51 | Correct | 16 ms | 12544 KB | Output is correct |
52 | Correct | 15 ms | 12544 KB | Output is correct |
53 | Correct | 18 ms | 12544 KB | Output is correct |
54 | Correct | 16 ms | 12800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12204 KB | Output is correct |
2 | Correct | 15 ms | 12032 KB | Output is correct |
3 | Correct | 15 ms | 12160 KB | Output is correct |
4 | Correct | 12 ms | 12032 KB | Output is correct |
5 | Correct | 13 ms | 12160 KB | Output is correct |
6 | Correct | 13 ms | 12160 KB | Output is correct |
7 | Correct | 12 ms | 12160 KB | Output is correct |
8 | Correct | 14 ms | 12288 KB | Output is correct |
9 | Correct | 12 ms | 12132 KB | Output is correct |
10 | Correct | 16 ms | 12160 KB | Output is correct |
11 | Correct | 13 ms | 12032 KB | Output is correct |
12 | Correct | 15 ms | 12032 KB | Output is correct |
13 | Correct | 14 ms | 12160 KB | Output is correct |
14 | Correct | 13 ms | 12032 KB | Output is correct |
15 | Correct | 13 ms | 12184 KB | Output is correct |
16 | Correct | 13 ms | 12160 KB | Output is correct |
17 | Correct | 14 ms | 12160 KB | Output is correct |
18 | Correct | 17 ms | 12160 KB | Output is correct |
19 | Correct | 14 ms | 12160 KB | Output is correct |
20 | Correct | 15 ms | 12160 KB | Output is correct |
21 | Correct | 15 ms | 12076 KB | Output is correct |
22 | Correct | 14 ms | 12160 KB | Output is correct |
23 | Correct | 13 ms | 12160 KB | Output is correct |
24 | Correct | 14 ms | 12160 KB | Output is correct |
25 | Correct | 13 ms | 12160 KB | Output is correct |
26 | Correct | 135 ms | 27764 KB | Output is correct |
27 | Correct | 225 ms | 34224 KB | Output is correct |
28 | Correct | 16 ms | 12672 KB | Output is correct |
29 | Correct | 14 ms | 12160 KB | Output is correct |
30 | Correct | 16 ms | 12032 KB | Output is correct |
31 | Correct | 135 ms | 27512 KB | Output is correct |
32 | Correct | 17 ms | 12544 KB | Output is correct |
33 | Correct | 168 ms | 39008 KB | Output is correct |
34 | Correct | 161 ms | 32760 KB | Output is correct |
35 | Correct | 18 ms | 12544 KB | Output is correct |
36 | Correct | 168 ms | 28700 KB | Output is correct |
37 | Correct | 17 ms | 12544 KB | Output is correct |
38 | Correct | 17 ms | 12544 KB | Output is correct |
39 | Correct | 128 ms | 27752 KB | Output is correct |
40 | Correct | 14 ms | 12936 KB | Output is correct |
41 | Correct | 142 ms | 27424 KB | Output is correct |
42 | Correct | 166 ms | 31228 KB | Output is correct |
43 | Correct | 12 ms | 12032 KB | Output is correct |
44 | Correct | 174 ms | 39416 KB | Output is correct |
45 | Correct | 220 ms | 34680 KB | Output is correct |
46 | Correct | 15 ms | 12544 KB | Output is correct |
47 | Correct | 20 ms | 12772 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 121 ms | 27720 KB | Output is correct |
2 | Correct | 166 ms | 23532 KB | Output is correct |
3 | Correct | 16 ms | 12416 KB | Output is correct |
4 | Correct | 18 ms | 12544 KB | Output is correct |
5 | Correct | 14 ms | 12032 KB | Output is correct |
6 | Correct | 14 ms | 12132 KB | Output is correct |
7 | Correct | 16 ms | 12544 KB | Output is correct |
8 | Correct | 190 ms | 30072 KB | Output is correct |
9 | Correct | 15 ms | 12544 KB | Output is correct |
10 | Correct | 186 ms | 27352 KB | Output is correct |
11 | Correct | 13 ms | 12160 KB | Output is correct |
12 | Correct | 160 ms | 27384 KB | Output is correct |
13 | Correct | 149 ms | 26744 KB | Output is correct |
14 | Correct | 162 ms | 23088 KB | Output is correct |
15 | Correct | 121 ms | 27764 KB | Output is correct |
16 | Correct | 16 ms | 12544 KB | Output is correct |
17 | Correct | 12 ms | 12032 KB | Output is correct |
18 | Correct | 183 ms | 24432 KB | Output is correct |
19 | Correct | 205 ms | 29560 KB | Output is correct |
20 | Correct | 16 ms | 12672 KB | Output is correct |
21 | Correct | 13 ms | 12160 KB | Output is correct |
22 | Correct | 168 ms | 27136 KB | Output is correct |
23 | Correct | 18 ms | 12544 KB | Output is correct |
24 | Correct | 147 ms | 26968 KB | Output is correct |
25 | Correct | 219 ms | 27356 KB | Output is correct |
26 | Correct | 17 ms | 12416 KB | Output is correct |
27 | Correct | 16 ms | 12544 KB | Output is correct |
28 | Correct | 15 ms | 12544 KB | Output is correct |
29 | Correct | 17 ms | 12544 KB | Output is correct |
30 | Correct | 16 ms | 12544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12204 KB | Output is correct |
2 | Correct | 15 ms | 12032 KB | Output is correct |
3 | Correct | 15 ms | 12160 KB | Output is correct |
4 | Correct | 12 ms | 12032 KB | Output is correct |
5 | Correct | 13 ms | 12160 KB | Output is correct |
6 | Correct | 13 ms | 12160 KB | Output is correct |
7 | Correct | 12 ms | 12160 KB | Output is correct |
8 | Correct | 14 ms | 12288 KB | Output is correct |
9 | Correct | 12 ms | 12132 KB | Output is correct |
10 | Correct | 16 ms | 12160 KB | Output is correct |
11 | Correct | 13 ms | 12032 KB | Output is correct |
12 | Correct | 15 ms | 12032 KB | Output is correct |
13 | Correct | 14 ms | 12160 KB | Output is correct |
14 | Correct | 13 ms | 12032 KB | Output is correct |
15 | Correct | 13 ms | 12184 KB | Output is correct |
16 | Correct | 13 ms | 12160 KB | Output is correct |
17 | Correct | 14 ms | 12160 KB | Output is correct |
18 | Correct | 17 ms | 12160 KB | Output is correct |
19 | Correct | 14 ms | 12160 KB | Output is correct |
20 | Correct | 15 ms | 12160 KB | Output is correct |
21 | Correct | 15 ms | 12076 KB | Output is correct |
22 | Correct | 14 ms | 12160 KB | Output is correct |
23 | Correct | 13 ms | 12160 KB | Output is correct |
24 | Correct | 14 ms | 12160 KB | Output is correct |
25 | Correct | 12 ms | 12160 KB | Output is correct |
26 | Correct | 15 ms | 12416 KB | Output is correct |
27 | Correct | 18 ms | 12512 KB | Output is correct |
28 | Correct | 16 ms | 12664 KB | Output is correct |
29 | Correct | 16 ms | 12428 KB | Output is correct |
30 | Correct | 17 ms | 12800 KB | Output is correct |
31 | Correct | 15 ms | 12032 KB | Output is correct |
32 | Correct | 17 ms | 12672 KB | Output is correct |
33 | Correct | 15 ms | 12160 KB | Output is correct |
34 | Correct | 15 ms | 12544 KB | Output is correct |
35 | Correct | 16 ms | 12416 KB | Output is correct |
36 | Correct | 16 ms | 12544 KB | Output is correct |
37 | Correct | 16 ms | 12644 KB | Output is correct |
38 | Correct | 15 ms | 12160 KB | Output is correct |
39 | Correct | 20 ms | 12800 KB | Output is correct |
40 | Correct | 16 ms | 12544 KB | Output is correct |
41 | Correct | 15 ms | 12544 KB | Output is correct |
42 | Correct | 17 ms | 12544 KB | Output is correct |
43 | Correct | 15 ms | 12928 KB | Output is correct |
44 | Correct | 13 ms | 12032 KB | Output is correct |
45 | Correct | 17 ms | 12544 KB | Output is correct |
46 | Correct | 15 ms | 12672 KB | Output is correct |
47 | Correct | 13 ms | 12160 KB | Output is correct |
48 | Correct | 16 ms | 12544 KB | Output is correct |
49 | Correct | 18 ms | 12416 KB | Output is correct |
50 | Correct | 14 ms | 12544 KB | Output is correct |
51 | Correct | 16 ms | 12544 KB | Output is correct |
52 | Correct | 15 ms | 12544 KB | Output is correct |
53 | Correct | 18 ms | 12544 KB | Output is correct |
54 | Correct | 16 ms | 12800 KB | Output is correct |
55 | Correct | 13 ms | 12160 KB | Output is correct |
56 | Correct | 135 ms | 27764 KB | Output is correct |
57 | Correct | 225 ms | 34224 KB | Output is correct |
58 | Correct | 16 ms | 12672 KB | Output is correct |
59 | Correct | 14 ms | 12160 KB | Output is correct |
60 | Correct | 16 ms | 12032 KB | Output is correct |
61 | Correct | 135 ms | 27512 KB | Output is correct |
62 | Correct | 17 ms | 12544 KB | Output is correct |
63 | Correct | 168 ms | 39008 KB | Output is correct |
64 | Correct | 161 ms | 32760 KB | Output is correct |
65 | Correct | 18 ms | 12544 KB | Output is correct |
66 | Correct | 168 ms | 28700 KB | Output is correct |
67 | Correct | 17 ms | 12544 KB | Output is correct |
68 | Correct | 17 ms | 12544 KB | Output is correct |
69 | Correct | 128 ms | 27752 KB | Output is correct |
70 | Correct | 14 ms | 12936 KB | Output is correct |
71 | Correct | 142 ms | 27424 KB | Output is correct |
72 | Correct | 166 ms | 31228 KB | Output is correct |
73 | Correct | 12 ms | 12032 KB | Output is correct |
74 | Correct | 174 ms | 39416 KB | Output is correct |
75 | Correct | 220 ms | 34680 KB | Output is correct |
76 | Correct | 15 ms | 12544 KB | Output is correct |
77 | Correct | 20 ms | 12772 KB | Output is correct |
78 | Correct | 121 ms | 27720 KB | Output is correct |
79 | Correct | 166 ms | 23532 KB | Output is correct |
80 | Correct | 16 ms | 12416 KB | Output is correct |
81 | Correct | 18 ms | 12544 KB | Output is correct |
82 | Correct | 14 ms | 12032 KB | Output is correct |
83 | Correct | 14 ms | 12132 KB | Output is correct |
84 | Correct | 16 ms | 12544 KB | Output is correct |
85 | Correct | 190 ms | 30072 KB | Output is correct |
86 | Correct | 15 ms | 12544 KB | Output is correct |
87 | Correct | 186 ms | 27352 KB | Output is correct |
88 | Correct | 13 ms | 12160 KB | Output is correct |
89 | Correct | 160 ms | 27384 KB | Output is correct |
90 | Correct | 149 ms | 26744 KB | Output is correct |
91 | Correct | 162 ms | 23088 KB | Output is correct |
92 | Correct | 121 ms | 27764 KB | Output is correct |
93 | Correct | 16 ms | 12544 KB | Output is correct |
94 | Correct | 12 ms | 12032 KB | Output is correct |
95 | Correct | 183 ms | 24432 KB | Output is correct |
96 | Correct | 205 ms | 29560 KB | Output is correct |
97 | Correct | 16 ms | 12672 KB | Output is correct |
98 | Correct | 13 ms | 12160 KB | Output is correct |
99 | Correct | 168 ms | 27136 KB | Output is correct |
100 | Correct | 18 ms | 12544 KB | Output is correct |
101 | Correct | 147 ms | 26968 KB | Output is correct |
102 | Correct | 219 ms | 27356 KB | Output is correct |
103 | Correct | 17 ms | 12416 KB | Output is correct |
104 | Correct | 16 ms | 12544 KB | Output is correct |
105 | Correct | 15 ms | 12544 KB | Output is correct |
106 | Correct | 17 ms | 12544 KB | Output is correct |
107 | Correct | 16 ms | 12544 KB | Output is correct |
108 | Correct | 1336 ms | 89160 KB | Output is correct |
109 | Correct | 1045 ms | 118136 KB | Output is correct |
110 | Correct | 1043 ms | 136208 KB | Output is correct |
111 | Correct | 1131 ms | 104824 KB | Output is correct |
112 | Correct | 1086 ms | 89012 KB | Output is correct |
113 | Correct | 904 ms | 73320 KB | Output is correct |
114 | Correct | 912 ms | 89040 KB | Output is correct |
115 | Correct | 845 ms | 89044 KB | Output is correct |
116 | Correct | 1247 ms | 146556 KB | Output is correct |
117 | Correct | 992 ms | 67448 KB | Output is correct |
118 | Correct | 869 ms | 87500 KB | Output is correct |
119 | Correct | 1093 ms | 67592 KB | Output is correct |
120 | Correct | 1020 ms | 90228 KB | Output is correct |
121 | Correct | 905 ms | 67624 KB | Output is correct |
122 | Correct | 1553 ms | 154716 KB | Output is correct |
123 | Correct | 754 ms | 69036 KB | Output is correct |
124 | Correct | 1061 ms | 66680 KB | Output is correct |