#include <bits/stdc++.h>
#define int long long
using namespace std;
struct Node {
int id, nbHab;
};
const int N = 2e5 + 42, MOD = 1e9 + 7;
bool ans[N];
Node node[N];
set<int> win[N];
vector<int> adj[N];
int n, m, par[N], sum[N];
int F(int i) {
if(par[i] == i)
return i;
return par[i] = F(par[i]);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) {
node[i].id = i;
cin >> node[i].nbHab;
par[i] = i;
win[i].insert(i);
sum[i] = node[i].nbHab;
}
for(int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
a--, b--;
if(a > b) swap(a, b);
if(node[a].nbHab > node[b].nbHab) swap(a, b);
adj[b].push_back(a);
}
sort(node, node + n,
[](Node a, Node b) {
if(a.nbHab == b.nbHab)
return a.id < b.id;
return a.nbHab < b.nbHab;
});
for(int i = 0; i < n; i++) {
int act = node[i].id;
for(int j : adj[act]) {
j = F(j);
if(j != act) {
if(sum[j] >= node[i].nbHab) {
if(win[j].size() > win[act].size())
swap(win[j], win[act]);
for(int id : win[j])
win[act].insert(id);
}
par[j] = act;
sum[act] += sum[j];
}
}
}
for(int i : win[F(node[n-1].id)])
ans[i] = true;
for(int i = 0; i < n; i++)
cout << ans[i];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
9 ms |
14436 KB |
Output is correct |
3 |
Correct |
9 ms |
14420 KB |
Output is correct |
4 |
Correct |
9 ms |
14676 KB |
Output is correct |
5 |
Correct |
9 ms |
14764 KB |
Output is correct |
6 |
Correct |
9 ms |
14676 KB |
Output is correct |
7 |
Correct |
8 ms |
14676 KB |
Output is correct |
8 |
Correct |
8 ms |
14548 KB |
Output is correct |
9 |
Correct |
9 ms |
14776 KB |
Output is correct |
10 |
Correct |
9 ms |
14828 KB |
Output is correct |
11 |
Correct |
9 ms |
14804 KB |
Output is correct |
12 |
Correct |
8 ms |
14804 KB |
Output is correct |
13 |
Correct |
8 ms |
14704 KB |
Output is correct |
14 |
Correct |
8 ms |
14696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14320 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
165 ms |
43548 KB |
Output is correct |
4 |
Correct |
198 ms |
48684 KB |
Output is correct |
5 |
Correct |
231 ms |
55456 KB |
Output is correct |
6 |
Correct |
245 ms |
58516 KB |
Output is correct |
7 |
Correct |
282 ms |
58592 KB |
Output is correct |
8 |
Correct |
206 ms |
48716 KB |
Output is correct |
9 |
Correct |
227 ms |
66476 KB |
Output is correct |
10 |
Correct |
132 ms |
35120 KB |
Output is correct |
11 |
Correct |
198 ms |
48936 KB |
Output is correct |
12 |
Correct |
221 ms |
46520 KB |
Output is correct |
13 |
Correct |
167 ms |
49800 KB |
Output is correct |
14 |
Correct |
167 ms |
50688 KB |
Output is correct |
15 |
Correct |
188 ms |
49724 KB |
Output is correct |
16 |
Correct |
165 ms |
48536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
299 ms |
63140 KB |
Output is correct |
3 |
Correct |
302 ms |
65608 KB |
Output is correct |
4 |
Correct |
221 ms |
50256 KB |
Output is correct |
5 |
Correct |
172 ms |
49408 KB |
Output is correct |
6 |
Correct |
309 ms |
65868 KB |
Output is correct |
7 |
Correct |
241 ms |
49496 KB |
Output is correct |
8 |
Correct |
204 ms |
49396 KB |
Output is correct |
9 |
Correct |
144 ms |
47676 KB |
Output is correct |
10 |
Correct |
155 ms |
41176 KB |
Output is correct |
11 |
Correct |
177 ms |
48972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14444 KB |
Output is correct |
2 |
Correct |
317 ms |
49012 KB |
Output is correct |
3 |
Correct |
320 ms |
55156 KB |
Output is correct |
4 |
Correct |
360 ms |
60776 KB |
Output is correct |
5 |
Correct |
422 ms |
73896 KB |
Output is correct |
6 |
Correct |
324 ms |
58564 KB |
Output is correct |
7 |
Correct |
249 ms |
45656 KB |
Output is correct |
8 |
Correct |
127 ms |
50536 KB |
Output is correct |
9 |
Correct |
141 ms |
33096 KB |
Output is correct |
10 |
Correct |
427 ms |
76240 KB |
Output is correct |
11 |
Correct |
183 ms |
47588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
9 ms |
14436 KB |
Output is correct |
3 |
Correct |
9 ms |
14420 KB |
Output is correct |
4 |
Correct |
9 ms |
14676 KB |
Output is correct |
5 |
Correct |
9 ms |
14764 KB |
Output is correct |
6 |
Correct |
9 ms |
14676 KB |
Output is correct |
7 |
Correct |
8 ms |
14676 KB |
Output is correct |
8 |
Correct |
8 ms |
14548 KB |
Output is correct |
9 |
Correct |
9 ms |
14776 KB |
Output is correct |
10 |
Correct |
9 ms |
14828 KB |
Output is correct |
11 |
Correct |
9 ms |
14804 KB |
Output is correct |
12 |
Correct |
8 ms |
14804 KB |
Output is correct |
13 |
Correct |
8 ms |
14704 KB |
Output is correct |
14 |
Correct |
8 ms |
14696 KB |
Output is correct |
15 |
Correct |
8 ms |
14320 KB |
Output is correct |
16 |
Correct |
7 ms |
14420 KB |
Output is correct |
17 |
Correct |
165 ms |
43548 KB |
Output is correct |
18 |
Correct |
198 ms |
48684 KB |
Output is correct |
19 |
Correct |
231 ms |
55456 KB |
Output is correct |
20 |
Correct |
245 ms |
58516 KB |
Output is correct |
21 |
Correct |
282 ms |
58592 KB |
Output is correct |
22 |
Correct |
206 ms |
48716 KB |
Output is correct |
23 |
Correct |
227 ms |
66476 KB |
Output is correct |
24 |
Correct |
132 ms |
35120 KB |
Output is correct |
25 |
Correct |
198 ms |
48936 KB |
Output is correct |
26 |
Correct |
221 ms |
46520 KB |
Output is correct |
27 |
Correct |
167 ms |
49800 KB |
Output is correct |
28 |
Correct |
167 ms |
50688 KB |
Output is correct |
29 |
Correct |
188 ms |
49724 KB |
Output is correct |
30 |
Correct |
165 ms |
48536 KB |
Output is correct |
31 |
Correct |
9 ms |
14420 KB |
Output is correct |
32 |
Correct |
299 ms |
63140 KB |
Output is correct |
33 |
Correct |
302 ms |
65608 KB |
Output is correct |
34 |
Correct |
221 ms |
50256 KB |
Output is correct |
35 |
Correct |
172 ms |
49408 KB |
Output is correct |
36 |
Correct |
309 ms |
65868 KB |
Output is correct |
37 |
Correct |
241 ms |
49496 KB |
Output is correct |
38 |
Correct |
204 ms |
49396 KB |
Output is correct |
39 |
Correct |
144 ms |
47676 KB |
Output is correct |
40 |
Correct |
155 ms |
41176 KB |
Output is correct |
41 |
Correct |
177 ms |
48972 KB |
Output is correct |
42 |
Correct |
7 ms |
14444 KB |
Output is correct |
43 |
Correct |
317 ms |
49012 KB |
Output is correct |
44 |
Correct |
320 ms |
55156 KB |
Output is correct |
45 |
Correct |
360 ms |
60776 KB |
Output is correct |
46 |
Correct |
422 ms |
73896 KB |
Output is correct |
47 |
Correct |
324 ms |
58564 KB |
Output is correct |
48 |
Correct |
249 ms |
45656 KB |
Output is correct |
49 |
Correct |
127 ms |
50536 KB |
Output is correct |
50 |
Correct |
141 ms |
33096 KB |
Output is correct |
51 |
Correct |
427 ms |
76240 KB |
Output is correct |
52 |
Correct |
183 ms |
47588 KB |
Output is correct |
53 |
Correct |
7 ms |
14356 KB |
Output is correct |
54 |
Correct |
7 ms |
14420 KB |
Output is correct |
55 |
Correct |
7 ms |
14428 KB |
Output is correct |
56 |
Correct |
10 ms |
14700 KB |
Output is correct |
57 |
Correct |
13 ms |
14772 KB |
Output is correct |
58 |
Correct |
9 ms |
14696 KB |
Output is correct |
59 |
Correct |
11 ms |
14604 KB |
Output is correct |
60 |
Correct |
11 ms |
14568 KB |
Output is correct |
61 |
Correct |
9 ms |
14692 KB |
Output is correct |
62 |
Correct |
9 ms |
14824 KB |
Output is correct |
63 |
Correct |
11 ms |
14756 KB |
Output is correct |
64 |
Correct |
8 ms |
14804 KB |
Output is correct |
65 |
Correct |
9 ms |
14676 KB |
Output is correct |
66 |
Correct |
8 ms |
14776 KB |
Output is correct |
67 |
Correct |
161 ms |
46488 KB |
Output is correct |
68 |
Correct |
174 ms |
49080 KB |
Output is correct |
69 |
Correct |
248 ms |
54892 KB |
Output is correct |
70 |
Correct |
266 ms |
58660 KB |
Output is correct |
71 |
Correct |
275 ms |
57208 KB |
Output is correct |
72 |
Correct |
203 ms |
48428 KB |
Output is correct |
73 |
Correct |
221 ms |
66504 KB |
Output is correct |
74 |
Correct |
117 ms |
33224 KB |
Output is correct |
75 |
Correct |
199 ms |
47568 KB |
Output is correct |
76 |
Correct |
230 ms |
45992 KB |
Output is correct |
77 |
Correct |
185 ms |
49796 KB |
Output is correct |
78 |
Correct |
164 ms |
49512 KB |
Output is correct |
79 |
Correct |
185 ms |
48468 KB |
Output is correct |
80 |
Correct |
161 ms |
49448 KB |
Output is correct |
81 |
Correct |
296 ms |
65420 KB |
Output is correct |
82 |
Correct |
324 ms |
66036 KB |
Output is correct |
83 |
Correct |
231 ms |
46116 KB |
Output is correct |
84 |
Correct |
171 ms |
49008 KB |
Output is correct |
85 |
Correct |
292 ms |
67088 KB |
Output is correct |
86 |
Correct |
206 ms |
50404 KB |
Output is correct |
87 |
Correct |
236 ms |
50288 KB |
Output is correct |
88 |
Correct |
147 ms |
40544 KB |
Output is correct |
89 |
Correct |
178 ms |
46668 KB |
Output is correct |
90 |
Correct |
341 ms |
51500 KB |
Output is correct |
91 |
Correct |
305 ms |
56696 KB |
Output is correct |
92 |
Correct |
410 ms |
63724 KB |
Output is correct |
93 |
Correct |
408 ms |
73000 KB |
Output is correct |
94 |
Correct |
359 ms |
58652 KB |
Output is correct |
95 |
Correct |
206 ms |
47496 KB |
Output is correct |
96 |
Correct |
132 ms |
50096 KB |
Output is correct |
97 |
Correct |
161 ms |
33500 KB |
Output is correct |
98 |
Correct |
418 ms |
77896 KB |
Output is correct |
99 |
Correct |
208 ms |
49096 KB |
Output is correct |
100 |
Correct |
49 ms |
19308 KB |
Output is correct |
101 |
Correct |
349 ms |
57732 KB |
Output is correct |
102 |
Correct |
256 ms |
46364 KB |
Output is correct |
103 |
Correct |
303 ms |
38960 KB |
Output is correct |
104 |
Correct |
293 ms |
46300 KB |
Output is correct |