#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
const int MX_N = 2e5 + 42;
int par[MX_N];
int sum[MX_N];
int guys[MX_N];
bool isOk[MX_N];
vector<int> graph[MX_N];
vector<int> dsuTree[MX_N];
int find(int node) {
if (par[node] < 0)
return node;
return par[node] = find(par[node]);
}
void unite(int u, int v) {
//cout << "edge " << u + 1 << ' ' << v + 1 << '\n';
u = find(u);
v = find(v);
if (u == v)
return;
//cout << " compo is " << u + 1 << '\n';
if (sum[u] < guys[v]) {
//cout << "nok\n";
isOk[u] = false;
}
par[v] += par[u];
par[u] = v;
sum[v] += sum[u];
dsuTree[v].push_back(u);
}
void upd(int node, bool fuck) {
//cout << "ucr is " << node << '\n';
fuck &= isOk[node];
for (auto& x: dsuTree[node])
upd(x, fuck);
isOk[node] = fuck;
}
signed main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> nodes {};
for (int i = 0; i < n; i++) {
cin >> guys[i];
nodes.push_back({guys[i], i});
par[i] = -1;
sum[i] = guys[i];
isOk[i] = true;
}
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
graph[u].push_back(v);
graph[v].push_back(u);
}
sort(nodes.begin(), nodes.end());
for (int i = 0; i < n; i++)
for (auto& x: graph[nodes[i].se])
if (make_pair(guys[x], x) < nodes[i])
unite(x, nodes[i].se);
upd(nodes.back().se, true);
/*for (int i = 0; i < n; i++) {
for (auto& x: dsuTree[i]) {
cout << "dsu edge " << i + 1 << " to " << x + 1 << '\n';
}
}*/
for (int i = 0; i < n; i++)
cout << isOk[i];
cout << '\n';
}
# |
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 |
5 ms |
9716 KB |
Output is correct |
4 |
Correct |
7 ms |
9912 KB |
Output is correct |
5 |
Correct |
8 ms |
9808 KB |
Output is correct |
6 |
Correct |
7 ms |
9848 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
9 ms |
9812 KB |
Output is correct |
9 |
Correct |
6 ms |
9940 KB |
Output is correct |
10 |
Correct |
8 ms |
9812 KB |
Output is correct |
11 |
Correct |
7 ms |
9812 KB |
Output is correct |
12 |
Correct |
7 ms |
9812 KB |
Output is correct |
13 |
Correct |
7 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9812 KB |
Output is correct |
3 |
Correct |
280 ms |
31588 KB |
Output is correct |
4 |
Correct |
245 ms |
36216 KB |
Output is correct |
5 |
Correct |
305 ms |
28680 KB |
Output is correct |
6 |
Correct |
297 ms |
29216 KB |
Output is correct |
7 |
Correct |
343 ms |
29348 KB |
Output is correct |
8 |
Correct |
304 ms |
36868 KB |
Output is correct |
9 |
Correct |
304 ms |
28908 KB |
Output is correct |
10 |
Correct |
243 ms |
29388 KB |
Output is correct |
11 |
Correct |
264 ms |
37468 KB |
Output is correct |
12 |
Correct |
340 ms |
31408 KB |
Output is correct |
13 |
Correct |
238 ms |
35936 KB |
Output is correct |
14 |
Correct |
258 ms |
35372 KB |
Output is correct |
15 |
Correct |
276 ms |
35872 KB |
Output is correct |
16 |
Correct |
224 ms |
35612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
333 ms |
28132 KB |
Output is correct |
3 |
Correct |
303 ms |
28372 KB |
Output is correct |
4 |
Correct |
321 ms |
36108 KB |
Output is correct |
5 |
Correct |
228 ms |
34212 KB |
Output is correct |
6 |
Correct |
342 ms |
28340 KB |
Output is correct |
7 |
Correct |
291 ms |
36016 KB |
Output is correct |
8 |
Correct |
293 ms |
35936 KB |
Output is correct |
9 |
Correct |
219 ms |
35644 KB |
Output is correct |
10 |
Correct |
250 ms |
30080 KB |
Output is correct |
11 |
Correct |
257 ms |
29304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
347 ms |
29536 KB |
Output is correct |
3 |
Correct |
337 ms |
29388 KB |
Output is correct |
4 |
Correct |
358 ms |
29480 KB |
Output is correct |
5 |
Correct |
325 ms |
29488 KB |
Output is correct |
6 |
Correct |
306 ms |
29300 KB |
Output is correct |
7 |
Correct |
259 ms |
33000 KB |
Output is correct |
8 |
Correct |
216 ms |
37808 KB |
Output is correct |
9 |
Correct |
233 ms |
22284 KB |
Output is correct |
10 |
Correct |
254 ms |
29364 KB |
Output is correct |
11 |
Correct |
255 ms |
29384 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 |
5 ms |
9716 KB |
Output is correct |
4 |
Correct |
7 ms |
9912 KB |
Output is correct |
5 |
Correct |
8 ms |
9808 KB |
Output is correct |
6 |
Correct |
7 ms |
9848 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
9 ms |
9812 KB |
Output is correct |
9 |
Correct |
6 ms |
9940 KB |
Output is correct |
10 |
Correct |
8 ms |
9812 KB |
Output is correct |
11 |
Correct |
7 ms |
9812 KB |
Output is correct |
12 |
Correct |
7 ms |
9812 KB |
Output is correct |
13 |
Correct |
7 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
6 ms |
9812 KB |
Output is correct |
17 |
Correct |
280 ms |
31588 KB |
Output is correct |
18 |
Correct |
245 ms |
36216 KB |
Output is correct |
19 |
Correct |
305 ms |
28680 KB |
Output is correct |
20 |
Correct |
297 ms |
29216 KB |
Output is correct |
21 |
Correct |
343 ms |
29348 KB |
Output is correct |
22 |
Correct |
304 ms |
36868 KB |
Output is correct |
23 |
Correct |
304 ms |
28908 KB |
Output is correct |
24 |
Correct |
243 ms |
29388 KB |
Output is correct |
25 |
Correct |
264 ms |
37468 KB |
Output is correct |
26 |
Correct |
340 ms |
31408 KB |
Output is correct |
27 |
Correct |
238 ms |
35936 KB |
Output is correct |
28 |
Correct |
258 ms |
35372 KB |
Output is correct |
29 |
Correct |
276 ms |
35872 KB |
Output is correct |
30 |
Correct |
224 ms |
35612 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
333 ms |
28132 KB |
Output is correct |
33 |
Correct |
303 ms |
28372 KB |
Output is correct |
34 |
Correct |
321 ms |
36108 KB |
Output is correct |
35 |
Correct |
228 ms |
34212 KB |
Output is correct |
36 |
Correct |
342 ms |
28340 KB |
Output is correct |
37 |
Correct |
291 ms |
36016 KB |
Output is correct |
38 |
Correct |
293 ms |
35936 KB |
Output is correct |
39 |
Correct |
219 ms |
35644 KB |
Output is correct |
40 |
Correct |
250 ms |
30080 KB |
Output is correct |
41 |
Correct |
257 ms |
29304 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
347 ms |
29536 KB |
Output is correct |
44 |
Correct |
337 ms |
29388 KB |
Output is correct |
45 |
Correct |
358 ms |
29480 KB |
Output is correct |
46 |
Correct |
325 ms |
29488 KB |
Output is correct |
47 |
Correct |
306 ms |
29300 KB |
Output is correct |
48 |
Correct |
259 ms |
33000 KB |
Output is correct |
49 |
Correct |
216 ms |
37808 KB |
Output is correct |
50 |
Correct |
233 ms |
22284 KB |
Output is correct |
51 |
Correct |
254 ms |
29364 KB |
Output is correct |
52 |
Correct |
255 ms |
29384 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9684 KB |
Output is correct |
55 |
Correct |
6 ms |
9684 KB |
Output is correct |
56 |
Correct |
7 ms |
9812 KB |
Output is correct |
57 |
Correct |
8 ms |
9984 KB |
Output is correct |
58 |
Correct |
7 ms |
9840 KB |
Output is correct |
59 |
Correct |
7 ms |
9860 KB |
Output is correct |
60 |
Correct |
7 ms |
9812 KB |
Output is correct |
61 |
Correct |
7 ms |
9940 KB |
Output is correct |
62 |
Correct |
7 ms |
9812 KB |
Output is correct |
63 |
Correct |
7 ms |
9812 KB |
Output is correct |
64 |
Correct |
7 ms |
9812 KB |
Output is correct |
65 |
Correct |
6 ms |
9940 KB |
Output is correct |
66 |
Correct |
7 ms |
9812 KB |
Output is correct |
67 |
Correct |
300 ms |
31584 KB |
Output is correct |
68 |
Correct |
231 ms |
36208 KB |
Output is correct |
69 |
Correct |
296 ms |
28720 KB |
Output is correct |
70 |
Correct |
322 ms |
29288 KB |
Output is correct |
71 |
Correct |
293 ms |
29300 KB |
Output is correct |
72 |
Correct |
320 ms |
36900 KB |
Output is correct |
73 |
Correct |
277 ms |
28908 KB |
Output is correct |
74 |
Correct |
224 ms |
29336 KB |
Output is correct |
75 |
Correct |
264 ms |
37552 KB |
Output is correct |
76 |
Correct |
298 ms |
31372 KB |
Output is correct |
77 |
Correct |
227 ms |
35928 KB |
Output is correct |
78 |
Correct |
239 ms |
35412 KB |
Output is correct |
79 |
Correct |
276 ms |
35884 KB |
Output is correct |
80 |
Correct |
219 ms |
35640 KB |
Output is correct |
81 |
Correct |
351 ms |
28188 KB |
Output is correct |
82 |
Correct |
335 ms |
28288 KB |
Output is correct |
83 |
Correct |
306 ms |
35968 KB |
Output is correct |
84 |
Correct |
234 ms |
34204 KB |
Output is correct |
85 |
Correct |
347 ms |
28344 KB |
Output is correct |
86 |
Correct |
336 ms |
35936 KB |
Output is correct |
87 |
Correct |
288 ms |
36016 KB |
Output is correct |
88 |
Correct |
248 ms |
30084 KB |
Output is correct |
89 |
Correct |
297 ms |
29356 KB |
Output is correct |
90 |
Correct |
340 ms |
29544 KB |
Output is correct |
91 |
Correct |
329 ms |
29232 KB |
Output is correct |
92 |
Correct |
345 ms |
29268 KB |
Output is correct |
93 |
Correct |
374 ms |
29372 KB |
Output is correct |
94 |
Correct |
290 ms |
29232 KB |
Output is correct |
95 |
Correct |
245 ms |
32948 KB |
Output is correct |
96 |
Correct |
204 ms |
37484 KB |
Output is correct |
97 |
Correct |
227 ms |
22280 KB |
Output is correct |
98 |
Correct |
264 ms |
29336 KB |
Output is correct |
99 |
Correct |
264 ms |
29412 KB |
Output is correct |
100 |
Correct |
104 ms |
14496 KB |
Output is correct |
101 |
Correct |
345 ms |
29428 KB |
Output is correct |
102 |
Correct |
297 ms |
27552 KB |
Output is correct |
103 |
Correct |
319 ms |
28356 KB |
Output is correct |
104 |
Correct |
348 ms |
29716 KB |
Output is correct |