#include <bits/stdc++.h>
using namespace std;
struct DSU {
vector<long long> e;
DSU(long long N) { e = vector<long long>(N, -1); }
long long get(long long x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
bool same_set(long long a, long long b) { return get(a) == get(b); }
long long size(long long x) { return -e[get(x)]; }
bool unite(long long x, long long y, vector<long long> &strength) { // union by size
x = get(x), y = get(y);
if (x == y) return false;
if (e[x] > e[y]) swap(x, y);
e[x] += e[y]; e[y] = x;
strength[x] += strength[y];
return true;
}
};
void dfs(long long u, long long works, vector<long long> &winnable, vector<vector<long long> > &val){
winnable[u] &= works;
for(long long v : val[u]){
dfs(v, winnable[u], winnable, val);
}
}
int main(){
long long n, m;
cin >> n >> m;
long long arr[n];
for(long long i = 0; i < n; i++){
cin >> arr[i];
}
vector<long long> adj[n];
for(long long i = 0; i < m; i++){
long long a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
DSU dsu(n);
vector<long long> winnable(n, 1);
vector<bool> visited(n, false);
vector<long long> inserted(n);
vector<long long> comp(n);
vector<long long> strength(n);
vector<vector<long long> > mark(n);
vector<pair<long long, long long> > order(n);
for(long long i = 0; i < n; i++){
strength[i] = arr[i];
order[i] = make_pair(arr[i], i);
}
sort(order.begin(), order.end());
for(auto t : order){
long long u = t.second;
for(long long v : adj[u]){
if(inserted[v]){
long long w = comp[dsu.get(v)];
if(strength[dsu.get(v)] < arr[u]){
winnable[w] = 0;
}
if(!visited[w]){
mark[u].push_back(w);
visited[w] = true;
}
}
}
for(long long v : adj[u]){
if(inserted[v]){
visited[comp[dsu.get(v)]] = false;
}
}
for(long long v : adj[u]){
if(inserted[v]){
dsu.unite(u, v, strength);
}
}
comp[dsu.get(u)] = u;
inserted[u] = 1;
}
dfs(order[n - 1].second, 1, winnable, mark);
for(long long i = 0; i < n; i++){
cout << winnable[i];
}
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
564 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
696 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
285 ms |
42172 KB |
Output is correct |
4 |
Correct |
248 ms |
47240 KB |
Output is correct |
5 |
Correct |
340 ms |
36940 KB |
Output is correct |
6 |
Correct |
379 ms |
38160 KB |
Output is correct |
7 |
Correct |
332 ms |
38220 KB |
Output is correct |
8 |
Correct |
305 ms |
49644 KB |
Output is correct |
9 |
Correct |
288 ms |
37792 KB |
Output is correct |
10 |
Correct |
231 ms |
36664 KB |
Output is correct |
11 |
Correct |
260 ms |
49232 KB |
Output is correct |
12 |
Correct |
283 ms |
39340 KB |
Output is correct |
13 |
Correct |
224 ms |
47268 KB |
Output is correct |
14 |
Correct |
249 ms |
46440 KB |
Output is correct |
15 |
Correct |
279 ms |
48800 KB |
Output is correct |
16 |
Correct |
240 ms |
47620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
329 ms |
32652 KB |
Output is correct |
3 |
Correct |
338 ms |
37312 KB |
Output is correct |
4 |
Correct |
332 ms |
48816 KB |
Output is correct |
5 |
Correct |
266 ms |
44224 KB |
Output is correct |
6 |
Correct |
352 ms |
37292 KB |
Output is correct |
7 |
Correct |
300 ms |
48812 KB |
Output is correct |
8 |
Correct |
326 ms |
48816 KB |
Output is correct |
9 |
Correct |
218 ms |
47500 KB |
Output is correct |
10 |
Correct |
256 ms |
40280 KB |
Output is correct |
11 |
Correct |
256 ms |
37544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
371 ms |
34252 KB |
Output is correct |
3 |
Correct |
346 ms |
38220 KB |
Output is correct |
4 |
Correct |
420 ms |
38360 KB |
Output is correct |
5 |
Correct |
329 ms |
38264 KB |
Output is correct |
6 |
Correct |
317 ms |
37772 KB |
Output is correct |
7 |
Correct |
266 ms |
43916 KB |
Output is correct |
8 |
Correct |
216 ms |
49132 KB |
Output is correct |
9 |
Correct |
222 ms |
22540 KB |
Output is correct |
10 |
Correct |
307 ms |
36764 KB |
Output is correct |
11 |
Correct |
270 ms |
37620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
564 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
696 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
285 ms |
42172 KB |
Output is correct |
18 |
Correct |
248 ms |
47240 KB |
Output is correct |
19 |
Correct |
340 ms |
36940 KB |
Output is correct |
20 |
Correct |
379 ms |
38160 KB |
Output is correct |
21 |
Correct |
332 ms |
38220 KB |
Output is correct |
22 |
Correct |
305 ms |
49644 KB |
Output is correct |
23 |
Correct |
288 ms |
37792 KB |
Output is correct |
24 |
Correct |
231 ms |
36664 KB |
Output is correct |
25 |
Correct |
260 ms |
49232 KB |
Output is correct |
26 |
Correct |
283 ms |
39340 KB |
Output is correct |
27 |
Correct |
224 ms |
47268 KB |
Output is correct |
28 |
Correct |
249 ms |
46440 KB |
Output is correct |
29 |
Correct |
279 ms |
48800 KB |
Output is correct |
30 |
Correct |
240 ms |
47620 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
329 ms |
32652 KB |
Output is correct |
33 |
Correct |
338 ms |
37312 KB |
Output is correct |
34 |
Correct |
332 ms |
48816 KB |
Output is correct |
35 |
Correct |
266 ms |
44224 KB |
Output is correct |
36 |
Correct |
352 ms |
37292 KB |
Output is correct |
37 |
Correct |
300 ms |
48812 KB |
Output is correct |
38 |
Correct |
326 ms |
48816 KB |
Output is correct |
39 |
Correct |
218 ms |
47500 KB |
Output is correct |
40 |
Correct |
256 ms |
40280 KB |
Output is correct |
41 |
Correct |
256 ms |
37544 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
371 ms |
34252 KB |
Output is correct |
44 |
Correct |
346 ms |
38220 KB |
Output is correct |
45 |
Correct |
420 ms |
38360 KB |
Output is correct |
46 |
Correct |
329 ms |
38264 KB |
Output is correct |
47 |
Correct |
317 ms |
37772 KB |
Output is correct |
48 |
Correct |
266 ms |
43916 KB |
Output is correct |
49 |
Correct |
216 ms |
49132 KB |
Output is correct |
50 |
Correct |
222 ms |
22540 KB |
Output is correct |
51 |
Correct |
307 ms |
36764 KB |
Output is correct |
52 |
Correct |
270 ms |
37620 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
3 ms |
596 KB |
Output is correct |
57 |
Correct |
3 ms |
664 KB |
Output is correct |
58 |
Correct |
3 ms |
596 KB |
Output is correct |
59 |
Correct |
3 ms |
596 KB |
Output is correct |
60 |
Correct |
3 ms |
456 KB |
Output is correct |
61 |
Correct |
3 ms |
724 KB |
Output is correct |
62 |
Correct |
3 ms |
596 KB |
Output is correct |
63 |
Correct |
3 ms |
596 KB |
Output is correct |
64 |
Correct |
3 ms |
568 KB |
Output is correct |
65 |
Correct |
2 ms |
724 KB |
Output is correct |
66 |
Correct |
3 ms |
548 KB |
Output is correct |
67 |
Correct |
300 ms |
42160 KB |
Output is correct |
68 |
Correct |
257 ms |
47308 KB |
Output is correct |
69 |
Correct |
333 ms |
36968 KB |
Output is correct |
70 |
Correct |
351 ms |
38060 KB |
Output is correct |
71 |
Correct |
376 ms |
38220 KB |
Output is correct |
72 |
Correct |
334 ms |
49740 KB |
Output is correct |
73 |
Correct |
297 ms |
37788 KB |
Output is correct |
74 |
Correct |
252 ms |
36720 KB |
Output is correct |
75 |
Correct |
243 ms |
49292 KB |
Output is correct |
76 |
Correct |
288 ms |
39340 KB |
Output is correct |
77 |
Correct |
256 ms |
47172 KB |
Output is correct |
78 |
Correct |
250 ms |
46424 KB |
Output is correct |
79 |
Correct |
294 ms |
48688 KB |
Output is correct |
80 |
Correct |
226 ms |
47584 KB |
Output is correct |
81 |
Correct |
353 ms |
37056 KB |
Output is correct |
82 |
Correct |
374 ms |
37236 KB |
Output is correct |
83 |
Correct |
314 ms |
48816 KB |
Output is correct |
84 |
Correct |
263 ms |
44228 KB |
Output is correct |
85 |
Correct |
373 ms |
37280 KB |
Output is correct |
86 |
Correct |
320 ms |
48872 KB |
Output is correct |
87 |
Correct |
319 ms |
48720 KB |
Output is correct |
88 |
Correct |
263 ms |
40228 KB |
Output is correct |
89 |
Correct |
277 ms |
37596 KB |
Output is correct |
90 |
Correct |
385 ms |
38784 KB |
Output is correct |
91 |
Correct |
361 ms |
38176 KB |
Output is correct |
92 |
Correct |
364 ms |
38268 KB |
Output is correct |
93 |
Correct |
387 ms |
38344 KB |
Output is correct |
94 |
Correct |
326 ms |
37804 KB |
Output is correct |
95 |
Correct |
259 ms |
43952 KB |
Output is correct |
96 |
Correct |
214 ms |
49108 KB |
Output is correct |
97 |
Correct |
234 ms |
22556 KB |
Output is correct |
98 |
Correct |
341 ms |
36864 KB |
Output is correct |
99 |
Correct |
283 ms |
37552 KB |
Output is correct |
100 |
Correct |
110 ms |
7244 KB |
Output is correct |
101 |
Correct |
468 ms |
38444 KB |
Output is correct |
102 |
Correct |
328 ms |
34068 KB |
Output is correct |
103 |
Correct |
330 ms |
35604 KB |
Output is correct |
104 |
Correct |
385 ms |
38572 KB |
Output is correct |