# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
130465 | 2019-07-15T09:13:51 Z | DodgeBallMan | Mergers (JOI19_mergers) | C++14 | 895 ms | 91100 KB |
#include <bits/stdc++.h> #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 5e5 + 10; int par[N], dep[N], dsu[N], deg[N], n, k, cnt; vector<int> g[N], co[N]; vector<pii> e; void pre( int now, int p ) { par[now] = p, dep[now] = dep[p] + 1; for( int i : g[now] ) if( i != p ) pre( i, now ); } int find( int now ) { return dsu[now] = dsu[now] == now ? now : find( dsu[now] ); } int main() { scanf("%d %d",&n,&k); for( int i = 1 ; i <= n ; i++ ) dsu[i] = i; for( int i = 1, u, v ; i <= n - 1 ; i++ ) { scanf("%d %d",&u,&v); g[u].emplace_back( v ), g[v].emplace_back( u ); e.emplace_back( pii( u, v ) ); } for( int i = 1, s ; i <= n ; i++ ) { scanf("%d",&s); co[s].emplace_back( i ); } pre( 1, 0 ); for( int i = 1 ; i <= k ; i++ ) if( co[i].size() > 1 ) { for( int j = 1 ; j < co[i].size() ; j++ ) { int a = find( co[i][j] ), b = find( co[i][j-1] ); while( a != b ) { if( dep[a] < dep[b] ) swap( a, b ); dsu[a] = find( par[a] ); a = dsu[a]; } } } for( int i = 0 ; i < e.size() ; i++ ) { int a = find( e[i].x ), b = find( e[i].y ); if( a != b ) deg[a]++, deg[b]++; } for( int i = 1 ; i <= n ; i++ ) if( deg[i] == 1 ) cnt++; printf("%d",( cnt + 1 ) >> 1 ); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23800 KB | Output is correct |
2 | Correct | 23 ms | 23804 KB | Output is correct |
3 | Correct | 29 ms | 23800 KB | Output is correct |
4 | Correct | 23 ms | 23804 KB | Output is correct |
5 | Correct | 23 ms | 23800 KB | Output is correct |
6 | Correct | 23 ms | 23800 KB | Output is correct |
7 | Correct | 28 ms | 23800 KB | Output is correct |
8 | Correct | 23 ms | 23928 KB | Output is correct |
9 | Correct | 23 ms | 23752 KB | Output is correct |
10 | Correct | 23 ms | 23800 KB | Output is correct |
11 | Correct | 28 ms | 23928 KB | Output is correct |
12 | Correct | 23 ms | 23928 KB | Output is correct |
13 | Correct | 24 ms | 23800 KB | Output is correct |
14 | Correct | 23 ms | 23800 KB | Output is correct |
15 | Correct | 24 ms | 23800 KB | Output is correct |
16 | Correct | 23 ms | 23800 KB | Output is correct |
17 | Correct | 23 ms | 23772 KB | Output is correct |
18 | Correct | 23 ms | 23800 KB | Output is correct |
19 | Correct | 23 ms | 23800 KB | Output is correct |
20 | Correct | 23 ms | 23800 KB | Output is correct |
21 | Correct | 23 ms | 23800 KB | Output is correct |
22 | Correct | 23 ms | 23800 KB | Output is correct |
23 | Correct | 23 ms | 23800 KB | Output is correct |
24 | Correct | 23 ms | 23800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23800 KB | Output is correct |
2 | Correct | 23 ms | 23804 KB | Output is correct |
3 | Correct | 29 ms | 23800 KB | Output is correct |
4 | Correct | 23 ms | 23804 KB | Output is correct |
5 | Correct | 23 ms | 23800 KB | Output is correct |
6 | Correct | 23 ms | 23800 KB | Output is correct |
7 | Correct | 28 ms | 23800 KB | Output is correct |
8 | Correct | 23 ms | 23928 KB | Output is correct |
9 | Correct | 23 ms | 23752 KB | Output is correct |
10 | Correct | 23 ms | 23800 KB | Output is correct |
11 | Correct | 28 ms | 23928 KB | Output is correct |
12 | Correct | 23 ms | 23928 KB | Output is correct |
13 | Correct | 24 ms | 23800 KB | Output is correct |
14 | Correct | 23 ms | 23800 KB | Output is correct |
15 | Correct | 24 ms | 23800 KB | Output is correct |
16 | Correct | 23 ms | 23800 KB | Output is correct |
17 | Correct | 23 ms | 23772 KB | Output is correct |
18 | Correct | 23 ms | 23800 KB | Output is correct |
19 | Correct | 23 ms | 23800 KB | Output is correct |
20 | Correct | 23 ms | 23800 KB | Output is correct |
21 | Correct | 23 ms | 23800 KB | Output is correct |
22 | Correct | 23 ms | 23800 KB | Output is correct |
23 | Correct | 23 ms | 23800 KB | Output is correct |
24 | Correct | 23 ms | 23800 KB | Output is correct |
25 | Correct | 23 ms | 23800 KB | Output is correct |
26 | Correct | 30 ms | 24056 KB | Output is correct |
27 | Correct | 26 ms | 24056 KB | Output is correct |
28 | Correct | 25 ms | 24156 KB | Output is correct |
29 | Correct | 25 ms | 24184 KB | Output is correct |
30 | Correct | 25 ms | 24056 KB | Output is correct |
31 | Correct | 23 ms | 23800 KB | Output is correct |
32 | Correct | 27 ms | 24312 KB | Output is correct |
33 | Correct | 23 ms | 23800 KB | Output is correct |
34 | Correct | 24 ms | 24184 KB | Output is correct |
35 | Correct | 25 ms | 24184 KB | Output is correct |
36 | Correct | 25 ms | 24056 KB | Output is correct |
37 | Correct | 25 ms | 24056 KB | Output is correct |
38 | Correct | 23 ms | 23800 KB | Output is correct |
39 | Correct | 25 ms | 24056 KB | Output is correct |
40 | Correct | 25 ms | 24056 KB | Output is correct |
41 | Correct | 28 ms | 24004 KB | Output is correct |
42 | Correct | 29 ms | 24184 KB | Output is correct |
43 | Correct | 25 ms | 24184 KB | Output is correct |
44 | Correct | 27 ms | 23800 KB | Output is correct |
45 | Correct | 26 ms | 24184 KB | Output is correct |
46 | Correct | 30 ms | 24060 KB | Output is correct |
47 | Correct | 28 ms | 23800 KB | Output is correct |
48 | Correct | 26 ms | 24056 KB | Output is correct |
49 | Correct | 29 ms | 24184 KB | Output is correct |
50 | Correct | 29 ms | 24184 KB | Output is correct |
51 | Correct | 26 ms | 24184 KB | Output is correct |
52 | Correct | 25 ms | 24052 KB | Output is correct |
53 | Correct | 25 ms | 24056 KB | Output is correct |
54 | Correct | 30 ms | 24056 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23800 KB | Output is correct |
2 | Correct | 23 ms | 23804 KB | Output is correct |
3 | Correct | 29 ms | 23800 KB | Output is correct |
4 | Correct | 23 ms | 23804 KB | Output is correct |
5 | Correct | 23 ms | 23800 KB | Output is correct |
6 | Correct | 23 ms | 23800 KB | Output is correct |
7 | Correct | 28 ms | 23800 KB | Output is correct |
8 | Correct | 23 ms | 23928 KB | Output is correct |
9 | Correct | 23 ms | 23752 KB | Output is correct |
10 | Correct | 23 ms | 23800 KB | Output is correct |
11 | Correct | 28 ms | 23928 KB | Output is correct |
12 | Correct | 23 ms | 23928 KB | Output is correct |
13 | Correct | 24 ms | 23800 KB | Output is correct |
14 | Correct | 23 ms | 23800 KB | Output is correct |
15 | Correct | 24 ms | 23800 KB | Output is correct |
16 | Correct | 23 ms | 23800 KB | Output is correct |
17 | Correct | 23 ms | 23772 KB | Output is correct |
18 | Correct | 23 ms | 23800 KB | Output is correct |
19 | Correct | 23 ms | 23800 KB | Output is correct |
20 | Correct | 23 ms | 23800 KB | Output is correct |
21 | Correct | 23 ms | 23800 KB | Output is correct |
22 | Correct | 23 ms | 23800 KB | Output is correct |
23 | Correct | 23 ms | 23800 KB | Output is correct |
24 | Correct | 23 ms | 23800 KB | Output is correct |
25 | Correct | 23 ms | 23800 KB | Output is correct |
26 | Correct | 92 ms | 31348 KB | Output is correct |
27 | Correct | 142 ms | 30912 KB | Output is correct |
28 | Correct | 26 ms | 24056 KB | Output is correct |
29 | Correct | 24 ms | 23928 KB | Output is correct |
30 | Correct | 29 ms | 23804 KB | Output is correct |
31 | Correct | 122 ms | 31180 KB | Output is correct |
32 | Correct | 25 ms | 24056 KB | Output is correct |
33 | Correct | 139 ms | 35304 KB | Output is correct |
34 | Correct | 120 ms | 30908 KB | Output is correct |
35 | Correct | 27 ms | 24156 KB | Output is correct |
36 | Correct | 128 ms | 31440 KB | Output is correct |
37 | Correct | 25 ms | 24056 KB | Output is correct |
38 | Correct | 26 ms | 24056 KB | Output is correct |
39 | Correct | 97 ms | 31208 KB | Output is correct |
40 | Correct | 24 ms | 24184 KB | Output is correct |
41 | Correct | 117 ms | 31340 KB | Output is correct |
42 | Correct | 137 ms | 32304 KB | Output is correct |
43 | Correct | 23 ms | 23800 KB | Output is correct |
44 | Correct | 135 ms | 35712 KB | Output is correct |
45 | Correct | 124 ms | 33256 KB | Output is correct |
46 | Correct | 25 ms | 24184 KB | Output is correct |
47 | Correct | 25 ms | 24060 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 94 ms | 31328 KB | Output is correct |
2 | Correct | 114 ms | 34648 KB | Output is correct |
3 | Correct | 26 ms | 24056 KB | Output is correct |
4 | Correct | 25 ms | 24056 KB | Output is correct |
5 | Correct | 23 ms | 23800 KB | Output is correct |
6 | Correct | 23 ms | 23800 KB | Output is correct |
7 | Correct | 25 ms | 24184 KB | Output is correct |
8 | Correct | 143 ms | 32748 KB | Output is correct |
9 | Correct | 25 ms | 24184 KB | Output is correct |
10 | Correct | 143 ms | 31620 KB | Output is correct |
11 | Correct | 23 ms | 23928 KB | Output is correct |
12 | Correct | 135 ms | 31592 KB | Output is correct |
13 | Correct | 143 ms | 32620 KB | Output is correct |
14 | Correct | 136 ms | 34368 KB | Output is correct |
15 | Correct | 100 ms | 31340 KB | Output is correct |
16 | Correct | 25 ms | 24184 KB | Output is correct |
17 | Correct | 23 ms | 24056 KB | Output is correct |
18 | Correct | 129 ms | 34288 KB | Output is correct |
19 | Correct | 141 ms | 36600 KB | Output is correct |
20 | Correct | 26 ms | 24056 KB | Output is correct |
21 | Correct | 28 ms | 23800 KB | Output is correct |
22 | Correct | 113 ms | 32948 KB | Output is correct |
23 | Correct | 25 ms | 24060 KB | Output is correct |
24 | Correct | 159 ms | 32004 KB | Output is correct |
25 | Correct | 140 ms | 35792 KB | Output is correct |
26 | Correct | 27 ms | 24156 KB | Output is correct |
27 | Correct | 25 ms | 24184 KB | Output is correct |
28 | Correct | 26 ms | 24060 KB | Output is correct |
29 | Correct | 26 ms | 24056 KB | Output is correct |
30 | Correct | 25 ms | 24184 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23800 KB | Output is correct |
2 | Correct | 23 ms | 23804 KB | Output is correct |
3 | Correct | 29 ms | 23800 KB | Output is correct |
4 | Correct | 23 ms | 23804 KB | Output is correct |
5 | Correct | 23 ms | 23800 KB | Output is correct |
6 | Correct | 23 ms | 23800 KB | Output is correct |
7 | Correct | 28 ms | 23800 KB | Output is correct |
8 | Correct | 23 ms | 23928 KB | Output is correct |
9 | Correct | 23 ms | 23752 KB | Output is correct |
10 | Correct | 23 ms | 23800 KB | Output is correct |
11 | Correct | 28 ms | 23928 KB | Output is correct |
12 | Correct | 23 ms | 23928 KB | Output is correct |
13 | Correct | 24 ms | 23800 KB | Output is correct |
14 | Correct | 23 ms | 23800 KB | Output is correct |
15 | Correct | 24 ms | 23800 KB | Output is correct |
16 | Correct | 23 ms | 23800 KB | Output is correct |
17 | Correct | 23 ms | 23772 KB | Output is correct |
18 | Correct | 23 ms | 23800 KB | Output is correct |
19 | Correct | 23 ms | 23800 KB | Output is correct |
20 | Correct | 23 ms | 23800 KB | Output is correct |
21 | Correct | 23 ms | 23800 KB | Output is correct |
22 | Correct | 23 ms | 23800 KB | Output is correct |
23 | Correct | 23 ms | 23800 KB | Output is correct |
24 | Correct | 23 ms | 23800 KB | Output is correct |
25 | Correct | 23 ms | 23800 KB | Output is correct |
26 | Correct | 30 ms | 24056 KB | Output is correct |
27 | Correct | 26 ms | 24056 KB | Output is correct |
28 | Correct | 25 ms | 24156 KB | Output is correct |
29 | Correct | 25 ms | 24184 KB | Output is correct |
30 | Correct | 25 ms | 24056 KB | Output is correct |
31 | Correct | 23 ms | 23800 KB | Output is correct |
32 | Correct | 27 ms | 24312 KB | Output is correct |
33 | Correct | 23 ms | 23800 KB | Output is correct |
34 | Correct | 24 ms | 24184 KB | Output is correct |
35 | Correct | 25 ms | 24184 KB | Output is correct |
36 | Correct | 25 ms | 24056 KB | Output is correct |
37 | Correct | 25 ms | 24056 KB | Output is correct |
38 | Correct | 23 ms | 23800 KB | Output is correct |
39 | Correct | 25 ms | 24056 KB | Output is correct |
40 | Correct | 25 ms | 24056 KB | Output is correct |
41 | Correct | 28 ms | 24004 KB | Output is correct |
42 | Correct | 29 ms | 24184 KB | Output is correct |
43 | Correct | 25 ms | 24184 KB | Output is correct |
44 | Correct | 27 ms | 23800 KB | Output is correct |
45 | Correct | 26 ms | 24184 KB | Output is correct |
46 | Correct | 30 ms | 24060 KB | Output is correct |
47 | Correct | 28 ms | 23800 KB | Output is correct |
48 | Correct | 26 ms | 24056 KB | Output is correct |
49 | Correct | 29 ms | 24184 KB | Output is correct |
50 | Correct | 29 ms | 24184 KB | Output is correct |
51 | Correct | 26 ms | 24184 KB | Output is correct |
52 | Correct | 25 ms | 24052 KB | Output is correct |
53 | Correct | 25 ms | 24056 KB | Output is correct |
54 | Correct | 30 ms | 24056 KB | Output is correct |
55 | Correct | 23 ms | 23800 KB | Output is correct |
56 | Correct | 92 ms | 31348 KB | Output is correct |
57 | Correct | 142 ms | 30912 KB | Output is correct |
58 | Correct | 26 ms | 24056 KB | Output is correct |
59 | Correct | 24 ms | 23928 KB | Output is correct |
60 | Correct | 29 ms | 23804 KB | Output is correct |
61 | Correct | 122 ms | 31180 KB | Output is correct |
62 | Correct | 25 ms | 24056 KB | Output is correct |
63 | Correct | 139 ms | 35304 KB | Output is correct |
64 | Correct | 120 ms | 30908 KB | Output is correct |
65 | Correct | 27 ms | 24156 KB | Output is correct |
66 | Correct | 128 ms | 31440 KB | Output is correct |
67 | Correct | 25 ms | 24056 KB | Output is correct |
68 | Correct | 26 ms | 24056 KB | Output is correct |
69 | Correct | 97 ms | 31208 KB | Output is correct |
70 | Correct | 24 ms | 24184 KB | Output is correct |
71 | Correct | 117 ms | 31340 KB | Output is correct |
72 | Correct | 137 ms | 32304 KB | Output is correct |
73 | Correct | 23 ms | 23800 KB | Output is correct |
74 | Correct | 135 ms | 35712 KB | Output is correct |
75 | Correct | 124 ms | 33256 KB | Output is correct |
76 | Correct | 25 ms | 24184 KB | Output is correct |
77 | Correct | 25 ms | 24060 KB | Output is correct |
78 | Correct | 94 ms | 31328 KB | Output is correct |
79 | Correct | 114 ms | 34648 KB | Output is correct |
80 | Correct | 26 ms | 24056 KB | Output is correct |
81 | Correct | 25 ms | 24056 KB | Output is correct |
82 | Correct | 23 ms | 23800 KB | Output is correct |
83 | Correct | 23 ms | 23800 KB | Output is correct |
84 | Correct | 25 ms | 24184 KB | Output is correct |
85 | Correct | 143 ms | 32748 KB | Output is correct |
86 | Correct | 25 ms | 24184 KB | Output is correct |
87 | Correct | 143 ms | 31620 KB | Output is correct |
88 | Correct | 23 ms | 23928 KB | Output is correct |
89 | Correct | 135 ms | 31592 KB | Output is correct |
90 | Correct | 143 ms | 32620 KB | Output is correct |
91 | Correct | 136 ms | 34368 KB | Output is correct |
92 | Correct | 100 ms | 31340 KB | Output is correct |
93 | Correct | 25 ms | 24184 KB | Output is correct |
94 | Correct | 23 ms | 24056 KB | Output is correct |
95 | Correct | 129 ms | 34288 KB | Output is correct |
96 | Correct | 141 ms | 36600 KB | Output is correct |
97 | Correct | 26 ms | 24056 KB | Output is correct |
98 | Correct | 28 ms | 23800 KB | Output is correct |
99 | Correct | 113 ms | 32948 KB | Output is correct |
100 | Correct | 25 ms | 24060 KB | Output is correct |
101 | Correct | 159 ms | 32004 KB | Output is correct |
102 | Correct | 140 ms | 35792 KB | Output is correct |
103 | Correct | 27 ms | 24156 KB | Output is correct |
104 | Correct | 25 ms | 24184 KB | Output is correct |
105 | Correct | 26 ms | 24060 KB | Output is correct |
106 | Correct | 26 ms | 24056 KB | Output is correct |
107 | Correct | 25 ms | 24184 KB | Output is correct |
108 | Correct | 682 ms | 69560 KB | Output is correct |
109 | Correct | 767 ms | 71888 KB | Output is correct |
110 | Correct | 772 ms | 78812 KB | Output is correct |
111 | Correct | 895 ms | 91100 KB | Output is correct |
112 | Correct | 852 ms | 85160 KB | Output is correct |
113 | Correct | 886 ms | 77524 KB | Output is correct |
114 | Correct | 707 ms | 61020 KB | Output is correct |
115 | Correct | 698 ms | 61460 KB | Output is correct |
116 | Correct | 892 ms | 66012 KB | Output is correct |
117 | Correct | 821 ms | 77452 KB | Output is correct |
118 | Correct | 676 ms | 62192 KB | Output is correct |
119 | Correct | 872 ms | 77400 KB | Output is correct |
120 | Correct | 823 ms | 85592 KB | Output is correct |
121 | Correct | 895 ms | 77360 KB | Output is correct |
122 | Correct | 873 ms | 71056 KB | Output is correct |
123 | Correct | 584 ms | 78828 KB | Output is correct |
124 | Correct | 849 ms | 75900 KB | Output is correct |