# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
130468 | 2019-07-15T09:17:43 Z | DodgeBallMan | Mergers (JOI19_mergers) | C++14 | 878 ms | 81204 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); e.reserve(n); 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 ); a = dsu[a] = find( par[a] ); } } } for(auto &x : e) if(find(x.x) != find(x.y)) deg[find(x.x)]++, deg[find(x.y)]++; for( int i = 1 ; i <= n ; i++ ) if( deg[i] == 1 ) cnt++; printf("%d",( cnt + 1 ) / 2); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23804 KB | Output is correct |
2 | Correct | 23 ms | 23800 KB | Output is correct |
3 | Correct | 23 ms | 23800 KB | Output is correct |
4 | Correct | 24 ms | 23800 KB | Output is correct |
5 | Correct | 23 ms | 23800 KB | Output is correct |
6 | Correct | 24 ms | 23800 KB | Output is correct |
7 | Correct | 23 ms | 23800 KB | Output is correct |
8 | Correct | 23 ms | 23800 KB | Output is correct |
9 | Correct | 24 ms | 23764 KB | Output is correct |
10 | Correct | 24 ms | 23928 KB | Output is correct |
11 | Correct | 24 ms | 23800 KB | Output is correct |
12 | Correct | 23 ms | 23800 KB | Output is correct |
13 | Correct | 28 ms | 23800 KB | Output is correct |
14 | Correct | 23 ms | 23800 KB | Output is correct |
15 | Correct | 23 ms | 23804 KB | Output is correct |
16 | Correct | 24 ms | 23800 KB | Output is correct |
17 | Correct | 24 ms | 23800 KB | Output is correct |
18 | Correct | 24 ms | 23928 KB | Output is correct |
19 | Correct | 24 ms | 23800 KB | Output is correct |
20 | Correct | 24 ms | 23816 KB | Output is correct |
21 | Correct | 23 ms | 23804 KB | Output is correct |
22 | Correct | 24 ms | 23800 KB | Output is correct |
23 | Correct | 24 ms | 23876 KB | Output is correct |
24 | Correct | 24 ms | 23800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23804 KB | Output is correct |
2 | Correct | 23 ms | 23800 KB | Output is correct |
3 | Correct | 23 ms | 23800 KB | Output is correct |
4 | Correct | 24 ms | 23800 KB | Output is correct |
5 | Correct | 23 ms | 23800 KB | Output is correct |
6 | Correct | 24 ms | 23800 KB | Output is correct |
7 | Correct | 23 ms | 23800 KB | Output is correct |
8 | Correct | 23 ms | 23800 KB | Output is correct |
9 | Correct | 24 ms | 23764 KB | Output is correct |
10 | Correct | 24 ms | 23928 KB | Output is correct |
11 | Correct | 24 ms | 23800 KB | Output is correct |
12 | Correct | 23 ms | 23800 KB | Output is correct |
13 | Correct | 28 ms | 23800 KB | Output is correct |
14 | Correct | 23 ms | 23800 KB | Output is correct |
15 | Correct | 23 ms | 23804 KB | Output is correct |
16 | Correct | 24 ms | 23800 KB | Output is correct |
17 | Correct | 24 ms | 23800 KB | Output is correct |
18 | Correct | 24 ms | 23928 KB | Output is correct |
19 | Correct | 24 ms | 23800 KB | Output is correct |
20 | Correct | 24 ms | 23816 KB | Output is correct |
21 | Correct | 23 ms | 23804 KB | Output is correct |
22 | Correct | 24 ms | 23800 KB | Output is correct |
23 | Correct | 24 ms | 23876 KB | Output is correct |
24 | Correct | 24 ms | 23800 KB | Output is correct |
25 | Correct | 25 ms | 23800 KB | Output is correct |
26 | Correct | 27 ms | 24056 KB | Output is correct |
27 | Correct | 27 ms | 24028 KB | Output is correct |
28 | Correct | 26 ms | 24184 KB | Output is correct |
29 | Correct | 26 ms | 24188 KB | Output is correct |
30 | Correct | 27 ms | 24056 KB | Output is correct |
31 | Correct | 30 ms | 23800 KB | Output is correct |
32 | Correct | 31 ms | 24312 KB | Output is correct |
33 | Correct | 24 ms | 23800 KB | Output is correct |
34 | Correct | 26 ms | 24056 KB | Output is correct |
35 | Correct | 32 ms | 24184 KB | Output is correct |
36 | Correct | 26 ms | 24056 KB | Output is correct |
37 | Correct | 26 ms | 24056 KB | Output is correct |
38 | Correct | 24 ms | 23928 KB | Output is correct |
39 | Correct | 26 ms | 24056 KB | Output is correct |
40 | Correct | 30 ms | 24056 KB | Output is correct |
41 | Correct | 26 ms | 24056 KB | Output is correct |
42 | Correct | 26 ms | 24056 KB | Output is correct |
43 | Correct | 26 ms | 24184 KB | Output is correct |
44 | Correct | 24 ms | 23928 KB | Output is correct |
45 | Correct | 26 ms | 24184 KB | Output is correct |
46 | Correct | 26 ms | 24056 KB | Output is correct |
47 | Correct | 24 ms | 23800 KB | Output is correct |
48 | Correct | 27 ms | 24056 KB | Output is correct |
49 | Correct | 27 ms | 24188 KB | Output is correct |
50 | Correct | 26 ms | 24184 KB | Output is correct |
51 | Correct | 26 ms | 24060 KB | Output is correct |
52 | Correct | 26 ms | 24056 KB | Output is correct |
53 | Correct | 26 ms | 24056 KB | Output is correct |
54 | Correct | 26 ms | 24056 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23804 KB | Output is correct |
2 | Correct | 23 ms | 23800 KB | Output is correct |
3 | Correct | 23 ms | 23800 KB | Output is correct |
4 | Correct | 24 ms | 23800 KB | Output is correct |
5 | Correct | 23 ms | 23800 KB | Output is correct |
6 | Correct | 24 ms | 23800 KB | Output is correct |
7 | Correct | 23 ms | 23800 KB | Output is correct |
8 | Correct | 23 ms | 23800 KB | Output is correct |
9 | Correct | 24 ms | 23764 KB | Output is correct |
10 | Correct | 24 ms | 23928 KB | Output is correct |
11 | Correct | 24 ms | 23800 KB | Output is correct |
12 | Correct | 23 ms | 23800 KB | Output is correct |
13 | Correct | 28 ms | 23800 KB | Output is correct |
14 | Correct | 23 ms | 23800 KB | Output is correct |
15 | Correct | 23 ms | 23804 KB | Output is correct |
16 | Correct | 24 ms | 23800 KB | Output is correct |
17 | Correct | 24 ms | 23800 KB | Output is correct |
18 | Correct | 24 ms | 23928 KB | Output is correct |
19 | Correct | 24 ms | 23800 KB | Output is correct |
20 | Correct | 24 ms | 23816 KB | Output is correct |
21 | Correct | 23 ms | 23804 KB | Output is correct |
22 | Correct | 24 ms | 23800 KB | Output is correct |
23 | Correct | 24 ms | 23876 KB | Output is correct |
24 | Correct | 24 ms | 23800 KB | Output is correct |
25 | Correct | 29 ms | 23880 KB | Output is correct |
26 | Correct | 98 ms | 30236 KB | Output is correct |
27 | Correct | 122 ms | 29788 KB | Output is correct |
28 | Correct | 26 ms | 24060 KB | Output is correct |
29 | Correct | 23 ms | 23852 KB | Output is correct |
30 | Correct | 28 ms | 23800 KB | Output is correct |
31 | Correct | 121 ms | 29916 KB | Output is correct |
32 | Correct | 27 ms | 24056 KB | Output is correct |
33 | Correct | 153 ms | 34060 KB | Output is correct |
34 | Correct | 118 ms | 29884 KB | Output is correct |
35 | Correct | 26 ms | 24056 KB | Output is correct |
36 | Correct | 130 ms | 30328 KB | Output is correct |
37 | Correct | 26 ms | 24056 KB | Output is correct |
38 | Correct | 25 ms | 24056 KB | Output is correct |
39 | Correct | 101 ms | 30148 KB | Output is correct |
40 | Correct | 26 ms | 24184 KB | Output is correct |
41 | Correct | 116 ms | 29848 KB | Output is correct |
42 | Correct | 127 ms | 31100 KB | Output is correct |
43 | Correct | 24 ms | 23772 KB | Output is correct |
44 | Correct | 159 ms | 34292 KB | Output is correct |
45 | Correct | 127 ms | 31992 KB | Output is correct |
46 | Correct | 31 ms | 24056 KB | Output is correct |
47 | Correct | 26 ms | 24056 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 92 ms | 29808 KB | Output is correct |
2 | Correct | 141 ms | 32840 KB | Output is correct |
3 | Correct | 26 ms | 24060 KB | Output is correct |
4 | Correct | 31 ms | 24056 KB | Output is correct |
5 | Correct | 24 ms | 23804 KB | Output is correct |
6 | Correct | 29 ms | 23772 KB | Output is correct |
7 | Correct | 26 ms | 24056 KB | Output is correct |
8 | Correct | 138 ms | 31308 KB | Output is correct |
9 | Correct | 26 ms | 24032 KB | Output is correct |
10 | Correct | 119 ms | 30176 KB | Output is correct |
11 | Correct | 24 ms | 23800 KB | Output is correct |
12 | Correct | 129 ms | 30300 KB | Output is correct |
13 | Correct | 139 ms | 31164 KB | Output is correct |
14 | Correct | 134 ms | 32828 KB | Output is correct |
15 | Correct | 92 ms | 30068 KB | Output is correct |
16 | Correct | 26 ms | 24056 KB | Output is correct |
17 | Correct | 24 ms | 23892 KB | Output is correct |
18 | Correct | 110 ms | 32724 KB | Output is correct |
19 | Correct | 146 ms | 35188 KB | Output is correct |
20 | Correct | 26 ms | 24056 KB | Output is correct |
21 | Correct | 29 ms | 23800 KB | Output is correct |
22 | Correct | 111 ms | 31648 KB | Output is correct |
23 | Correct | 26 ms | 24056 KB | Output is correct |
24 | Correct | 140 ms | 30456 KB | Output is correct |
25 | Correct | 153 ms | 34344 KB | Output is correct |
26 | Correct | 26 ms | 24184 KB | Output is correct |
27 | Correct | 27 ms | 24184 KB | Output is correct |
28 | Correct | 26 ms | 24056 KB | Output is correct |
29 | Correct | 26 ms | 24056 KB | Output is correct |
30 | Correct | 26 ms | 24056 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23804 KB | Output is correct |
2 | Correct | 23 ms | 23800 KB | Output is correct |
3 | Correct | 23 ms | 23800 KB | Output is correct |
4 | Correct | 24 ms | 23800 KB | Output is correct |
5 | Correct | 23 ms | 23800 KB | Output is correct |
6 | Correct | 24 ms | 23800 KB | Output is correct |
7 | Correct | 23 ms | 23800 KB | Output is correct |
8 | Correct | 23 ms | 23800 KB | Output is correct |
9 | Correct | 24 ms | 23764 KB | Output is correct |
10 | Correct | 24 ms | 23928 KB | Output is correct |
11 | Correct | 24 ms | 23800 KB | Output is correct |
12 | Correct | 23 ms | 23800 KB | Output is correct |
13 | Correct | 28 ms | 23800 KB | Output is correct |
14 | Correct | 23 ms | 23800 KB | Output is correct |
15 | Correct | 23 ms | 23804 KB | Output is correct |
16 | Correct | 24 ms | 23800 KB | Output is correct |
17 | Correct | 24 ms | 23800 KB | Output is correct |
18 | Correct | 24 ms | 23928 KB | Output is correct |
19 | Correct | 24 ms | 23800 KB | Output is correct |
20 | Correct | 24 ms | 23816 KB | Output is correct |
21 | Correct | 23 ms | 23804 KB | Output is correct |
22 | Correct | 24 ms | 23800 KB | Output is correct |
23 | Correct | 24 ms | 23876 KB | Output is correct |
24 | Correct | 24 ms | 23800 KB | Output is correct |
25 | Correct | 25 ms | 23800 KB | Output is correct |
26 | Correct | 27 ms | 24056 KB | Output is correct |
27 | Correct | 27 ms | 24028 KB | Output is correct |
28 | Correct | 26 ms | 24184 KB | Output is correct |
29 | Correct | 26 ms | 24188 KB | Output is correct |
30 | Correct | 27 ms | 24056 KB | Output is correct |
31 | Correct | 30 ms | 23800 KB | Output is correct |
32 | Correct | 31 ms | 24312 KB | Output is correct |
33 | Correct | 24 ms | 23800 KB | Output is correct |
34 | Correct | 26 ms | 24056 KB | Output is correct |
35 | Correct | 32 ms | 24184 KB | Output is correct |
36 | Correct | 26 ms | 24056 KB | Output is correct |
37 | Correct | 26 ms | 24056 KB | Output is correct |
38 | Correct | 24 ms | 23928 KB | Output is correct |
39 | Correct | 26 ms | 24056 KB | Output is correct |
40 | Correct | 30 ms | 24056 KB | Output is correct |
41 | Correct | 26 ms | 24056 KB | Output is correct |
42 | Correct | 26 ms | 24056 KB | Output is correct |
43 | Correct | 26 ms | 24184 KB | Output is correct |
44 | Correct | 24 ms | 23928 KB | Output is correct |
45 | Correct | 26 ms | 24184 KB | Output is correct |
46 | Correct | 26 ms | 24056 KB | Output is correct |
47 | Correct | 24 ms | 23800 KB | Output is correct |
48 | Correct | 27 ms | 24056 KB | Output is correct |
49 | Correct | 27 ms | 24188 KB | Output is correct |
50 | Correct | 26 ms | 24184 KB | Output is correct |
51 | Correct | 26 ms | 24060 KB | Output is correct |
52 | Correct | 26 ms | 24056 KB | Output is correct |
53 | Correct | 26 ms | 24056 KB | Output is correct |
54 | Correct | 26 ms | 24056 KB | Output is correct |
55 | Correct | 29 ms | 23880 KB | Output is correct |
56 | Correct | 98 ms | 30236 KB | Output is correct |
57 | Correct | 122 ms | 29788 KB | Output is correct |
58 | Correct | 26 ms | 24060 KB | Output is correct |
59 | Correct | 23 ms | 23852 KB | Output is correct |
60 | Correct | 28 ms | 23800 KB | Output is correct |
61 | Correct | 121 ms | 29916 KB | Output is correct |
62 | Correct | 27 ms | 24056 KB | Output is correct |
63 | Correct | 153 ms | 34060 KB | Output is correct |
64 | Correct | 118 ms | 29884 KB | Output is correct |
65 | Correct | 26 ms | 24056 KB | Output is correct |
66 | Correct | 130 ms | 30328 KB | Output is correct |
67 | Correct | 26 ms | 24056 KB | Output is correct |
68 | Correct | 25 ms | 24056 KB | Output is correct |
69 | Correct | 101 ms | 30148 KB | Output is correct |
70 | Correct | 26 ms | 24184 KB | Output is correct |
71 | Correct | 116 ms | 29848 KB | Output is correct |
72 | Correct | 127 ms | 31100 KB | Output is correct |
73 | Correct | 24 ms | 23772 KB | Output is correct |
74 | Correct | 159 ms | 34292 KB | Output is correct |
75 | Correct | 127 ms | 31992 KB | Output is correct |
76 | Correct | 31 ms | 24056 KB | Output is correct |
77 | Correct | 26 ms | 24056 KB | Output is correct |
78 | Correct | 92 ms | 29808 KB | Output is correct |
79 | Correct | 141 ms | 32840 KB | Output is correct |
80 | Correct | 26 ms | 24060 KB | Output is correct |
81 | Correct | 31 ms | 24056 KB | Output is correct |
82 | Correct | 24 ms | 23804 KB | Output is correct |
83 | Correct | 29 ms | 23772 KB | Output is correct |
84 | Correct | 26 ms | 24056 KB | Output is correct |
85 | Correct | 138 ms | 31308 KB | Output is correct |
86 | Correct | 26 ms | 24032 KB | Output is correct |
87 | Correct | 119 ms | 30176 KB | Output is correct |
88 | Correct | 24 ms | 23800 KB | Output is correct |
89 | Correct | 129 ms | 30300 KB | Output is correct |
90 | Correct | 139 ms | 31164 KB | Output is correct |
91 | Correct | 134 ms | 32828 KB | Output is correct |
92 | Correct | 92 ms | 30068 KB | Output is correct |
93 | Correct | 26 ms | 24056 KB | Output is correct |
94 | Correct | 24 ms | 23892 KB | Output is correct |
95 | Correct | 110 ms | 32724 KB | Output is correct |
96 | Correct | 146 ms | 35188 KB | Output is correct |
97 | Correct | 26 ms | 24056 KB | Output is correct |
98 | Correct | 29 ms | 23800 KB | Output is correct |
99 | Correct | 111 ms | 31648 KB | Output is correct |
100 | Correct | 26 ms | 24056 KB | Output is correct |
101 | Correct | 140 ms | 30456 KB | Output is correct |
102 | Correct | 153 ms | 34344 KB | Output is correct |
103 | Correct | 26 ms | 24184 KB | Output is correct |
104 | Correct | 27 ms | 24184 KB | Output is correct |
105 | Correct | 26 ms | 24056 KB | Output is correct |
106 | Correct | 26 ms | 24056 KB | Output is correct |
107 | Correct | 26 ms | 24056 KB | Output is correct |
108 | Correct | 610 ms | 60008 KB | Output is correct |
109 | Correct | 742 ms | 62748 KB | Output is correct |
110 | Correct | 754 ms | 69688 KB | Output is correct |
111 | Correct | 851 ms | 81204 KB | Output is correct |
112 | Correct | 878 ms | 75576 KB | Output is correct |
113 | Correct | 748 ms | 67492 KB | Output is correct |
114 | Correct | 646 ms | 52268 KB | Output is correct |
115 | Correct | 653 ms | 52328 KB | Output is correct |
116 | Correct | 812 ms | 56684 KB | Output is correct |
117 | Correct | 767 ms | 67704 KB | Output is correct |
118 | Correct | 759 ms | 54156 KB | Output is correct |
119 | Correct | 779 ms | 67544 KB | Output is correct |
120 | Correct | 797 ms | 75772 KB | Output is correct |
121 | Correct | 788 ms | 67620 KB | Output is correct |
122 | Correct | 841 ms | 61288 KB | Output is correct |
123 | Correct | 584 ms | 68944 KB | Output is correct |
124 | Correct | 822 ms | 66296 KB | Output is correct |