#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 200500;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
int s[N];
bool can[N];
struct dsu{
vector<int> p;
vector<long long> sum;
vector<set<int>> children;
dsu(){
p.resize(n);
iota(all(p), 0);
sum.resize(n);
for (int i = 0; i < n; i++) sum[i] = s[i];
children.resize(n);
for (int i = 0; i < n; i++){
children[i].insert(i);
}
}
int leader(int x){
return (x == p[x] ? x : p[x] = leader(p[x]));
}
bool unite(int x, int y){
int px = leader(x);
int py = leader(y);
if (px == py) return false;
if (sum[px] < s[y]){
for (int i : children[px]) can[i] = false;
children[px].clear();
}
if (sum[py] < s[x]){
for (int i : children[py]) can[i] = false;
children[py].clear();
}
x = px, y = py;
if (children[x].size() > children[y].size()) swap(x, y);
for (int i : children[x]) children[y].insert(i);
children[x].clear();
sum[y] += sum[x];
p[x] = y;
return true;
}
};
vector<int> g[N];
void solve(){
int m;
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> s[i];
}
vector<pair<int, int>> edges;
while (m--){
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
if (s[u] > s[v]) swap(u, v);
edges.emplace_back(u, v);
}
sort(all(edges), [](auto x, auto y){
return s[x.second] < s[y.second];
});
fill(can, can + n, true);
dsu d;
for (auto [u, v] : edges){
d.unite(u, v);
}
for (int i = 0; i < n; i++){
cout << can[i];
}
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5204 KB |
Output is correct |
5 |
Correct |
5 ms |
5332 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
4 ms |
5332 KB |
Output is correct |
10 |
Correct |
4 ms |
5332 KB |
Output is correct |
11 |
Correct |
6 ms |
5332 KB |
Output is correct |
12 |
Correct |
4 ms |
5264 KB |
Output is correct |
13 |
Correct |
5 ms |
5332 KB |
Output is correct |
14 |
Correct |
5 ms |
5332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
190 ms |
35068 KB |
Output is correct |
4 |
Correct |
484 ms |
38992 KB |
Output is correct |
5 |
Correct |
336 ms |
34232 KB |
Output is correct |
6 |
Correct |
419 ms |
35192 KB |
Output is correct |
7 |
Correct |
350 ms |
35344 KB |
Output is correct |
8 |
Correct |
503 ms |
37620 KB |
Output is correct |
9 |
Correct |
242 ms |
35296 KB |
Output is correct |
10 |
Correct |
181 ms |
35968 KB |
Output is correct |
11 |
Correct |
292 ms |
35968 KB |
Output is correct |
12 |
Correct |
296 ms |
35312 KB |
Output is correct |
13 |
Correct |
439 ms |
38780 KB |
Output is correct |
14 |
Correct |
439 ms |
38196 KB |
Output is correct |
15 |
Correct |
211 ms |
35240 KB |
Output is correct |
16 |
Correct |
138 ms |
34820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
354 ms |
34924 KB |
Output is correct |
3 |
Correct |
349 ms |
35316 KB |
Output is correct |
4 |
Correct |
477 ms |
37896 KB |
Output is correct |
5 |
Correct |
455 ms |
37944 KB |
Output is correct |
6 |
Correct |
366 ms |
35384 KB |
Output is correct |
7 |
Correct |
196 ms |
35256 KB |
Output is correct |
8 |
Correct |
202 ms |
35420 KB |
Output is correct |
9 |
Correct |
138 ms |
35032 KB |
Output is correct |
10 |
Correct |
362 ms |
35256 KB |
Output is correct |
11 |
Correct |
425 ms |
35132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
356 ms |
34996 KB |
Output is correct |
3 |
Correct |
371 ms |
35180 KB |
Output is correct |
4 |
Correct |
425 ms |
35308 KB |
Output is correct |
5 |
Correct |
512 ms |
36024 KB |
Output is correct |
6 |
Correct |
419 ms |
34224 KB |
Output is correct |
7 |
Correct |
334 ms |
36040 KB |
Output is correct |
8 |
Correct |
173 ms |
36504 KB |
Output is correct |
9 |
Correct |
151 ms |
21868 KB |
Output is correct |
10 |
Correct |
516 ms |
36796 KB |
Output is correct |
11 |
Correct |
347 ms |
35080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5204 KB |
Output is correct |
5 |
Correct |
5 ms |
5332 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
4 ms |
5332 KB |
Output is correct |
10 |
Correct |
4 ms |
5332 KB |
Output is correct |
11 |
Correct |
6 ms |
5332 KB |
Output is correct |
12 |
Correct |
4 ms |
5264 KB |
Output is correct |
13 |
Correct |
5 ms |
5332 KB |
Output is correct |
14 |
Correct |
5 ms |
5332 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
190 ms |
35068 KB |
Output is correct |
18 |
Correct |
484 ms |
38992 KB |
Output is correct |
19 |
Correct |
336 ms |
34232 KB |
Output is correct |
20 |
Correct |
419 ms |
35192 KB |
Output is correct |
21 |
Correct |
350 ms |
35344 KB |
Output is correct |
22 |
Correct |
503 ms |
37620 KB |
Output is correct |
23 |
Correct |
242 ms |
35296 KB |
Output is correct |
24 |
Correct |
181 ms |
35968 KB |
Output is correct |
25 |
Correct |
292 ms |
35968 KB |
Output is correct |
26 |
Correct |
296 ms |
35312 KB |
Output is correct |
27 |
Correct |
439 ms |
38780 KB |
Output is correct |
28 |
Correct |
439 ms |
38196 KB |
Output is correct |
29 |
Correct |
211 ms |
35240 KB |
Output is correct |
30 |
Correct |
138 ms |
34820 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
354 ms |
34924 KB |
Output is correct |
33 |
Correct |
349 ms |
35316 KB |
Output is correct |
34 |
Correct |
477 ms |
37896 KB |
Output is correct |
35 |
Correct |
455 ms |
37944 KB |
Output is correct |
36 |
Correct |
366 ms |
35384 KB |
Output is correct |
37 |
Correct |
196 ms |
35256 KB |
Output is correct |
38 |
Correct |
202 ms |
35420 KB |
Output is correct |
39 |
Correct |
138 ms |
35032 KB |
Output is correct |
40 |
Correct |
362 ms |
35256 KB |
Output is correct |
41 |
Correct |
425 ms |
35132 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
356 ms |
34996 KB |
Output is correct |
44 |
Correct |
371 ms |
35180 KB |
Output is correct |
45 |
Correct |
425 ms |
35308 KB |
Output is correct |
46 |
Correct |
512 ms |
36024 KB |
Output is correct |
47 |
Correct |
419 ms |
34224 KB |
Output is correct |
48 |
Correct |
334 ms |
36040 KB |
Output is correct |
49 |
Correct |
173 ms |
36504 KB |
Output is correct |
50 |
Correct |
151 ms |
21868 KB |
Output is correct |
51 |
Correct |
516 ms |
36796 KB |
Output is correct |
52 |
Correct |
347 ms |
35080 KB |
Output is correct |
53 |
Correct |
2 ms |
4948 KB |
Output is correct |
54 |
Correct |
3 ms |
4948 KB |
Output is correct |
55 |
Correct |
3 ms |
5076 KB |
Output is correct |
56 |
Correct |
5 ms |
5204 KB |
Output is correct |
57 |
Correct |
5 ms |
5332 KB |
Output is correct |
58 |
Correct |
4 ms |
5204 KB |
Output is correct |
59 |
Correct |
4 ms |
5204 KB |
Output is correct |
60 |
Correct |
4 ms |
5204 KB |
Output is correct |
61 |
Correct |
4 ms |
5332 KB |
Output is correct |
62 |
Correct |
5 ms |
5308 KB |
Output is correct |
63 |
Correct |
4 ms |
5332 KB |
Output is correct |
64 |
Correct |
4 ms |
5332 KB |
Output is correct |
65 |
Correct |
4 ms |
5332 KB |
Output is correct |
66 |
Correct |
6 ms |
5260 KB |
Output is correct |
67 |
Correct |
188 ms |
35164 KB |
Output is correct |
68 |
Correct |
465 ms |
38800 KB |
Output is correct |
69 |
Correct |
286 ms |
34180 KB |
Output is correct |
70 |
Correct |
315 ms |
35088 KB |
Output is correct |
71 |
Correct |
313 ms |
35172 KB |
Output is correct |
72 |
Correct |
510 ms |
37488 KB |
Output is correct |
73 |
Correct |
252 ms |
35156 KB |
Output is correct |
74 |
Correct |
186 ms |
35896 KB |
Output is correct |
75 |
Correct |
313 ms |
35912 KB |
Output is correct |
76 |
Correct |
296 ms |
35196 KB |
Output is correct |
77 |
Correct |
445 ms |
38804 KB |
Output is correct |
78 |
Correct |
416 ms |
38080 KB |
Output is correct |
79 |
Correct |
188 ms |
35100 KB |
Output is correct |
80 |
Correct |
134 ms |
34756 KB |
Output is correct |
81 |
Correct |
312 ms |
35000 KB |
Output is correct |
82 |
Correct |
338 ms |
35100 KB |
Output is correct |
83 |
Correct |
469 ms |
37800 KB |
Output is correct |
84 |
Correct |
456 ms |
37736 KB |
Output is correct |
85 |
Correct |
329 ms |
35100 KB |
Output is correct |
86 |
Correct |
209 ms |
35096 KB |
Output is correct |
87 |
Correct |
210 ms |
35128 KB |
Output is correct |
88 |
Correct |
339 ms |
35236 KB |
Output is correct |
89 |
Correct |
366 ms |
35188 KB |
Output is correct |
90 |
Correct |
333 ms |
35100 KB |
Output is correct |
91 |
Correct |
386 ms |
35044 KB |
Output is correct |
92 |
Correct |
427 ms |
35236 KB |
Output is correct |
93 |
Correct |
442 ms |
35908 KB |
Output is correct |
94 |
Correct |
410 ms |
33976 KB |
Output is correct |
95 |
Correct |
321 ms |
35852 KB |
Output is correct |
96 |
Correct |
179 ms |
36372 KB |
Output is correct |
97 |
Correct |
178 ms |
21936 KB |
Output is correct |
98 |
Correct |
505 ms |
36716 KB |
Output is correct |
99 |
Correct |
389 ms |
35196 KB |
Output is correct |
100 |
Correct |
56 ms |
9160 KB |
Output is correct |
101 |
Correct |
422 ms |
35332 KB |
Output is correct |
102 |
Correct |
324 ms |
29216 KB |
Output is correct |
103 |
Correct |
282 ms |
30656 KB |
Output is correct |
104 |
Correct |
321 ms |
34700 KB |
Output is correct |