# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
210364 | 2020-03-17T07:36:22 Z | arman_ferdous | Mergers (JOI19_mergers) | C++14 | 815 ms | 85596 KB |
// taken from https://github.com/win11905/submission/blob/master/JOISC/19/mergers.cpp #include <bits/stdc++.h> #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 5e5+5; int n, k; vector<int> g[N]; vector<pii> E; int dep[N], dsu[N], deg[N], par[N]; vector<int> col[N]; int find(int u) { return dsu[u] = dsu[u] == u ? u : find(dsu[u]); } void init_dep(int u, int p) { dep[u] = dep[p] + 1, par[u] = p; for(int v : g[u]) if(v != p) init_dep(v, u); } int main() { iota(dsu, dsu+N, 0); scanf("%d %d", &n, &k); for(int i = 1, u, v; i < n; ++i) { scanf("%d %d", &u, &v); g[u].emplace_back(v), g[v].emplace_back(u); E.emplace_back(u, v); } for(int i = 1, v; i <= n; ++i) { scanf("%d", &v); col[v].emplace_back(i); } init_dep(1, 0); for(int i = 1; i <= k; ++i) if(col[i].size() > 1) { for(int j = 1; j < col[i].size(); ++j) { int a = find(col[i][j-1]), b = find(col[i][j]); while(a != b) { if(dep[a] < dep[b]) swap(a, b); dsu[a] = find(par[a]); a = dsu[a]; } } } for(auto x : E) { int a = find(x.x), b = find(x.y); if(a != b) deg[a]++, deg[b]++; } int cnt = 0; for(int i = 1; i <= n; ++i) if(deg[i] == 1) cnt++; printf("%d\n", (cnt+1) / 2); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 25720 KB | Output is correct |
2 | Correct | 21 ms | 25720 KB | Output is correct |
3 | Correct | 22 ms | 25720 KB | Output is correct |
4 | Correct | 20 ms | 25720 KB | Output is correct |
5 | Correct | 21 ms | 25848 KB | Output is correct |
6 | Correct | 21 ms | 25720 KB | Output is correct |
7 | Correct | 20 ms | 25720 KB | Output is correct |
8 | Correct | 20 ms | 25720 KB | Output is correct |
9 | Correct | 21 ms | 25720 KB | Output is correct |
10 | Correct | 20 ms | 25720 KB | Output is correct |
11 | Correct | 21 ms | 25720 KB | Output is correct |
12 | Correct | 20 ms | 25720 KB | Output is correct |
13 | Correct | 21 ms | 25720 KB | Output is correct |
14 | Correct | 20 ms | 25720 KB | Output is correct |
15 | Correct | 20 ms | 25820 KB | Output is correct |
16 | Correct | 20 ms | 25832 KB | Output is correct |
17 | Correct | 20 ms | 25848 KB | Output is correct |
18 | Correct | 20 ms | 25720 KB | Output is correct |
19 | Correct | 21 ms | 25720 KB | Output is correct |
20 | Correct | 20 ms | 25724 KB | Output is correct |
21 | Correct | 21 ms | 25720 KB | Output is correct |
22 | Correct | 22 ms | 25720 KB | Output is correct |
23 | Correct | 21 ms | 25720 KB | Output is correct |
24 | Correct | 20 ms | 25720 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 25720 KB | Output is correct |
2 | Correct | 21 ms | 25720 KB | Output is correct |
3 | Correct | 22 ms | 25720 KB | Output is correct |
4 | Correct | 20 ms | 25720 KB | Output is correct |
5 | Correct | 21 ms | 25848 KB | Output is correct |
6 | Correct | 21 ms | 25720 KB | Output is correct |
7 | Correct | 20 ms | 25720 KB | Output is correct |
8 | Correct | 20 ms | 25720 KB | Output is correct |
9 | Correct | 21 ms | 25720 KB | Output is correct |
10 | Correct | 20 ms | 25720 KB | Output is correct |
11 | Correct | 21 ms | 25720 KB | Output is correct |
12 | Correct | 20 ms | 25720 KB | Output is correct |
13 | Correct | 21 ms | 25720 KB | Output is correct |
14 | Correct | 20 ms | 25720 KB | Output is correct |
15 | Correct | 20 ms | 25820 KB | Output is correct |
16 | Correct | 20 ms | 25832 KB | Output is correct |
17 | Correct | 20 ms | 25848 KB | Output is correct |
18 | Correct | 20 ms | 25720 KB | Output is correct |
19 | Correct | 21 ms | 25720 KB | Output is correct |
20 | Correct | 20 ms | 25724 KB | Output is correct |
21 | Correct | 21 ms | 25720 KB | Output is correct |
22 | Correct | 22 ms | 25720 KB | Output is correct |
23 | Correct | 21 ms | 25720 KB | Output is correct |
24 | Correct | 20 ms | 25720 KB | Output is correct |
25 | Correct | 21 ms | 25848 KB | Output is correct |
26 | Correct | 22 ms | 25976 KB | Output is correct |
27 | Correct | 22 ms | 25976 KB | Output is correct |
28 | Correct | 23 ms | 26104 KB | Output is correct |
29 | Correct | 23 ms | 26104 KB | Output is correct |
30 | Correct | 22 ms | 25976 KB | Output is correct |
31 | Correct | 21 ms | 25720 KB | Output is correct |
32 | Correct | 23 ms | 26104 KB | Output is correct |
33 | Correct | 21 ms | 25720 KB | Output is correct |
34 | Correct | 23 ms | 25976 KB | Output is correct |
35 | Correct | 24 ms | 26104 KB | Output is correct |
36 | Correct | 23 ms | 25976 KB | Output is correct |
37 | Correct | 23 ms | 25976 KB | Output is correct |
38 | Correct | 21 ms | 25720 KB | Output is correct |
39 | Correct | 23 ms | 25972 KB | Output is correct |
40 | Correct | 22 ms | 25980 KB | Output is correct |
41 | Correct | 22 ms | 25976 KB | Output is correct |
42 | Correct | 22 ms | 25976 KB | Output is correct |
43 | Correct | 23 ms | 26108 KB | Output is correct |
44 | Correct | 20 ms | 25720 KB | Output is correct |
45 | Correct | 23 ms | 26104 KB | Output is correct |
46 | Correct | 23 ms | 25976 KB | Output is correct |
47 | Correct | 21 ms | 25720 KB | Output is correct |
48 | Correct | 23 ms | 25976 KB | Output is correct |
49 | Correct | 23 ms | 26104 KB | Output is correct |
50 | Correct | 22 ms | 26104 KB | Output is correct |
51 | Correct | 23 ms | 25976 KB | Output is correct |
52 | Correct | 23 ms | 25976 KB | Output is correct |
53 | Correct | 22 ms | 25976 KB | Output is correct |
54 | Correct | 22 ms | 25976 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 25720 KB | Output is correct |
2 | Correct | 21 ms | 25720 KB | Output is correct |
3 | Correct | 22 ms | 25720 KB | Output is correct |
4 | Correct | 20 ms | 25720 KB | Output is correct |
5 | Correct | 21 ms | 25848 KB | Output is correct |
6 | Correct | 21 ms | 25720 KB | Output is correct |
7 | Correct | 20 ms | 25720 KB | Output is correct |
8 | Correct | 20 ms | 25720 KB | Output is correct |
9 | Correct | 21 ms | 25720 KB | Output is correct |
10 | Correct | 20 ms | 25720 KB | Output is correct |
11 | Correct | 21 ms | 25720 KB | Output is correct |
12 | Correct | 20 ms | 25720 KB | Output is correct |
13 | Correct | 21 ms | 25720 KB | Output is correct |
14 | Correct | 20 ms | 25720 KB | Output is correct |
15 | Correct | 20 ms | 25820 KB | Output is correct |
16 | Correct | 20 ms | 25832 KB | Output is correct |
17 | Correct | 20 ms | 25848 KB | Output is correct |
18 | Correct | 20 ms | 25720 KB | Output is correct |
19 | Correct | 21 ms | 25720 KB | Output is correct |
20 | Correct | 20 ms | 25724 KB | Output is correct |
21 | Correct | 21 ms | 25720 KB | Output is correct |
22 | Correct | 22 ms | 25720 KB | Output is correct |
23 | Correct | 21 ms | 25720 KB | Output is correct |
24 | Correct | 20 ms | 25720 KB | Output is correct |
25 | Correct | 21 ms | 25720 KB | Output is correct |
26 | Correct | 83 ms | 32868 KB | Output is correct |
27 | Correct | 105 ms | 32488 KB | Output is correct |
28 | Correct | 23 ms | 25976 KB | Output is correct |
29 | Correct | 21 ms | 25720 KB | Output is correct |
30 | Correct | 21 ms | 25720 KB | Output is correct |
31 | Correct | 104 ms | 32616 KB | Output is correct |
32 | Correct | 22 ms | 25976 KB | Output is correct |
33 | Correct | 116 ms | 36712 KB | Output is correct |
34 | Correct | 106 ms | 32488 KB | Output is correct |
35 | Correct | 22 ms | 25976 KB | Output is correct |
36 | Correct | 111 ms | 33004 KB | Output is correct |
37 | Correct | 23 ms | 25976 KB | Output is correct |
38 | Correct | 22 ms | 25976 KB | Output is correct |
39 | Correct | 85 ms | 32744 KB | Output is correct |
40 | Correct | 23 ms | 26104 KB | Output is correct |
41 | Correct | 107 ms | 32876 KB | Output is correct |
42 | Correct | 109 ms | 33900 KB | Output is correct |
43 | Correct | 20 ms | 25720 KB | Output is correct |
44 | Correct | 116 ms | 37228 KB | Output is correct |
45 | Correct | 111 ms | 34664 KB | Output is correct |
46 | Correct | 22 ms | 25976 KB | Output is correct |
47 | Correct | 23 ms | 25976 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 31460 KB | Output is correct |
2 | Correct | 96 ms | 34404 KB | Output is correct |
3 | Correct | 22 ms | 25976 KB | Output is correct |
4 | Correct | 24 ms | 25976 KB | Output is correct |
5 | Correct | 20 ms | 25720 KB | Output is correct |
6 | Correct | 20 ms | 25720 KB | Output is correct |
7 | Correct | 22 ms | 25976 KB | Output is correct |
8 | Correct | 122 ms | 34284 KB | Output is correct |
9 | Correct | 22 ms | 25976 KB | Output is correct |
10 | Correct | 106 ms | 33132 KB | Output is correct |
11 | Correct | 21 ms | 25720 KB | Output is correct |
12 | Correct | 110 ms | 33000 KB | Output is correct |
13 | Correct | 124 ms | 34152 KB | Output is correct |
14 | Correct | 116 ms | 35820 KB | Output is correct |
15 | Correct | 85 ms | 32768 KB | Output is correct |
16 | Correct | 22 ms | 25976 KB | Output is correct |
17 | Correct | 21 ms | 25720 KB | Output is correct |
18 | Correct | 103 ms | 35816 KB | Output is correct |
19 | Correct | 122 ms | 38124 KB | Output is correct |
20 | Correct | 23 ms | 25976 KB | Output is correct |
21 | Correct | 20 ms | 25720 KB | Output is correct |
22 | Correct | 100 ms | 34532 KB | Output is correct |
23 | Correct | 23 ms | 25976 KB | Output is correct |
24 | Correct | 118 ms | 33388 KB | Output is correct |
25 | Correct | 118 ms | 37356 KB | Output is correct |
26 | Correct | 23 ms | 26104 KB | Output is correct |
27 | Correct | 22 ms | 26104 KB | Output is correct |
28 | Correct | 22 ms | 25976 KB | Output is correct |
29 | Correct | 22 ms | 26048 KB | Output is correct |
30 | Correct | 22 ms | 25976 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 25720 KB | Output is correct |
2 | Correct | 21 ms | 25720 KB | Output is correct |
3 | Correct | 22 ms | 25720 KB | Output is correct |
4 | Correct | 20 ms | 25720 KB | Output is correct |
5 | Correct | 21 ms | 25848 KB | Output is correct |
6 | Correct | 21 ms | 25720 KB | Output is correct |
7 | Correct | 20 ms | 25720 KB | Output is correct |
8 | Correct | 20 ms | 25720 KB | Output is correct |
9 | Correct | 21 ms | 25720 KB | Output is correct |
10 | Correct | 20 ms | 25720 KB | Output is correct |
11 | Correct | 21 ms | 25720 KB | Output is correct |
12 | Correct | 20 ms | 25720 KB | Output is correct |
13 | Correct | 21 ms | 25720 KB | Output is correct |
14 | Correct | 20 ms | 25720 KB | Output is correct |
15 | Correct | 20 ms | 25820 KB | Output is correct |
16 | Correct | 20 ms | 25832 KB | Output is correct |
17 | Correct | 20 ms | 25848 KB | Output is correct |
18 | Correct | 20 ms | 25720 KB | Output is correct |
19 | Correct | 21 ms | 25720 KB | Output is correct |
20 | Correct | 20 ms | 25724 KB | Output is correct |
21 | Correct | 21 ms | 25720 KB | Output is correct |
22 | Correct | 22 ms | 25720 KB | Output is correct |
23 | Correct | 21 ms | 25720 KB | Output is correct |
24 | Correct | 20 ms | 25720 KB | Output is correct |
25 | Correct | 21 ms | 25848 KB | Output is correct |
26 | Correct | 22 ms | 25976 KB | Output is correct |
27 | Correct | 22 ms | 25976 KB | Output is correct |
28 | Correct | 23 ms | 26104 KB | Output is correct |
29 | Correct | 23 ms | 26104 KB | Output is correct |
30 | Correct | 22 ms | 25976 KB | Output is correct |
31 | Correct | 21 ms | 25720 KB | Output is correct |
32 | Correct | 23 ms | 26104 KB | Output is correct |
33 | Correct | 21 ms | 25720 KB | Output is correct |
34 | Correct | 23 ms | 25976 KB | Output is correct |
35 | Correct | 24 ms | 26104 KB | Output is correct |
36 | Correct | 23 ms | 25976 KB | Output is correct |
37 | Correct | 23 ms | 25976 KB | Output is correct |
38 | Correct | 21 ms | 25720 KB | Output is correct |
39 | Correct | 23 ms | 25972 KB | Output is correct |
40 | Correct | 22 ms | 25980 KB | Output is correct |
41 | Correct | 22 ms | 25976 KB | Output is correct |
42 | Correct | 22 ms | 25976 KB | Output is correct |
43 | Correct | 23 ms | 26108 KB | Output is correct |
44 | Correct | 20 ms | 25720 KB | Output is correct |
45 | Correct | 23 ms | 26104 KB | Output is correct |
46 | Correct | 23 ms | 25976 KB | Output is correct |
47 | Correct | 21 ms | 25720 KB | Output is correct |
48 | Correct | 23 ms | 25976 KB | Output is correct |
49 | Correct | 23 ms | 26104 KB | Output is correct |
50 | Correct | 22 ms | 26104 KB | Output is correct |
51 | Correct | 23 ms | 25976 KB | Output is correct |
52 | Correct | 23 ms | 25976 KB | Output is correct |
53 | Correct | 22 ms | 25976 KB | Output is correct |
54 | Correct | 22 ms | 25976 KB | Output is correct |
55 | Correct | 21 ms | 25720 KB | Output is correct |
56 | Correct | 83 ms | 32868 KB | Output is correct |
57 | Correct | 105 ms | 32488 KB | Output is correct |
58 | Correct | 23 ms | 25976 KB | Output is correct |
59 | Correct | 21 ms | 25720 KB | Output is correct |
60 | Correct | 21 ms | 25720 KB | Output is correct |
61 | Correct | 104 ms | 32616 KB | Output is correct |
62 | Correct | 22 ms | 25976 KB | Output is correct |
63 | Correct | 116 ms | 36712 KB | Output is correct |
64 | Correct | 106 ms | 32488 KB | Output is correct |
65 | Correct | 22 ms | 25976 KB | Output is correct |
66 | Correct | 111 ms | 33004 KB | Output is correct |
67 | Correct | 23 ms | 25976 KB | Output is correct |
68 | Correct | 22 ms | 25976 KB | Output is correct |
69 | Correct | 85 ms | 32744 KB | Output is correct |
70 | Correct | 23 ms | 26104 KB | Output is correct |
71 | Correct | 107 ms | 32876 KB | Output is correct |
72 | Correct | 109 ms | 33900 KB | Output is correct |
73 | Correct | 20 ms | 25720 KB | Output is correct |
74 | Correct | 116 ms | 37228 KB | Output is correct |
75 | Correct | 111 ms | 34664 KB | Output is correct |
76 | Correct | 22 ms | 25976 KB | Output is correct |
77 | Correct | 23 ms | 25976 KB | Output is correct |
78 | Correct | 81 ms | 31460 KB | Output is correct |
79 | Correct | 96 ms | 34404 KB | Output is correct |
80 | Correct | 22 ms | 25976 KB | Output is correct |
81 | Correct | 24 ms | 25976 KB | Output is correct |
82 | Correct | 20 ms | 25720 KB | Output is correct |
83 | Correct | 20 ms | 25720 KB | Output is correct |
84 | Correct | 22 ms | 25976 KB | Output is correct |
85 | Correct | 122 ms | 34284 KB | Output is correct |
86 | Correct | 22 ms | 25976 KB | Output is correct |
87 | Correct | 106 ms | 33132 KB | Output is correct |
88 | Correct | 21 ms | 25720 KB | Output is correct |
89 | Correct | 110 ms | 33000 KB | Output is correct |
90 | Correct | 124 ms | 34152 KB | Output is correct |
91 | Correct | 116 ms | 35820 KB | Output is correct |
92 | Correct | 85 ms | 32768 KB | Output is correct |
93 | Correct | 22 ms | 25976 KB | Output is correct |
94 | Correct | 21 ms | 25720 KB | Output is correct |
95 | Correct | 103 ms | 35816 KB | Output is correct |
96 | Correct | 122 ms | 38124 KB | Output is correct |
97 | Correct | 23 ms | 25976 KB | Output is correct |
98 | Correct | 20 ms | 25720 KB | Output is correct |
99 | Correct | 100 ms | 34532 KB | Output is correct |
100 | Correct | 23 ms | 25976 KB | Output is correct |
101 | Correct | 118 ms | 33388 KB | Output is correct |
102 | Correct | 118 ms | 37356 KB | Output is correct |
103 | Correct | 23 ms | 26104 KB | Output is correct |
104 | Correct | 22 ms | 26104 KB | Output is correct |
105 | Correct | 22 ms | 25976 KB | Output is correct |
106 | Correct | 22 ms | 26048 KB | Output is correct |
107 | Correct | 22 ms | 25976 KB | Output is correct |
108 | Correct | 583 ms | 64708 KB | Output is correct |
109 | Correct | 725 ms | 69084 KB | Output is correct |
110 | Correct | 731 ms | 75740 KB | Output is correct |
111 | Correct | 815 ms | 85596 KB | Output is correct |
112 | Correct | 794 ms | 79708 KB | Output is correct |
113 | Correct | 646 ms | 71900 KB | Output is correct |
114 | Correct | 628 ms | 57820 KB | Output is correct |
115 | Correct | 626 ms | 58464 KB | Output is correct |
116 | Correct | 759 ms | 60644 KB | Output is correct |
117 | Correct | 735 ms | 71516 KB | Output is correct |
118 | Correct | 645 ms | 58104 KB | Output is correct |
119 | Correct | 753 ms | 71516 KB | Output is correct |
120 | Correct | 761 ms | 79628 KB | Output is correct |
121 | Correct | 740 ms | 71516 KB | Output is correct |
122 | Correct | 788 ms | 65244 KB | Output is correct |
123 | Correct | 534 ms | 72784 KB | Output is correct |
124 | Correct | 788 ms | 70492 KB | Output is correct |