# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
105887 | 2019-04-15T14:32:36 Z | Kepperoni | Mergers (JOI19_mergers) | C++14 | 1345 ms | 63452 KB |
#include <bits/stdc++.h> #define x first #define y second #define pb push_back #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; typedef pair<ll, ll> pii; const int MAXN = 5e5 + 10; int n, kk; int gr[MAXN]; int le[MAXN], ri[MAXN]; int fi[MAXN], se[MAXN]; int cmi[MAXN], cma[MAXN], cnt[MAXN], tr[MAXN]; vector<int> k[MAXN]; int leaf = 1; int ccnt = 1; void prep(int v, int p = 0){ le[v] = ccnt; ri[v] = ccnt; fi[gr[v]] = min(fi[gr[v]], ccnt); se[gr[v]] = max(se[gr[v]], ccnt); ccnt++; for(auto x : k[v]){ if(x != p){ prep(x, v); ri[v] = ri[x]; } } } void go(int v, int p = 0){ cmi[v] = fi[gr[v]]; cma[v] = se[gr[v]]; for(auto x : k[v]){ if(x != p){ go(x, v); cmi[v] = min(cmi[v], cmi[x]); cma[v] = max(cma[v], cma[x]); cnt[v] += cnt[x]; } } if(cmi[v] >= le[v] && cma[v] <= ri[v]){ if(cnt[v] == 0 && v != 1) leaf++; if(cnt[v] == 1 && v == 1) leaf++; cnt[v] = 1; } } int main(){ scanf(" %d %d", &n, &kk); for(int i=0; i<n-1; i++){ int ca, cb; scanf(" %d %d", &ca, &cb); k[ca].pb(cb); k[cb].pb(ca); } for(int i=1; i<=n; i++) scanf(" %d", &gr[i]); for(int i=1; i<=kk; i++) fi[i] = 1e6; prep(1); go(1); printf("%d\n", leaf/2); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 12160 KB | Output is correct |
2 | Correct | 13 ms | 12160 KB | Output is correct |
3 | Correct | 14 ms | 12160 KB | Output is correct |
4 | Correct | 14 ms | 12160 KB | Output is correct |
5 | Correct | 15 ms | 12288 KB | Output is correct |
6 | Correct | 10 ms | 12160 KB | Output is correct |
7 | Correct | 14 ms | 12108 KB | Output is correct |
8 | Correct | 14 ms | 12160 KB | Output is correct |
9 | Correct | 14 ms | 12160 KB | Output is correct |
10 | Correct | 13 ms | 12160 KB | Output is correct |
11 | Correct | 15 ms | 12160 KB | Output is correct |
12 | Correct | 14 ms | 12288 KB | Output is correct |
13 | Correct | 13 ms | 12160 KB | Output is correct |
14 | Correct | 15 ms | 12160 KB | Output is correct |
15 | Correct | 16 ms | 12160 KB | Output is correct |
16 | Correct | 15 ms | 12160 KB | Output is correct |
17 | Correct | 15 ms | 12160 KB | Output is correct |
18 | Correct | 15 ms | 12160 KB | Output is correct |
19 | Correct | 13 ms | 12160 KB | Output is correct |
20 | Correct | 15 ms | 12160 KB | Output is correct |
21 | Correct | 13 ms | 12160 KB | Output is correct |
22 | Correct | 15 ms | 12160 KB | Output is correct |
23 | Correct | 14 ms | 12160 KB | Output is correct |
24 | Correct | 16 ms | 12160 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 12160 KB | Output is correct |
2 | Correct | 13 ms | 12160 KB | Output is correct |
3 | Correct | 14 ms | 12160 KB | Output is correct |
4 | Correct | 14 ms | 12160 KB | Output is correct |
5 | Correct | 15 ms | 12288 KB | Output is correct |
6 | Correct | 10 ms | 12160 KB | Output is correct |
7 | Correct | 14 ms | 12108 KB | Output is correct |
8 | Correct | 14 ms | 12160 KB | Output is correct |
9 | Correct | 14 ms | 12160 KB | Output is correct |
10 | Correct | 13 ms | 12160 KB | Output is correct |
11 | Correct | 15 ms | 12160 KB | Output is correct |
12 | Correct | 14 ms | 12288 KB | Output is correct |
13 | Correct | 13 ms | 12160 KB | Output is correct |
14 | Correct | 15 ms | 12160 KB | Output is correct |
15 | Correct | 16 ms | 12160 KB | Output is correct |
16 | Correct | 15 ms | 12160 KB | Output is correct |
17 | Correct | 15 ms | 12160 KB | Output is correct |
18 | Correct | 15 ms | 12160 KB | Output is correct |
19 | Correct | 13 ms | 12160 KB | Output is correct |
20 | Correct | 15 ms | 12160 KB | Output is correct |
21 | Correct | 13 ms | 12160 KB | Output is correct |
22 | Correct | 15 ms | 12160 KB | Output is correct |
23 | Correct | 14 ms | 12160 KB | Output is correct |
24 | Correct | 16 ms | 12160 KB | Output is correct |
25 | Correct | 14 ms | 12160 KB | Output is correct |
26 | Correct | 17 ms | 12288 KB | Output is correct |
27 | Correct | 17 ms | 12420 KB | Output is correct |
28 | Correct | 16 ms | 12536 KB | Output is correct |
29 | Correct | 17 ms | 12416 KB | Output is correct |
30 | Correct | 16 ms | 12288 KB | Output is correct |
31 | Correct | 15 ms | 12160 KB | Output is correct |
32 | Correct | 16 ms | 12416 KB | Output is correct |
33 | Correct | 17 ms | 12160 KB | Output is correct |
34 | Correct | 17 ms | 12288 KB | Output is correct |
35 | Correct | 19 ms | 12288 KB | Output is correct |
36 | Correct | 19 ms | 12288 KB | Output is correct |
37 | Correct | 17 ms | 12288 KB | Output is correct |
38 | Correct | 13 ms | 12160 KB | Output is correct |
39 | Correct | 16 ms | 12160 KB | Output is correct |
40 | Correct | 17 ms | 12288 KB | Output is correct |
41 | Correct | 17 ms | 12288 KB | Output is correct |
42 | Correct | 15 ms | 12288 KB | Output is correct |
43 | Correct | 19 ms | 12416 KB | Output is correct |
44 | Correct | 16 ms | 12160 KB | Output is correct |
45 | Correct | 16 ms | 12288 KB | Output is correct |
46 | Correct | 15 ms | 12288 KB | Output is correct |
47 | Correct | 14 ms | 12160 KB | Output is correct |
48 | Correct | 15 ms | 12288 KB | Output is correct |
49 | Correct | 13 ms | 12288 KB | Output is correct |
50 | Correct | 19 ms | 12288 KB | Output is correct |
51 | Correct | 16 ms | 12288 KB | Output is correct |
52 | Correct | 15 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 | 14 ms | 12160 KB | Output is correct |
2 | Correct | 13 ms | 12160 KB | Output is correct |
3 | Correct | 14 ms | 12160 KB | Output is correct |
4 | Correct | 14 ms | 12160 KB | Output is correct |
5 | Correct | 15 ms | 12288 KB | Output is correct |
6 | Correct | 10 ms | 12160 KB | Output is correct |
7 | Correct | 14 ms | 12108 KB | Output is correct |
8 | Correct | 14 ms | 12160 KB | Output is correct |
9 | Correct | 14 ms | 12160 KB | Output is correct |
10 | Correct | 13 ms | 12160 KB | Output is correct |
11 | Correct | 15 ms | 12160 KB | Output is correct |
12 | Correct | 14 ms | 12288 KB | Output is correct |
13 | Correct | 13 ms | 12160 KB | Output is correct |
14 | Correct | 15 ms | 12160 KB | Output is correct |
15 | Correct | 16 ms | 12160 KB | Output is correct |
16 | Correct | 15 ms | 12160 KB | Output is correct |
17 | Correct | 15 ms | 12160 KB | Output is correct |
18 | Correct | 15 ms | 12160 KB | Output is correct |
19 | Correct | 13 ms | 12160 KB | Output is correct |
20 | Correct | 15 ms | 12160 KB | Output is correct |
21 | Correct | 13 ms | 12160 KB | Output is correct |
22 | Correct | 15 ms | 12160 KB | Output is correct |
23 | Correct | 14 ms | 12160 KB | Output is correct |
24 | Correct | 16 ms | 12160 KB | Output is correct |
25 | Correct | 13 ms | 12160 KB | Output is correct |
26 | Correct | 112 ms | 17780 KB | Output is correct |
27 | Correct | 143 ms | 17784 KB | Output is correct |
28 | Correct | 17 ms | 12288 KB | Output is correct |
29 | Correct | 16 ms | 12160 KB | Output is correct |
30 | Correct | 16 ms | 12144 KB | Output is correct |
31 | Correct | 136 ms | 17760 KB | Output is correct |
32 | Correct | 15 ms | 12288 KB | Output is correct |
33 | Correct | 212 ms | 23516 KB | Output is correct |
34 | Correct | 141 ms | 17828 KB | Output is correct |
35 | Correct | 17 ms | 12336 KB | Output is correct |
36 | Correct | 172 ms | 18292 KB | Output is correct |
37 | Correct | 15 ms | 12288 KB | Output is correct |
38 | Correct | 15 ms | 12288 KB | Output is correct |
39 | Correct | 99 ms | 17648 KB | Output is correct |
40 | Correct | 14 ms | 12416 KB | Output is correct |
41 | Correct | 138 ms | 17668 KB | Output is correct |
42 | Correct | 160 ms | 19588 KB | Output is correct |
43 | Correct | 13 ms | 12160 KB | Output is correct |
44 | Correct | 155 ms | 23804 KB | Output is correct |
45 | Correct | 142 ms | 20600 KB | Output is correct |
46 | Correct | 14 ms | 12288 KB | Output is correct |
47 | Correct | 15 ms | 12288 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 102 ms | 17620 KB | Output is correct |
2 | Correct | 88 ms | 18800 KB | Output is correct |
3 | Correct | 16 ms | 12288 KB | Output is correct |
4 | Correct | 15 ms | 12288 KB | Output is correct |
5 | Correct | 13 ms | 12160 KB | Output is correct |
6 | Correct | 12 ms | 12160 KB | Output is correct |
7 | Correct | 17 ms | 12288 KB | Output is correct |
8 | Correct | 147 ms | 18124 KB | Output is correct |
9 | Correct | 16 ms | 12288 KB | Output is correct |
10 | Correct | 133 ms | 17720 KB | Output is correct |
11 | Correct | 14 ms | 12132 KB | Output is correct |
12 | Correct | 195 ms | 17644 KB | Output is correct |
13 | Correct | 190 ms | 18100 KB | Output is correct |
14 | Correct | 155 ms | 18572 KB | Output is correct |
15 | Correct | 105 ms | 17648 KB | Output is correct |
16 | Correct | 16 ms | 12260 KB | Output is correct |
17 | Correct | 17 ms | 12120 KB | Output is correct |
18 | Correct | 105 ms | 18672 KB | Output is correct |
19 | Correct | 181 ms | 21752 KB | Output is correct |
20 | Correct | 17 ms | 12288 KB | Output is correct |
21 | Correct | 14 ms | 12160 KB | Output is correct |
22 | Correct | 95 ms | 18416 KB | Output is correct |
23 | Correct | 15 ms | 12288 KB | Output is correct |
24 | Correct | 155 ms | 17728 KB | Output is correct |
25 | Correct | 140 ms | 20472 KB | Output is correct |
26 | Correct | 14 ms | 12416 KB | Output is correct |
27 | Correct | 15 ms | 12416 KB | Output is correct |
28 | Correct | 14 ms | 12288 KB | Output is correct |
29 | Correct | 16 ms | 12288 KB | Output is correct |
30 | Correct | 19 ms | 12288 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 12160 KB | Output is correct |
2 | Correct | 13 ms | 12160 KB | Output is correct |
3 | Correct | 14 ms | 12160 KB | Output is correct |
4 | Correct | 14 ms | 12160 KB | Output is correct |
5 | Correct | 15 ms | 12288 KB | Output is correct |
6 | Correct | 10 ms | 12160 KB | Output is correct |
7 | Correct | 14 ms | 12108 KB | Output is correct |
8 | Correct | 14 ms | 12160 KB | Output is correct |
9 | Correct | 14 ms | 12160 KB | Output is correct |
10 | Correct | 13 ms | 12160 KB | Output is correct |
11 | Correct | 15 ms | 12160 KB | Output is correct |
12 | Correct | 14 ms | 12288 KB | Output is correct |
13 | Correct | 13 ms | 12160 KB | Output is correct |
14 | Correct | 15 ms | 12160 KB | Output is correct |
15 | Correct | 16 ms | 12160 KB | Output is correct |
16 | Correct | 15 ms | 12160 KB | Output is correct |
17 | Correct | 15 ms | 12160 KB | Output is correct |
18 | Correct | 15 ms | 12160 KB | Output is correct |
19 | Correct | 13 ms | 12160 KB | Output is correct |
20 | Correct | 15 ms | 12160 KB | Output is correct |
21 | Correct | 13 ms | 12160 KB | Output is correct |
22 | Correct | 15 ms | 12160 KB | Output is correct |
23 | Correct | 14 ms | 12160 KB | Output is correct |
24 | Correct | 16 ms | 12160 KB | Output is correct |
25 | Correct | 14 ms | 12160 KB | Output is correct |
26 | Correct | 17 ms | 12288 KB | Output is correct |
27 | Correct | 17 ms | 12420 KB | Output is correct |
28 | Correct | 16 ms | 12536 KB | Output is correct |
29 | Correct | 17 ms | 12416 KB | Output is correct |
30 | Correct | 16 ms | 12288 KB | Output is correct |
31 | Correct | 15 ms | 12160 KB | Output is correct |
32 | Correct | 16 ms | 12416 KB | Output is correct |
33 | Correct | 17 ms | 12160 KB | Output is correct |
34 | Correct | 17 ms | 12288 KB | Output is correct |
35 | Correct | 19 ms | 12288 KB | Output is correct |
36 | Correct | 19 ms | 12288 KB | Output is correct |
37 | Correct | 17 ms | 12288 KB | Output is correct |
38 | Correct | 13 ms | 12160 KB | Output is correct |
39 | Correct | 16 ms | 12160 KB | Output is correct |
40 | Correct | 17 ms | 12288 KB | Output is correct |
41 | Correct | 17 ms | 12288 KB | Output is correct |
42 | Correct | 15 ms | 12288 KB | Output is correct |
43 | Correct | 19 ms | 12416 KB | Output is correct |
44 | Correct | 16 ms | 12160 KB | Output is correct |
45 | Correct | 16 ms | 12288 KB | Output is correct |
46 | Correct | 15 ms | 12288 KB | Output is correct |
47 | Correct | 14 ms | 12160 KB | Output is correct |
48 | Correct | 15 ms | 12288 KB | Output is correct |
49 | Correct | 13 ms | 12288 KB | Output is correct |
50 | Correct | 19 ms | 12288 KB | Output is correct |
51 | Correct | 16 ms | 12288 KB | Output is correct |
52 | Correct | 15 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 | 13 ms | 12160 KB | Output is correct |
56 | Correct | 112 ms | 17780 KB | Output is correct |
57 | Correct | 143 ms | 17784 KB | Output is correct |
58 | Correct | 17 ms | 12288 KB | Output is correct |
59 | Correct | 16 ms | 12160 KB | Output is correct |
60 | Correct | 16 ms | 12144 KB | Output is correct |
61 | Correct | 136 ms | 17760 KB | Output is correct |
62 | Correct | 15 ms | 12288 KB | Output is correct |
63 | Correct | 212 ms | 23516 KB | Output is correct |
64 | Correct | 141 ms | 17828 KB | Output is correct |
65 | Correct | 17 ms | 12336 KB | Output is correct |
66 | Correct | 172 ms | 18292 KB | Output is correct |
67 | Correct | 15 ms | 12288 KB | Output is correct |
68 | Correct | 15 ms | 12288 KB | Output is correct |
69 | Correct | 99 ms | 17648 KB | Output is correct |
70 | Correct | 14 ms | 12416 KB | Output is correct |
71 | Correct | 138 ms | 17668 KB | Output is correct |
72 | Correct | 160 ms | 19588 KB | Output is correct |
73 | Correct | 13 ms | 12160 KB | Output is correct |
74 | Correct | 155 ms | 23804 KB | Output is correct |
75 | Correct | 142 ms | 20600 KB | Output is correct |
76 | Correct | 14 ms | 12288 KB | Output is correct |
77 | Correct | 15 ms | 12288 KB | Output is correct |
78 | Correct | 102 ms | 17620 KB | Output is correct |
79 | Correct | 88 ms | 18800 KB | Output is correct |
80 | Correct | 16 ms | 12288 KB | Output is correct |
81 | Correct | 15 ms | 12288 KB | Output is correct |
82 | Correct | 13 ms | 12160 KB | Output is correct |
83 | Correct | 12 ms | 12160 KB | Output is correct |
84 | Correct | 17 ms | 12288 KB | Output is correct |
85 | Correct | 147 ms | 18124 KB | Output is correct |
86 | Correct | 16 ms | 12288 KB | Output is correct |
87 | Correct | 133 ms | 17720 KB | Output is correct |
88 | Correct | 14 ms | 12132 KB | Output is correct |
89 | Correct | 195 ms | 17644 KB | Output is correct |
90 | Correct | 190 ms | 18100 KB | Output is correct |
91 | Correct | 155 ms | 18572 KB | Output is correct |
92 | Correct | 105 ms | 17648 KB | Output is correct |
93 | Correct | 16 ms | 12260 KB | Output is correct |
94 | Correct | 17 ms | 12120 KB | Output is correct |
95 | Correct | 105 ms | 18672 KB | Output is correct |
96 | Correct | 181 ms | 21752 KB | Output is correct |
97 | Correct | 17 ms | 12288 KB | Output is correct |
98 | Correct | 14 ms | 12160 KB | Output is correct |
99 | Correct | 95 ms | 18416 KB | Output is correct |
100 | Correct | 15 ms | 12288 KB | Output is correct |
101 | Correct | 155 ms | 17728 KB | Output is correct |
102 | Correct | 140 ms | 20472 KB | Output is correct |
103 | Correct | 14 ms | 12416 KB | Output is correct |
104 | Correct | 15 ms | 12416 KB | Output is correct |
105 | Correct | 14 ms | 12288 KB | Output is correct |
106 | Correct | 16 ms | 12288 KB | Output is correct |
107 | Correct | 19 ms | 12288 KB | Output is correct |
108 | Correct | 625 ms | 43020 KB | Output is correct |
109 | Correct | 1014 ms | 54440 KB | Output is correct |
110 | Correct | 1079 ms | 63452 KB | Output is correct |
111 | Correct | 1272 ms | 62396 KB | Output is correct |
112 | Correct | 1345 ms | 54388 KB | Output is correct |
113 | Correct | 790 ms | 45016 KB | Output is correct |
114 | Correct | 908 ms | 40136 KB | Output is correct |
115 | Correct | 935 ms | 40124 KB | Output is correct |
116 | Correct | 1010 ms | 40784 KB | Output is correct |
117 | Correct | 1099 ms | 44152 KB | Output is correct |
118 | Correct | 868 ms | 39680 KB | Output is correct |
119 | Correct | 1162 ms | 44004 KB | Output is correct |
120 | Correct | 1124 ms | 55104 KB | Output is correct |
121 | Correct | 1028 ms | 44004 KB | Output is correct |
122 | Correct | 1012 ms | 42372 KB | Output is correct |
123 | Correct | 708 ms | 45352 KB | Output is correct |
124 | Correct | 1095 ms | 43244 KB | Output is correct |