# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
374718 |
2021-03-08T02:11:46 Z |
guka415 |
Mergers (JOI19_mergers) |
C++14 |
|
810 ms |
98540 KB |
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define mp make_pair
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int sz = 6e5;
vector<int> adj[sz], reglst[sz];
int n, k;
int ufp[sz], reg[sz], dep[sz], treepar[sz], deg[sz];
void dfs(int src, int prv) {
for (int x : adj[src]) {
if (x != prv) {
treepar[x] = src;
dep[x] = dep[src] + 1;
dfs(x, src);
}
}
}
int getpar(int x) {
while (x != ufp[x]) {
x = ufp[x] = ufp[ufp[x]];
}
return x;
}
void unite(int a, int b) {
int para = getpar(a), parb = getpar(b);
if (para != parb) {
if (dep[para] < dep[parb])swap(para, parb);
ufp[para] = parb;
}
}
int main() {
fast;
cin >> n >> k;
foru(i, 0, n - 1) {
int x, y;
cin >> x >> y;
adj[--x].pb(--y);
adj[y].pb(x);
}
foru(i, 0, n) {
cin >> reg[i]; reglst[reg[i]].pb(i);
ufp[i] = i;
}
treepar[0] = -1;
dfs(0, -1);
for (int r = 1; r <= k; r++) {
for (int j = 1; j < reglst[r].size(); j++) {
int x = getpar(reglst[r][0]), y = getpar(reglst[r][j]);
while (x != y) {
if (dep[x] < dep[y]) {
unite(y, treepar[y]);
y = getpar(y);
}
else {
unite(x, treepar[x]);
x = getpar(x);
}
}
}
}
foru(i, 0, n) {
for (int x : adj[i]) {
if (dep[x] > dep[i] && getpar(x)!=getpar(i))
deg[getpar(x)]++, deg[getpar(i)]++;
}
}
int ret = 0;
foru(i, 0, n)
ret += (deg[i] == 1 && getpar(i) == i);
cout << (ret + 1) / 2 << '\n';
return 0;
}
Compilation message
mergers.cpp: In function 'int main()':
mergers.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int j = 1; j < reglst[r].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
28524 KB |
Output is correct |
2 |
Correct |
18 ms |
28652 KB |
Output is correct |
3 |
Correct |
18 ms |
28524 KB |
Output is correct |
4 |
Correct |
18 ms |
28524 KB |
Output is correct |
5 |
Correct |
18 ms |
28524 KB |
Output is correct |
6 |
Correct |
18 ms |
28524 KB |
Output is correct |
7 |
Correct |
18 ms |
28524 KB |
Output is correct |
8 |
Correct |
18 ms |
28524 KB |
Output is correct |
9 |
Correct |
18 ms |
28524 KB |
Output is correct |
10 |
Correct |
20 ms |
28652 KB |
Output is correct |
11 |
Correct |
18 ms |
28524 KB |
Output is correct |
12 |
Correct |
18 ms |
28544 KB |
Output is correct |
13 |
Correct |
18 ms |
28524 KB |
Output is correct |
14 |
Correct |
18 ms |
28524 KB |
Output is correct |
15 |
Correct |
18 ms |
28544 KB |
Output is correct |
16 |
Correct |
18 ms |
28524 KB |
Output is correct |
17 |
Correct |
18 ms |
28524 KB |
Output is correct |
18 |
Correct |
19 ms |
28524 KB |
Output is correct |
19 |
Correct |
18 ms |
28524 KB |
Output is correct |
20 |
Correct |
18 ms |
28524 KB |
Output is correct |
21 |
Correct |
18 ms |
28536 KB |
Output is correct |
22 |
Correct |
18 ms |
28524 KB |
Output is correct |
23 |
Correct |
18 ms |
28524 KB |
Output is correct |
24 |
Correct |
18 ms |
28524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
28524 KB |
Output is correct |
2 |
Correct |
18 ms |
28652 KB |
Output is correct |
3 |
Correct |
18 ms |
28524 KB |
Output is correct |
4 |
Correct |
18 ms |
28524 KB |
Output is correct |
5 |
Correct |
18 ms |
28524 KB |
Output is correct |
6 |
Correct |
18 ms |
28524 KB |
Output is correct |
7 |
Correct |
18 ms |
28524 KB |
Output is correct |
8 |
Correct |
18 ms |
28524 KB |
Output is correct |
9 |
Correct |
18 ms |
28524 KB |
Output is correct |
10 |
Correct |
20 ms |
28652 KB |
Output is correct |
11 |
Correct |
18 ms |
28524 KB |
Output is correct |
12 |
Correct |
18 ms |
28544 KB |
Output is correct |
13 |
Correct |
18 ms |
28524 KB |
Output is correct |
14 |
Correct |
18 ms |
28524 KB |
Output is correct |
15 |
Correct |
18 ms |
28544 KB |
Output is correct |
16 |
Correct |
18 ms |
28524 KB |
Output is correct |
17 |
Correct |
18 ms |
28524 KB |
Output is correct |
18 |
Correct |
19 ms |
28524 KB |
Output is correct |
19 |
Correct |
18 ms |
28524 KB |
Output is correct |
20 |
Correct |
18 ms |
28524 KB |
Output is correct |
21 |
Correct |
18 ms |
28536 KB |
Output is correct |
22 |
Correct |
18 ms |
28524 KB |
Output is correct |
23 |
Correct |
18 ms |
28524 KB |
Output is correct |
24 |
Correct |
18 ms |
28524 KB |
Output is correct |
25 |
Correct |
18 ms |
28524 KB |
Output is correct |
26 |
Correct |
19 ms |
28780 KB |
Output is correct |
27 |
Correct |
20 ms |
28800 KB |
Output is correct |
28 |
Correct |
20 ms |
28908 KB |
Output is correct |
29 |
Correct |
20 ms |
28780 KB |
Output is correct |
30 |
Correct |
19 ms |
28780 KB |
Output is correct |
31 |
Correct |
18 ms |
28524 KB |
Output is correct |
32 |
Correct |
20 ms |
28908 KB |
Output is correct |
33 |
Correct |
18 ms |
28524 KB |
Output is correct |
34 |
Correct |
19 ms |
28780 KB |
Output is correct |
35 |
Correct |
20 ms |
28780 KB |
Output is correct |
36 |
Correct |
20 ms |
28780 KB |
Output is correct |
37 |
Correct |
20 ms |
28780 KB |
Output is correct |
38 |
Correct |
18 ms |
28524 KB |
Output is correct |
39 |
Correct |
20 ms |
28780 KB |
Output is correct |
40 |
Correct |
20 ms |
28780 KB |
Output is correct |
41 |
Correct |
20 ms |
28780 KB |
Output is correct |
42 |
Correct |
21 ms |
28908 KB |
Output is correct |
43 |
Correct |
20 ms |
28908 KB |
Output is correct |
44 |
Correct |
18 ms |
28524 KB |
Output is correct |
45 |
Correct |
21 ms |
28908 KB |
Output is correct |
46 |
Correct |
20 ms |
28780 KB |
Output is correct |
47 |
Correct |
18 ms |
28524 KB |
Output is correct |
48 |
Correct |
20 ms |
28780 KB |
Output is correct |
49 |
Correct |
23 ms |
29088 KB |
Output is correct |
50 |
Correct |
20 ms |
29036 KB |
Output is correct |
51 |
Correct |
21 ms |
28780 KB |
Output is correct |
52 |
Correct |
19 ms |
28780 KB |
Output is correct |
53 |
Correct |
20 ms |
28780 KB |
Output is correct |
54 |
Correct |
20 ms |
28780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
28524 KB |
Output is correct |
2 |
Correct |
18 ms |
28652 KB |
Output is correct |
3 |
Correct |
18 ms |
28524 KB |
Output is correct |
4 |
Correct |
18 ms |
28524 KB |
Output is correct |
5 |
Correct |
18 ms |
28524 KB |
Output is correct |
6 |
Correct |
18 ms |
28524 KB |
Output is correct |
7 |
Correct |
18 ms |
28524 KB |
Output is correct |
8 |
Correct |
18 ms |
28524 KB |
Output is correct |
9 |
Correct |
18 ms |
28524 KB |
Output is correct |
10 |
Correct |
20 ms |
28652 KB |
Output is correct |
11 |
Correct |
18 ms |
28524 KB |
Output is correct |
12 |
Correct |
18 ms |
28544 KB |
Output is correct |
13 |
Correct |
18 ms |
28524 KB |
Output is correct |
14 |
Correct |
18 ms |
28524 KB |
Output is correct |
15 |
Correct |
18 ms |
28544 KB |
Output is correct |
16 |
Correct |
18 ms |
28524 KB |
Output is correct |
17 |
Correct |
18 ms |
28524 KB |
Output is correct |
18 |
Correct |
19 ms |
28524 KB |
Output is correct |
19 |
Correct |
18 ms |
28524 KB |
Output is correct |
20 |
Correct |
18 ms |
28524 KB |
Output is correct |
21 |
Correct |
18 ms |
28536 KB |
Output is correct |
22 |
Correct |
18 ms |
28524 KB |
Output is correct |
23 |
Correct |
18 ms |
28524 KB |
Output is correct |
24 |
Correct |
18 ms |
28524 KB |
Output is correct |
25 |
Correct |
20 ms |
28524 KB |
Output is correct |
26 |
Correct |
66 ms |
34148 KB |
Output is correct |
27 |
Correct |
92 ms |
33900 KB |
Output is correct |
28 |
Correct |
19 ms |
28780 KB |
Output is correct |
29 |
Correct |
18 ms |
28524 KB |
Output is correct |
30 |
Correct |
18 ms |
28524 KB |
Output is correct |
31 |
Correct |
85 ms |
34028 KB |
Output is correct |
32 |
Correct |
20 ms |
28800 KB |
Output is correct |
33 |
Correct |
118 ms |
39532 KB |
Output is correct |
34 |
Correct |
88 ms |
33900 KB |
Output is correct |
35 |
Correct |
19 ms |
28780 KB |
Output is correct |
36 |
Correct |
101 ms |
35948 KB |
Output is correct |
37 |
Correct |
20 ms |
28780 KB |
Output is correct |
38 |
Correct |
20 ms |
28780 KB |
Output is correct |
39 |
Correct |
72 ms |
35556 KB |
Output is correct |
40 |
Correct |
20 ms |
28908 KB |
Output is correct |
41 |
Correct |
94 ms |
35172 KB |
Output is correct |
42 |
Correct |
113 ms |
37228 KB |
Output is correct |
43 |
Correct |
18 ms |
28524 KB |
Output is correct |
44 |
Correct |
117 ms |
41188 KB |
Output is correct |
45 |
Correct |
105 ms |
38252 KB |
Output is correct |
46 |
Correct |
20 ms |
28800 KB |
Output is correct |
47 |
Correct |
20 ms |
28780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
34276 KB |
Output is correct |
2 |
Correct |
81 ms |
37092 KB |
Output is correct |
3 |
Correct |
20 ms |
28780 KB |
Output is correct |
4 |
Correct |
20 ms |
28780 KB |
Output is correct |
5 |
Correct |
18 ms |
28524 KB |
Output is correct |
6 |
Correct |
18 ms |
28524 KB |
Output is correct |
7 |
Correct |
19 ms |
28780 KB |
Output is correct |
8 |
Correct |
102 ms |
35308 KB |
Output is correct |
9 |
Correct |
19 ms |
28780 KB |
Output is correct |
10 |
Correct |
94 ms |
35820 KB |
Output is correct |
11 |
Correct |
18 ms |
28524 KB |
Output is correct |
12 |
Correct |
107 ms |
35820 KB |
Output is correct |
13 |
Correct |
117 ms |
37100 KB |
Output is correct |
14 |
Correct |
99 ms |
38676 KB |
Output is correct |
15 |
Correct |
70 ms |
35576 KB |
Output is correct |
16 |
Correct |
20 ms |
28908 KB |
Output is correct |
17 |
Correct |
18 ms |
28524 KB |
Output is correct |
18 |
Correct |
87 ms |
38628 KB |
Output is correct |
19 |
Correct |
115 ms |
41708 KB |
Output is correct |
20 |
Correct |
20 ms |
28780 KB |
Output is correct |
21 |
Correct |
18 ms |
28524 KB |
Output is correct |
22 |
Correct |
81 ms |
37220 KB |
Output is correct |
23 |
Correct |
20 ms |
28780 KB |
Output is correct |
24 |
Correct |
111 ms |
36204 KB |
Output is correct |
25 |
Correct |
115 ms |
40668 KB |
Output is correct |
26 |
Correct |
21 ms |
28908 KB |
Output is correct |
27 |
Correct |
20 ms |
28908 KB |
Output is correct |
28 |
Correct |
20 ms |
28780 KB |
Output is correct |
29 |
Correct |
20 ms |
28772 KB |
Output is correct |
30 |
Correct |
20 ms |
28780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
28524 KB |
Output is correct |
2 |
Correct |
18 ms |
28652 KB |
Output is correct |
3 |
Correct |
18 ms |
28524 KB |
Output is correct |
4 |
Correct |
18 ms |
28524 KB |
Output is correct |
5 |
Correct |
18 ms |
28524 KB |
Output is correct |
6 |
Correct |
18 ms |
28524 KB |
Output is correct |
7 |
Correct |
18 ms |
28524 KB |
Output is correct |
8 |
Correct |
18 ms |
28524 KB |
Output is correct |
9 |
Correct |
18 ms |
28524 KB |
Output is correct |
10 |
Correct |
20 ms |
28652 KB |
Output is correct |
11 |
Correct |
18 ms |
28524 KB |
Output is correct |
12 |
Correct |
18 ms |
28544 KB |
Output is correct |
13 |
Correct |
18 ms |
28524 KB |
Output is correct |
14 |
Correct |
18 ms |
28524 KB |
Output is correct |
15 |
Correct |
18 ms |
28544 KB |
Output is correct |
16 |
Correct |
18 ms |
28524 KB |
Output is correct |
17 |
Correct |
18 ms |
28524 KB |
Output is correct |
18 |
Correct |
19 ms |
28524 KB |
Output is correct |
19 |
Correct |
18 ms |
28524 KB |
Output is correct |
20 |
Correct |
18 ms |
28524 KB |
Output is correct |
21 |
Correct |
18 ms |
28536 KB |
Output is correct |
22 |
Correct |
18 ms |
28524 KB |
Output is correct |
23 |
Correct |
18 ms |
28524 KB |
Output is correct |
24 |
Correct |
18 ms |
28524 KB |
Output is correct |
25 |
Correct |
18 ms |
28524 KB |
Output is correct |
26 |
Correct |
19 ms |
28780 KB |
Output is correct |
27 |
Correct |
20 ms |
28800 KB |
Output is correct |
28 |
Correct |
20 ms |
28908 KB |
Output is correct |
29 |
Correct |
20 ms |
28780 KB |
Output is correct |
30 |
Correct |
19 ms |
28780 KB |
Output is correct |
31 |
Correct |
18 ms |
28524 KB |
Output is correct |
32 |
Correct |
20 ms |
28908 KB |
Output is correct |
33 |
Correct |
18 ms |
28524 KB |
Output is correct |
34 |
Correct |
19 ms |
28780 KB |
Output is correct |
35 |
Correct |
20 ms |
28780 KB |
Output is correct |
36 |
Correct |
20 ms |
28780 KB |
Output is correct |
37 |
Correct |
20 ms |
28780 KB |
Output is correct |
38 |
Correct |
18 ms |
28524 KB |
Output is correct |
39 |
Correct |
20 ms |
28780 KB |
Output is correct |
40 |
Correct |
20 ms |
28780 KB |
Output is correct |
41 |
Correct |
20 ms |
28780 KB |
Output is correct |
42 |
Correct |
21 ms |
28908 KB |
Output is correct |
43 |
Correct |
20 ms |
28908 KB |
Output is correct |
44 |
Correct |
18 ms |
28524 KB |
Output is correct |
45 |
Correct |
21 ms |
28908 KB |
Output is correct |
46 |
Correct |
20 ms |
28780 KB |
Output is correct |
47 |
Correct |
18 ms |
28524 KB |
Output is correct |
48 |
Correct |
20 ms |
28780 KB |
Output is correct |
49 |
Correct |
23 ms |
29088 KB |
Output is correct |
50 |
Correct |
20 ms |
29036 KB |
Output is correct |
51 |
Correct |
21 ms |
28780 KB |
Output is correct |
52 |
Correct |
19 ms |
28780 KB |
Output is correct |
53 |
Correct |
20 ms |
28780 KB |
Output is correct |
54 |
Correct |
20 ms |
28780 KB |
Output is correct |
55 |
Correct |
20 ms |
28524 KB |
Output is correct |
56 |
Correct |
66 ms |
34148 KB |
Output is correct |
57 |
Correct |
92 ms |
33900 KB |
Output is correct |
58 |
Correct |
19 ms |
28780 KB |
Output is correct |
59 |
Correct |
18 ms |
28524 KB |
Output is correct |
60 |
Correct |
18 ms |
28524 KB |
Output is correct |
61 |
Correct |
85 ms |
34028 KB |
Output is correct |
62 |
Correct |
20 ms |
28800 KB |
Output is correct |
63 |
Correct |
118 ms |
39532 KB |
Output is correct |
64 |
Correct |
88 ms |
33900 KB |
Output is correct |
65 |
Correct |
19 ms |
28780 KB |
Output is correct |
66 |
Correct |
101 ms |
35948 KB |
Output is correct |
67 |
Correct |
20 ms |
28780 KB |
Output is correct |
68 |
Correct |
20 ms |
28780 KB |
Output is correct |
69 |
Correct |
72 ms |
35556 KB |
Output is correct |
70 |
Correct |
20 ms |
28908 KB |
Output is correct |
71 |
Correct |
94 ms |
35172 KB |
Output is correct |
72 |
Correct |
113 ms |
37228 KB |
Output is correct |
73 |
Correct |
18 ms |
28524 KB |
Output is correct |
74 |
Correct |
117 ms |
41188 KB |
Output is correct |
75 |
Correct |
105 ms |
38252 KB |
Output is correct |
76 |
Correct |
20 ms |
28800 KB |
Output is correct |
77 |
Correct |
20 ms |
28780 KB |
Output is correct |
78 |
Correct |
67 ms |
34276 KB |
Output is correct |
79 |
Correct |
81 ms |
37092 KB |
Output is correct |
80 |
Correct |
20 ms |
28780 KB |
Output is correct |
81 |
Correct |
20 ms |
28780 KB |
Output is correct |
82 |
Correct |
18 ms |
28524 KB |
Output is correct |
83 |
Correct |
18 ms |
28524 KB |
Output is correct |
84 |
Correct |
19 ms |
28780 KB |
Output is correct |
85 |
Correct |
102 ms |
35308 KB |
Output is correct |
86 |
Correct |
19 ms |
28780 KB |
Output is correct |
87 |
Correct |
94 ms |
35820 KB |
Output is correct |
88 |
Correct |
18 ms |
28524 KB |
Output is correct |
89 |
Correct |
107 ms |
35820 KB |
Output is correct |
90 |
Correct |
117 ms |
37100 KB |
Output is correct |
91 |
Correct |
99 ms |
38676 KB |
Output is correct |
92 |
Correct |
70 ms |
35576 KB |
Output is correct |
93 |
Correct |
20 ms |
28908 KB |
Output is correct |
94 |
Correct |
18 ms |
28524 KB |
Output is correct |
95 |
Correct |
87 ms |
38628 KB |
Output is correct |
96 |
Correct |
115 ms |
41708 KB |
Output is correct |
97 |
Correct |
20 ms |
28780 KB |
Output is correct |
98 |
Correct |
18 ms |
28524 KB |
Output is correct |
99 |
Correct |
81 ms |
37220 KB |
Output is correct |
100 |
Correct |
20 ms |
28780 KB |
Output is correct |
101 |
Correct |
111 ms |
36204 KB |
Output is correct |
102 |
Correct |
115 ms |
40668 KB |
Output is correct |
103 |
Correct |
21 ms |
28908 KB |
Output is correct |
104 |
Correct |
20 ms |
28908 KB |
Output is correct |
105 |
Correct |
20 ms |
28780 KB |
Output is correct |
106 |
Correct |
20 ms |
28772 KB |
Output is correct |
107 |
Correct |
20 ms |
28780 KB |
Output is correct |
108 |
Correct |
516 ms |
72284 KB |
Output is correct |
109 |
Correct |
699 ms |
76676 KB |
Output is correct |
110 |
Correct |
735 ms |
85724 KB |
Output is correct |
111 |
Correct |
810 ms |
98540 KB |
Output is correct |
112 |
Correct |
799 ms |
90860 KB |
Output is correct |
113 |
Correct |
514 ms |
80084 KB |
Output is correct |
114 |
Correct |
581 ms |
62472 KB |
Output is correct |
115 |
Correct |
578 ms |
62560 KB |
Output is correct |
116 |
Correct |
696 ms |
68716 KB |
Output is correct |
117 |
Correct |
716 ms |
80236 KB |
Output is correct |
118 |
Correct |
611 ms |
65132 KB |
Output is correct |
119 |
Correct |
721 ms |
80364 KB |
Output is correct |
120 |
Correct |
752 ms |
91372 KB |
Output is correct |
121 |
Correct |
730 ms |
80264 KB |
Output is correct |
122 |
Correct |
765 ms |
73836 KB |
Output is correct |
123 |
Correct |
513 ms |
81756 KB |
Output is correct |
124 |
Correct |
794 ms |
78828 KB |
Output is correct |