#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define sp << ' ' <<
#define nl << '\n'
const int LIM = 2e5;
int N, M, s[LIM], e[LIM];
vector<int> g[LIM], h[LIM];
int find(int u) {
return e[u] < 0 ? u : e[u] = find(e[u]);
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> N >> M;
array<int, 2> byS[N];
for(int i = 0; i < N; ++i) {
cin >> s[i];
e[i] = -1;
h[i] = {i};
byS[i] = {s[i], i};
}
for(int i = 0; i < M; ++i) {
int u, v; cin >> u >> v;
--u, --v;
if(make_pair(s[u], u) < make_pair(s[v], v)) swap(u, v);
g[u].push_back(v);
}
sort(byS, byS + N);
for(auto [_, r] : byS) {
int u = find(r);
for(int &v : g[r]) {
v = find(v);
if(s[v] < s[u]) h[v].clear();
if(size(h[v]) > size(h[u]))
h[u].swap(h[v]);
}
for(int &v : g[r]) if((v = find(v)) != u) {
for(int y : h[v]) h[u].push_back(y);
s[u] += s[v];
e[v] = u;
}
}
for(int u : h[find(0)])
s[u] = -1;
for(int i = 0; i < N; ++i)
cout << (s[i] < 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
6 |
Correct |
7 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
6 ms |
9940 KB |
Output is correct |
12 |
Correct |
6 ms |
9940 KB |
Output is correct |
13 |
Correct |
6 ms |
9976 KB |
Output is correct |
14 |
Correct |
6 ms |
9932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
128 ms |
29264 KB |
Output is correct |
4 |
Correct |
129 ms |
31780 KB |
Output is correct |
5 |
Correct |
141 ms |
31332 KB |
Output is correct |
6 |
Correct |
153 ms |
32152 KB |
Output is correct |
7 |
Correct |
144 ms |
32444 KB |
Output is correct |
8 |
Correct |
142 ms |
30640 KB |
Output is correct |
9 |
Correct |
141 ms |
33700 KB |
Output is correct |
10 |
Correct |
108 ms |
24392 KB |
Output is correct |
11 |
Correct |
158 ms |
30684 KB |
Output is correct |
12 |
Correct |
146 ms |
30408 KB |
Output is correct |
13 |
Correct |
143 ms |
33472 KB |
Output is correct |
14 |
Correct |
144 ms |
33296 KB |
Output is correct |
15 |
Correct |
128 ms |
30648 KB |
Output is correct |
16 |
Correct |
83 ms |
30436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
182 ms |
33572 KB |
Output is correct |
3 |
Correct |
219 ms |
33848 KB |
Output is correct |
4 |
Correct |
160 ms |
33456 KB |
Output is correct |
5 |
Correct |
120 ms |
32900 KB |
Output is correct |
6 |
Correct |
184 ms |
33704 KB |
Output is correct |
7 |
Correct |
190 ms |
30652 KB |
Output is correct |
8 |
Correct |
139 ms |
30604 KB |
Output is correct |
9 |
Correct |
87 ms |
30452 KB |
Output is correct |
10 |
Correct |
130 ms |
27936 KB |
Output is correct |
11 |
Correct |
153 ms |
29736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
235 ms |
29492 KB |
Output is correct |
3 |
Correct |
186 ms |
30224 KB |
Output is correct |
4 |
Correct |
209 ms |
32456 KB |
Output is correct |
5 |
Correct |
197 ms |
34044 KB |
Output is correct |
6 |
Correct |
150 ms |
30448 KB |
Output is correct |
7 |
Correct |
126 ms |
28544 KB |
Output is correct |
8 |
Correct |
111 ms |
32432 KB |
Output is correct |
9 |
Correct |
101 ms |
20784 KB |
Output is correct |
10 |
Correct |
156 ms |
35516 KB |
Output is correct |
11 |
Correct |
180 ms |
29612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
6 |
Correct |
7 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
6 ms |
9940 KB |
Output is correct |
12 |
Correct |
6 ms |
9940 KB |
Output is correct |
13 |
Correct |
6 ms |
9976 KB |
Output is correct |
14 |
Correct |
6 ms |
9932 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
128 ms |
29264 KB |
Output is correct |
18 |
Correct |
129 ms |
31780 KB |
Output is correct |
19 |
Correct |
141 ms |
31332 KB |
Output is correct |
20 |
Correct |
153 ms |
32152 KB |
Output is correct |
21 |
Correct |
144 ms |
32444 KB |
Output is correct |
22 |
Correct |
142 ms |
30640 KB |
Output is correct |
23 |
Correct |
141 ms |
33700 KB |
Output is correct |
24 |
Correct |
108 ms |
24392 KB |
Output is correct |
25 |
Correct |
158 ms |
30684 KB |
Output is correct |
26 |
Correct |
146 ms |
30408 KB |
Output is correct |
27 |
Correct |
143 ms |
33472 KB |
Output is correct |
28 |
Correct |
144 ms |
33296 KB |
Output is correct |
29 |
Correct |
128 ms |
30648 KB |
Output is correct |
30 |
Correct |
83 ms |
30436 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
182 ms |
33572 KB |
Output is correct |
33 |
Correct |
219 ms |
33848 KB |
Output is correct |
34 |
Correct |
160 ms |
33456 KB |
Output is correct |
35 |
Correct |
120 ms |
32900 KB |
Output is correct |
36 |
Correct |
184 ms |
33704 KB |
Output is correct |
37 |
Correct |
190 ms |
30652 KB |
Output is correct |
38 |
Correct |
139 ms |
30604 KB |
Output is correct |
39 |
Correct |
87 ms |
30452 KB |
Output is correct |
40 |
Correct |
130 ms |
27936 KB |
Output is correct |
41 |
Correct |
153 ms |
29736 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
235 ms |
29492 KB |
Output is correct |
44 |
Correct |
186 ms |
30224 KB |
Output is correct |
45 |
Correct |
209 ms |
32456 KB |
Output is correct |
46 |
Correct |
197 ms |
34044 KB |
Output is correct |
47 |
Correct |
150 ms |
30448 KB |
Output is correct |
48 |
Correct |
126 ms |
28544 KB |
Output is correct |
49 |
Correct |
111 ms |
32432 KB |
Output is correct |
50 |
Correct |
101 ms |
20784 KB |
Output is correct |
51 |
Correct |
156 ms |
35516 KB |
Output is correct |
52 |
Correct |
180 ms |
29612 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9684 KB |
Output is correct |
55 |
Correct |
5 ms |
9684 KB |
Output is correct |
56 |
Correct |
6 ms |
9812 KB |
Output is correct |
57 |
Correct |
6 ms |
9940 KB |
Output is correct |
58 |
Correct |
6 ms |
9812 KB |
Output is correct |
59 |
Correct |
7 ms |
9876 KB |
Output is correct |
60 |
Correct |
6 ms |
9848 KB |
Output is correct |
61 |
Correct |
6 ms |
9940 KB |
Output is correct |
62 |
Correct |
7 ms |
9972 KB |
Output is correct |
63 |
Correct |
8 ms |
9856 KB |
Output is correct |
64 |
Correct |
6 ms |
9940 KB |
Output is correct |
65 |
Correct |
6 ms |
9940 KB |
Output is correct |
66 |
Correct |
6 ms |
9880 KB |
Output is correct |
67 |
Correct |
140 ms |
29188 KB |
Output is correct |
68 |
Correct |
130 ms |
31736 KB |
Output is correct |
69 |
Correct |
142 ms |
31376 KB |
Output is correct |
70 |
Correct |
168 ms |
32164 KB |
Output is correct |
71 |
Correct |
136 ms |
32264 KB |
Output is correct |
72 |
Correct |
172 ms |
30632 KB |
Output is correct |
73 |
Correct |
136 ms |
33608 KB |
Output is correct |
74 |
Correct |
81 ms |
24400 KB |
Output is correct |
75 |
Correct |
150 ms |
30596 KB |
Output is correct |
76 |
Correct |
173 ms |
30376 KB |
Output is correct |
77 |
Correct |
125 ms |
33516 KB |
Output is correct |
78 |
Correct |
126 ms |
33328 KB |
Output is correct |
79 |
Correct |
121 ms |
30672 KB |
Output is correct |
80 |
Correct |
104 ms |
30504 KB |
Output is correct |
81 |
Correct |
193 ms |
33500 KB |
Output is correct |
82 |
Correct |
178 ms |
33788 KB |
Output is correct |
83 |
Correct |
165 ms |
33520 KB |
Output is correct |
84 |
Correct |
141 ms |
32884 KB |
Output is correct |
85 |
Correct |
195 ms |
33636 KB |
Output is correct |
86 |
Correct |
147 ms |
30612 KB |
Output is correct |
87 |
Correct |
149 ms |
30656 KB |
Output is correct |
88 |
Correct |
128 ms |
27972 KB |
Output is correct |
89 |
Correct |
157 ms |
29692 KB |
Output is correct |
90 |
Correct |
188 ms |
29520 KB |
Output is correct |
91 |
Correct |
220 ms |
30320 KB |
Output is correct |
92 |
Correct |
196 ms |
32344 KB |
Output is correct |
93 |
Correct |
192 ms |
34076 KB |
Output is correct |
94 |
Correct |
169 ms |
30484 KB |
Output is correct |
95 |
Correct |
124 ms |
28576 KB |
Output is correct |
96 |
Correct |
92 ms |
32380 KB |
Output is correct |
97 |
Correct |
100 ms |
20852 KB |
Output is correct |
98 |
Correct |
150 ms |
35528 KB |
Output is correct |
99 |
Correct |
166 ms |
29504 KB |
Output is correct |
100 |
Correct |
40 ms |
12736 KB |
Output is correct |
101 |
Correct |
196 ms |
30680 KB |
Output is correct |
102 |
Correct |
140 ms |
26420 KB |
Output is correct |
103 |
Correct |
165 ms |
25668 KB |
Output is correct |
104 |
Correct |
216 ms |
28724 KB |
Output is correct |