#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
ll cnt[N], p[N], c[N];
set<ll> s[N];
vector<ll> adj[N], g[N];
ll get(ll a) {return p[a] = (p[a] == a ? a : get(p[a]));}
ll val[N];
void uni(ll a, ll b, ll vb) {
a = get(a), b = get(b);
if(a == b) return;
if(cnt[a] < vb) {
val[a] = 0;
}
p[a] = b;
cnt[b] += cnt[a];
g[b].push_back(a);
}
int ans[N];
void dfs(int u, int cur) {
cur &= val[u];
ans[u] = cur;
for(int v: g[u]) {
dfs(v, cur);
}
}
int main() {
int n, m; cin >> n >> m;
vector<pair<ll, ll>> paiu;
for(int i = 0; i < n; ++i) {
cin >> c[i];
paiu.push_back({c[i], i});
}
for(int i = 0; i < n; ++i) {
val[i] = 1;
p[i] = i;
cnt[i] = c[i];
s[i].insert(i);
}
sort(paiu.begin(), paiu.end());
vector<bool> vis(n, false);
for(int i = 0; i < m; ++i) {
int u, v; cin >> u >> v; --u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 0; i < n; ++i) {
ll u = paiu[i].second;
for(int v: adj[u]) {
if(!vis[v]) continue;
uni(v, u, c[u]);
}
vis[u] = true;
}
dfs(paiu[n - 1].second, 1);
for(int i = 0; i < n; ++i) cout << ans[i];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
13 ms |
19028 KB |
Output is correct |
3 |
Correct |
10 ms |
19028 KB |
Output is correct |
4 |
Correct |
13 ms |
19284 KB |
Output is correct |
5 |
Correct |
12 ms |
19408 KB |
Output is correct |
6 |
Correct |
12 ms |
19292 KB |
Output is correct |
7 |
Correct |
13 ms |
19348 KB |
Output is correct |
8 |
Correct |
12 ms |
19284 KB |
Output is correct |
9 |
Correct |
12 ms |
19412 KB |
Output is correct |
10 |
Correct |
13 ms |
19412 KB |
Output is correct |
11 |
Correct |
13 ms |
19424 KB |
Output is correct |
12 |
Correct |
13 ms |
19412 KB |
Output is correct |
13 |
Correct |
12 ms |
19488 KB |
Output is correct |
14 |
Correct |
15 ms |
19344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
16 ms |
19076 KB |
Output is correct |
3 |
Correct |
319 ms |
52144 KB |
Output is correct |
4 |
Correct |
296 ms |
56236 KB |
Output is correct |
5 |
Correct |
335 ms |
50852 KB |
Output is correct |
6 |
Correct |
456 ms |
52120 KB |
Output is correct |
7 |
Correct |
372 ms |
52996 KB |
Output is correct |
8 |
Correct |
363 ms |
59500 KB |
Output is correct |
9 |
Correct |
301 ms |
52276 KB |
Output is correct |
10 |
Correct |
271 ms |
53404 KB |
Output is correct |
11 |
Correct |
284 ms |
60272 KB |
Output is correct |
12 |
Correct |
311 ms |
54224 KB |
Output is correct |
13 |
Correct |
256 ms |
57132 KB |
Output is correct |
14 |
Correct |
252 ms |
57896 KB |
Output is correct |
15 |
Correct |
295 ms |
59444 KB |
Output is correct |
16 |
Correct |
222 ms |
58188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
19028 KB |
Output is correct |
2 |
Correct |
371 ms |
49048 KB |
Output is correct |
3 |
Correct |
360 ms |
49200 KB |
Output is correct |
4 |
Correct |
320 ms |
55904 KB |
Output is correct |
5 |
Correct |
276 ms |
57132 KB |
Output is correct |
6 |
Correct |
363 ms |
52536 KB |
Output is correct |
7 |
Correct |
323 ms |
59244 KB |
Output is correct |
8 |
Correct |
354 ms |
59164 KB |
Output is correct |
9 |
Correct |
240 ms |
58036 KB |
Output is correct |
10 |
Correct |
293 ms |
52200 KB |
Output is correct |
11 |
Correct |
268 ms |
53040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
374 ms |
50388 KB |
Output is correct |
3 |
Correct |
373 ms |
53384 KB |
Output is correct |
4 |
Correct |
366 ms |
51660 KB |
Output is correct |
5 |
Correct |
367 ms |
54696 KB |
Output is correct |
6 |
Correct |
337 ms |
52528 KB |
Output is correct |
7 |
Correct |
267 ms |
55012 KB |
Output is correct |
8 |
Correct |
240 ms |
60664 KB |
Output is correct |
9 |
Correct |
207 ms |
39048 KB |
Output is correct |
10 |
Correct |
318 ms |
51732 KB |
Output is correct |
11 |
Correct |
286 ms |
51600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
13 ms |
19028 KB |
Output is correct |
3 |
Correct |
10 ms |
19028 KB |
Output is correct |
4 |
Correct |
13 ms |
19284 KB |
Output is correct |
5 |
Correct |
12 ms |
19408 KB |
Output is correct |
6 |
Correct |
12 ms |
19292 KB |
Output is correct |
7 |
Correct |
13 ms |
19348 KB |
Output is correct |
8 |
Correct |
12 ms |
19284 KB |
Output is correct |
9 |
Correct |
12 ms |
19412 KB |
Output is correct |
10 |
Correct |
13 ms |
19412 KB |
Output is correct |
11 |
Correct |
13 ms |
19424 KB |
Output is correct |
12 |
Correct |
13 ms |
19412 KB |
Output is correct |
13 |
Correct |
12 ms |
19488 KB |
Output is correct |
14 |
Correct |
15 ms |
19344 KB |
Output is correct |
15 |
Correct |
10 ms |
19028 KB |
Output is correct |
16 |
Correct |
16 ms |
19076 KB |
Output is correct |
17 |
Correct |
319 ms |
52144 KB |
Output is correct |
18 |
Correct |
296 ms |
56236 KB |
Output is correct |
19 |
Correct |
335 ms |
50852 KB |
Output is correct |
20 |
Correct |
456 ms |
52120 KB |
Output is correct |
21 |
Correct |
372 ms |
52996 KB |
Output is correct |
22 |
Correct |
363 ms |
59500 KB |
Output is correct |
23 |
Correct |
301 ms |
52276 KB |
Output is correct |
24 |
Correct |
271 ms |
53404 KB |
Output is correct |
25 |
Correct |
284 ms |
60272 KB |
Output is correct |
26 |
Correct |
311 ms |
54224 KB |
Output is correct |
27 |
Correct |
256 ms |
57132 KB |
Output is correct |
28 |
Correct |
252 ms |
57896 KB |
Output is correct |
29 |
Correct |
295 ms |
59444 KB |
Output is correct |
30 |
Correct |
222 ms |
58188 KB |
Output is correct |
31 |
Correct |
11 ms |
19028 KB |
Output is correct |
32 |
Correct |
371 ms |
49048 KB |
Output is correct |
33 |
Correct |
360 ms |
49200 KB |
Output is correct |
34 |
Correct |
320 ms |
55904 KB |
Output is correct |
35 |
Correct |
276 ms |
57132 KB |
Output is correct |
36 |
Correct |
363 ms |
52536 KB |
Output is correct |
37 |
Correct |
323 ms |
59244 KB |
Output is correct |
38 |
Correct |
354 ms |
59164 KB |
Output is correct |
39 |
Correct |
240 ms |
58036 KB |
Output is correct |
40 |
Correct |
293 ms |
52200 KB |
Output is correct |
41 |
Correct |
268 ms |
53040 KB |
Output is correct |
42 |
Correct |
10 ms |
19028 KB |
Output is correct |
43 |
Correct |
374 ms |
50388 KB |
Output is correct |
44 |
Correct |
373 ms |
53384 KB |
Output is correct |
45 |
Correct |
366 ms |
51660 KB |
Output is correct |
46 |
Correct |
367 ms |
54696 KB |
Output is correct |
47 |
Correct |
337 ms |
52528 KB |
Output is correct |
48 |
Correct |
267 ms |
55012 KB |
Output is correct |
49 |
Correct |
240 ms |
60664 KB |
Output is correct |
50 |
Correct |
207 ms |
39048 KB |
Output is correct |
51 |
Correct |
318 ms |
51732 KB |
Output is correct |
52 |
Correct |
286 ms |
51600 KB |
Output is correct |
53 |
Correct |
10 ms |
19028 KB |
Output is correct |
54 |
Correct |
11 ms |
19012 KB |
Output is correct |
55 |
Correct |
10 ms |
19108 KB |
Output is correct |
56 |
Correct |
13 ms |
19404 KB |
Output is correct |
57 |
Correct |
13 ms |
19412 KB |
Output is correct |
58 |
Correct |
12 ms |
19300 KB |
Output is correct |
59 |
Correct |
12 ms |
19328 KB |
Output is correct |
60 |
Correct |
12 ms |
19284 KB |
Output is correct |
61 |
Correct |
13 ms |
19436 KB |
Output is correct |
62 |
Correct |
14 ms |
19412 KB |
Output is correct |
63 |
Correct |
13 ms |
19360 KB |
Output is correct |
64 |
Correct |
15 ms |
19432 KB |
Output is correct |
65 |
Correct |
12 ms |
19412 KB |
Output is correct |
66 |
Correct |
12 ms |
19364 KB |
Output is correct |
67 |
Correct |
317 ms |
55016 KB |
Output is correct |
68 |
Correct |
304 ms |
58380 KB |
Output is correct |
69 |
Correct |
331 ms |
50184 KB |
Output is correct |
70 |
Correct |
370 ms |
52300 KB |
Output is correct |
71 |
Correct |
337 ms |
51652 KB |
Output is correct |
72 |
Correct |
350 ms |
59188 KB |
Output is correct |
73 |
Correct |
291 ms |
52344 KB |
Output is correct |
74 |
Correct |
250 ms |
51564 KB |
Output is correct |
75 |
Correct |
271 ms |
58924 KB |
Output is correct |
76 |
Correct |
313 ms |
53824 KB |
Output is correct |
77 |
Correct |
259 ms |
57072 KB |
Output is correct |
78 |
Correct |
247 ms |
56696 KB |
Output is correct |
79 |
Correct |
315 ms |
58240 KB |
Output is correct |
80 |
Correct |
219 ms |
59052 KB |
Output is correct |
81 |
Correct |
355 ms |
51432 KB |
Output is correct |
82 |
Correct |
378 ms |
52232 KB |
Output is correct |
83 |
Correct |
330 ms |
55996 KB |
Output is correct |
84 |
Correct |
292 ms |
56904 KB |
Output is correct |
85 |
Correct |
374 ms |
53724 KB |
Output is correct |
86 |
Correct |
300 ms |
60264 KB |
Output is correct |
87 |
Correct |
347 ms |
60136 KB |
Output is correct |
88 |
Correct |
346 ms |
51436 KB |
Output is correct |
89 |
Correct |
326 ms |
50348 KB |
Output is correct |
90 |
Correct |
393 ms |
52876 KB |
Output is correct |
91 |
Correct |
442 ms |
54568 KB |
Output is correct |
92 |
Correct |
377 ms |
54788 KB |
Output is correct |
93 |
Correct |
434 ms |
53792 KB |
Output is correct |
94 |
Correct |
346 ms |
52680 KB |
Output is correct |
95 |
Correct |
342 ms |
56804 KB |
Output is correct |
96 |
Correct |
253 ms |
60268 KB |
Output is correct |
97 |
Correct |
218 ms |
39300 KB |
Output is correct |
98 |
Correct |
318 ms |
53232 KB |
Output is correct |
99 |
Correct |
286 ms |
52956 KB |
Output is correct |
100 |
Correct |
118 ms |
25856 KB |
Output is correct |
101 |
Correct |
396 ms |
54632 KB |
Output is correct |
102 |
Correct |
404 ms |
48416 KB |
Output is correct |
103 |
Correct |
427 ms |
47104 KB |
Output is correct |
104 |
Correct |
388 ms |
50800 KB |
Output is correct |