#include <bits/stdc++.h>
using namespace std;
struct DSU {
vector<int> par;
int n;
DSU(int _n) {
n = _n;
par.resize(n);
for(int i = 0; i < n; i++) par[i] = i;
}
int find_par(int u) {
if(u == par[u]) return par[u];
return par[u] = find_par(par[u]);
}
bool check(int u, int v) { return find_par(u) == find_par(v); }
void join(int u, int v) {
u = find_par(u);
v = find_par(v);
par[v] = u;
}
};
const int N = 2e5 + 10;
int n, m;
int a[N];
vector<int> g[N];
int order[N];
set<int> can[N];
bool done[N];
long long sz[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
iota(order + 1, order + n + 1, 1);
sort(order + 1, order + n + 1, [&](int i, int j) { return a[i] < a[j]; });
DSU dsu(n + 1);
for(int i = 1; i <= n; i++) {
can[i].insert(i);
sz[i] = a[i];
}
for(int i = 1; i <= n; i++) {
int u = order[i];
for(int v : g[u]) {
if(!done[v]) continue;
if(dsu.check(u, v)) continue;
int U = dsu.find_par(u);
int V = dsu.find_par(v);
if(sz[V] < a[u]) {
can[V].clear();
dsu.join(u, v);
sz[U] += sz[V];
} else {
if(can[U].size() < can[V].size()) swap(U, V);
dsu.join(U, V);
sz[U] += sz[V];
for(auto it = can[V].begin(); it != can[V].end(); it++) can[U].insert(*it);
}
}
done[u] = true;
}
int comp = dsu.find_par(1);
for(int i = 1; i <= n; i++) {
if(can[comp].find(i) == can[comp].end()) cout << 0;
else cout << 1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
9 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
12 ms |
14568 KB |
Output is correct |
5 |
Correct |
10 ms |
14696 KB |
Output is correct |
6 |
Correct |
10 ms |
14676 KB |
Output is correct |
7 |
Correct |
9 ms |
14568 KB |
Output is correct |
8 |
Correct |
10 ms |
14548 KB |
Output is correct |
9 |
Correct |
10 ms |
14656 KB |
Output is correct |
10 |
Correct |
9 ms |
14724 KB |
Output is correct |
11 |
Correct |
10 ms |
14728 KB |
Output is correct |
12 |
Correct |
9 ms |
14676 KB |
Output is correct |
13 |
Correct |
9 ms |
14804 KB |
Output is correct |
14 |
Correct |
9 ms |
14696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14408 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
189 ms |
40824 KB |
Output is correct |
4 |
Correct |
273 ms |
70232 KB |
Output is correct |
5 |
Correct |
278 ms |
49808 KB |
Output is correct |
6 |
Correct |
317 ms |
52188 KB |
Output is correct |
7 |
Correct |
334 ms |
51696 KB |
Output is correct |
8 |
Correct |
352 ms |
55596 KB |
Output is correct |
9 |
Correct |
241 ms |
59988 KB |
Output is correct |
10 |
Correct |
158 ms |
35692 KB |
Output is correct |
11 |
Correct |
295 ms |
44892 KB |
Output is correct |
12 |
Correct |
267 ms |
46696 KB |
Output is correct |
13 |
Correct |
274 ms |
72484 KB |
Output is correct |
14 |
Correct |
288 ms |
70464 KB |
Output is correct |
15 |
Correct |
216 ms |
44052 KB |
Output is correct |
16 |
Correct |
153 ms |
43852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14548 KB |
Output is correct |
2 |
Correct |
339 ms |
59300 KB |
Output is correct |
3 |
Correct |
393 ms |
58896 KB |
Output is correct |
4 |
Correct |
327 ms |
73520 KB |
Output is correct |
5 |
Correct |
267 ms |
73104 KB |
Output is correct |
6 |
Correct |
354 ms |
58184 KB |
Output is correct |
7 |
Correct |
259 ms |
44080 KB |
Output is correct |
8 |
Correct |
259 ms |
44112 KB |
Output is correct |
9 |
Correct |
175 ms |
43808 KB |
Output is correct |
10 |
Correct |
240 ms |
48828 KB |
Output is correct |
11 |
Correct |
301 ms |
61388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
364 ms |
44924 KB |
Output is correct |
3 |
Correct |
364 ms |
52360 KB |
Output is correct |
4 |
Correct |
375 ms |
59504 KB |
Output is correct |
5 |
Correct |
461 ms |
73440 KB |
Output is correct |
6 |
Correct |
438 ms |
59208 KB |
Output is correct |
7 |
Correct |
310 ms |
48932 KB |
Output is correct |
8 |
Correct |
199 ms |
55544 KB |
Output is correct |
9 |
Correct |
177 ms |
31060 KB |
Output is correct |
10 |
Correct |
451 ms |
77864 KB |
Output is correct |
11 |
Correct |
357 ms |
64980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
9 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
12 ms |
14568 KB |
Output is correct |
5 |
Correct |
10 ms |
14696 KB |
Output is correct |
6 |
Correct |
10 ms |
14676 KB |
Output is correct |
7 |
Correct |
9 ms |
14568 KB |
Output is correct |
8 |
Correct |
10 ms |
14548 KB |
Output is correct |
9 |
Correct |
10 ms |
14656 KB |
Output is correct |
10 |
Correct |
9 ms |
14724 KB |
Output is correct |
11 |
Correct |
10 ms |
14728 KB |
Output is correct |
12 |
Correct |
9 ms |
14676 KB |
Output is correct |
13 |
Correct |
9 ms |
14804 KB |
Output is correct |
14 |
Correct |
9 ms |
14696 KB |
Output is correct |
15 |
Correct |
8 ms |
14408 KB |
Output is correct |
16 |
Correct |
8 ms |
14420 KB |
Output is correct |
17 |
Correct |
189 ms |
40824 KB |
Output is correct |
18 |
Correct |
273 ms |
70232 KB |
Output is correct |
19 |
Correct |
278 ms |
49808 KB |
Output is correct |
20 |
Correct |
317 ms |
52188 KB |
Output is correct |
21 |
Correct |
334 ms |
51696 KB |
Output is correct |
22 |
Correct |
352 ms |
55596 KB |
Output is correct |
23 |
Correct |
241 ms |
59988 KB |
Output is correct |
24 |
Correct |
158 ms |
35692 KB |
Output is correct |
25 |
Correct |
295 ms |
44892 KB |
Output is correct |
26 |
Correct |
267 ms |
46696 KB |
Output is correct |
27 |
Correct |
274 ms |
72484 KB |
Output is correct |
28 |
Correct |
288 ms |
70464 KB |
Output is correct |
29 |
Correct |
216 ms |
44052 KB |
Output is correct |
30 |
Correct |
153 ms |
43852 KB |
Output is correct |
31 |
Correct |
8 ms |
14548 KB |
Output is correct |
32 |
Correct |
339 ms |
59300 KB |
Output is correct |
33 |
Correct |
393 ms |
58896 KB |
Output is correct |
34 |
Correct |
327 ms |
73520 KB |
Output is correct |
35 |
Correct |
267 ms |
73104 KB |
Output is correct |
36 |
Correct |
354 ms |
58184 KB |
Output is correct |
37 |
Correct |
259 ms |
44080 KB |
Output is correct |
38 |
Correct |
259 ms |
44112 KB |
Output is correct |
39 |
Correct |
175 ms |
43808 KB |
Output is correct |
40 |
Correct |
240 ms |
48828 KB |
Output is correct |
41 |
Correct |
301 ms |
61388 KB |
Output is correct |
42 |
Correct |
8 ms |
14420 KB |
Output is correct |
43 |
Correct |
364 ms |
44924 KB |
Output is correct |
44 |
Correct |
364 ms |
52360 KB |
Output is correct |
45 |
Correct |
375 ms |
59504 KB |
Output is correct |
46 |
Correct |
461 ms |
73440 KB |
Output is correct |
47 |
Correct |
438 ms |
59208 KB |
Output is correct |
48 |
Correct |
310 ms |
48932 KB |
Output is correct |
49 |
Correct |
199 ms |
55544 KB |
Output is correct |
50 |
Correct |
177 ms |
31060 KB |
Output is correct |
51 |
Correct |
451 ms |
77864 KB |
Output is correct |
52 |
Correct |
357 ms |
64980 KB |
Output is correct |
53 |
Correct |
9 ms |
14428 KB |
Output is correct |
54 |
Correct |
10 ms |
14420 KB |
Output is correct |
55 |
Correct |
9 ms |
14424 KB |
Output is correct |
56 |
Correct |
10 ms |
14592 KB |
Output is correct |
57 |
Correct |
13 ms |
14680 KB |
Output is correct |
58 |
Correct |
10 ms |
14664 KB |
Output is correct |
59 |
Correct |
10 ms |
14608 KB |
Output is correct |
60 |
Correct |
9 ms |
14548 KB |
Output is correct |
61 |
Correct |
11 ms |
14676 KB |
Output is correct |
62 |
Correct |
14 ms |
14692 KB |
Output is correct |
63 |
Correct |
11 ms |
14736 KB |
Output is correct |
64 |
Correct |
10 ms |
14696 KB |
Output is correct |
65 |
Correct |
10 ms |
14820 KB |
Output is correct |
66 |
Correct |
10 ms |
14676 KB |
Output is correct |
67 |
Correct |
221 ms |
44608 KB |
Output is correct |
68 |
Correct |
309 ms |
72984 KB |
Output is correct |
69 |
Correct |
311 ms |
53732 KB |
Output is correct |
70 |
Correct |
359 ms |
56096 KB |
Output is correct |
71 |
Correct |
341 ms |
55572 KB |
Output is correct |
72 |
Correct |
429 ms |
59492 KB |
Output is correct |
73 |
Correct |
301 ms |
63940 KB |
Output is correct |
74 |
Correct |
185 ms |
38820 KB |
Output is correct |
75 |
Correct |
313 ms |
47928 KB |
Output is correct |
76 |
Correct |
308 ms |
49252 KB |
Output is correct |
77 |
Correct |
283 ms |
74984 KB |
Output is correct |
78 |
Correct |
303 ms |
73192 KB |
Output is correct |
79 |
Correct |
233 ms |
48124 KB |
Output is correct |
80 |
Correct |
171 ms |
47240 KB |
Output is correct |
81 |
Correct |
390 ms |
62932 KB |
Output is correct |
82 |
Correct |
372 ms |
62844 KB |
Output is correct |
83 |
Correct |
325 ms |
77620 KB |
Output is correct |
84 |
Correct |
321 ms |
75588 KB |
Output is correct |
85 |
Correct |
407 ms |
62252 KB |
Output is correct |
86 |
Correct |
257 ms |
48324 KB |
Output is correct |
87 |
Correct |
249 ms |
48216 KB |
Output is correct |
88 |
Correct |
258 ms |
52292 KB |
Output is correct |
89 |
Correct |
313 ms |
63980 KB |
Output is correct |
90 |
Correct |
455 ms |
48716 KB |
Output is correct |
91 |
Correct |
377 ms |
52264 KB |
Output is correct |
92 |
Correct |
419 ms |
59432 KB |
Output is correct |
93 |
Correct |
495 ms |
73384 KB |
Output is correct |
94 |
Correct |
436 ms |
59352 KB |
Output is correct |
95 |
Correct |
310 ms |
48900 KB |
Output is correct |
96 |
Correct |
198 ms |
55464 KB |
Output is correct |
97 |
Correct |
160 ms |
31096 KB |
Output is correct |
98 |
Correct |
486 ms |
77892 KB |
Output is correct |
99 |
Correct |
326 ms |
65080 KB |
Output is correct |
100 |
Correct |
51 ms |
18764 KB |
Output is correct |
101 |
Correct |
412 ms |
53124 KB |
Output is correct |
102 |
Correct |
275 ms |
46864 KB |
Output is correct |
103 |
Correct |
289 ms |
39328 KB |
Output is correct |
104 |
Correct |
406 ms |
45416 KB |
Output is correct |