#include <bits/stdc++.h>
using namespace std;
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 2e5+10, MOD = 1e9+7;
// keep removing the max node, mark component as bad if it's sum is < value of the node
int n, m;
int s[N], par[N];
ll sum[N];
vector<int> st[N], good[N], adj[N];
bool ans[N];
void mark_bad(int c) {
c = par[c];
for (int x : good[c]) ans[x] = 0;
good[c].clear();
}
void union_sets(int a, int b) {
a = par[a], b = par[b];
if (a == b) return;
if (sz(st[a]) < sz(st[b])) swap(a, b);
for (int x : st[b]) {
par[x] = a;
st[a].push_back(x);
}
st[b].clear();
for (int x : good[b]) {
good[a].push_back(x);
}
good[b].clear();
sum[a] += sum[b], sum[b] = 0;
}
void solve() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b, --a, --b;
adj[a].push_back(b), adj[b].push_back(a);
}
for (int i = 0; i < n; i++) {
par[i] = i; sum[i] = s[i];
st[i].push_back(i);
good[i].push_back(i);
}
vector<int> ord(n); iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int x, int y) { return s[x] < s[y]; });
fill(ans, ans + n, 1);
vector<bool> hit(n);
for (int x : ord) {
for (int nxt : adj[x]) if (hit[nxt]) {
int v = par[nxt];
if (sum[v] < s[x]) {
mark_bad(v);
}
}
for (int nxt : adj[x]) if (hit[nxt]) {
union_sets(x, nxt);
}
hit[x] = 1;
}
for (int i = 0; i < n; i++) cout << ans[i];
cout << '\n';
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14328 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
12 ms |
14648 KB |
Output is correct |
5 |
Correct |
12 ms |
14644 KB |
Output is correct |
6 |
Correct |
9 ms |
14656 KB |
Output is correct |
7 |
Correct |
9 ms |
14672 KB |
Output is correct |
8 |
Correct |
9 ms |
14568 KB |
Output is correct |
9 |
Correct |
10 ms |
14676 KB |
Output is correct |
10 |
Correct |
11 ms |
14676 KB |
Output is correct |
11 |
Correct |
12 ms |
14676 KB |
Output is correct |
12 |
Correct |
9 ms |
14716 KB |
Output is correct |
13 |
Correct |
9 ms |
14676 KB |
Output is correct |
14 |
Correct |
11 ms |
14676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14372 KB |
Output is correct |
3 |
Correct |
194 ms |
39740 KB |
Output is correct |
4 |
Correct |
200 ms |
48344 KB |
Output is correct |
5 |
Correct |
261 ms |
48348 KB |
Output is correct |
6 |
Correct |
266 ms |
49948 KB |
Output is correct |
7 |
Correct |
256 ms |
50344 KB |
Output is correct |
8 |
Correct |
245 ms |
45888 KB |
Output is correct |
9 |
Correct |
262 ms |
53964 KB |
Output is correct |
10 |
Correct |
239 ms |
43128 KB |
Output is correct |
11 |
Correct |
180 ms |
43844 KB |
Output is correct |
12 |
Correct |
292 ms |
45104 KB |
Output is correct |
13 |
Correct |
199 ms |
49460 KB |
Output is correct |
14 |
Correct |
249 ms |
48552 KB |
Output is correct |
15 |
Correct |
192 ms |
43792 KB |
Output is correct |
16 |
Correct |
130 ms |
42768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14420 KB |
Output is correct |
2 |
Correct |
329 ms |
47976 KB |
Output is correct |
3 |
Correct |
337 ms |
52528 KB |
Output is correct |
4 |
Correct |
212 ms |
51404 KB |
Output is correct |
5 |
Correct |
209 ms |
49480 KB |
Output is correct |
6 |
Correct |
303 ms |
52420 KB |
Output is correct |
7 |
Correct |
199 ms |
43744 KB |
Output is correct |
8 |
Correct |
204 ms |
43704 KB |
Output is correct |
9 |
Correct |
113 ms |
42752 KB |
Output is correct |
10 |
Correct |
195 ms |
47512 KB |
Output is correct |
11 |
Correct |
260 ms |
48788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14328 KB |
Output is correct |
2 |
Correct |
329 ms |
41740 KB |
Output is correct |
3 |
Correct |
356 ms |
47484 KB |
Output is correct |
4 |
Correct |
312 ms |
48824 KB |
Output is correct |
5 |
Correct |
279 ms |
49180 KB |
Output is correct |
6 |
Correct |
239 ms |
44996 KB |
Output is correct |
7 |
Correct |
207 ms |
44812 KB |
Output is correct |
8 |
Correct |
148 ms |
45628 KB |
Output is correct |
9 |
Correct |
149 ms |
30988 KB |
Output is correct |
10 |
Correct |
263 ms |
49200 KB |
Output is correct |
11 |
Correct |
240 ms |
49116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14328 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
12 ms |
14648 KB |
Output is correct |
5 |
Correct |
12 ms |
14644 KB |
Output is correct |
6 |
Correct |
9 ms |
14656 KB |
Output is correct |
7 |
Correct |
9 ms |
14672 KB |
Output is correct |
8 |
Correct |
9 ms |
14568 KB |
Output is correct |
9 |
Correct |
10 ms |
14676 KB |
Output is correct |
10 |
Correct |
11 ms |
14676 KB |
Output is correct |
11 |
Correct |
12 ms |
14676 KB |
Output is correct |
12 |
Correct |
9 ms |
14716 KB |
Output is correct |
13 |
Correct |
9 ms |
14676 KB |
Output is correct |
14 |
Correct |
11 ms |
14676 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
8 ms |
14372 KB |
Output is correct |
17 |
Correct |
194 ms |
39740 KB |
Output is correct |
18 |
Correct |
200 ms |
48344 KB |
Output is correct |
19 |
Correct |
261 ms |
48348 KB |
Output is correct |
20 |
Correct |
266 ms |
49948 KB |
Output is correct |
21 |
Correct |
256 ms |
50344 KB |
Output is correct |
22 |
Correct |
245 ms |
45888 KB |
Output is correct |
23 |
Correct |
262 ms |
53964 KB |
Output is correct |
24 |
Correct |
239 ms |
43128 KB |
Output is correct |
25 |
Correct |
180 ms |
43844 KB |
Output is correct |
26 |
Correct |
292 ms |
45104 KB |
Output is correct |
27 |
Correct |
199 ms |
49460 KB |
Output is correct |
28 |
Correct |
249 ms |
48552 KB |
Output is correct |
29 |
Correct |
192 ms |
43792 KB |
Output is correct |
30 |
Correct |
130 ms |
42768 KB |
Output is correct |
31 |
Correct |
11 ms |
14420 KB |
Output is correct |
32 |
Correct |
329 ms |
47976 KB |
Output is correct |
33 |
Correct |
337 ms |
52528 KB |
Output is correct |
34 |
Correct |
212 ms |
51404 KB |
Output is correct |
35 |
Correct |
209 ms |
49480 KB |
Output is correct |
36 |
Correct |
303 ms |
52420 KB |
Output is correct |
37 |
Correct |
199 ms |
43744 KB |
Output is correct |
38 |
Correct |
204 ms |
43704 KB |
Output is correct |
39 |
Correct |
113 ms |
42752 KB |
Output is correct |
40 |
Correct |
195 ms |
47512 KB |
Output is correct |
41 |
Correct |
260 ms |
48788 KB |
Output is correct |
42 |
Correct |
10 ms |
14328 KB |
Output is correct |
43 |
Correct |
329 ms |
41740 KB |
Output is correct |
44 |
Correct |
356 ms |
47484 KB |
Output is correct |
45 |
Correct |
312 ms |
48824 KB |
Output is correct |
46 |
Correct |
279 ms |
49180 KB |
Output is correct |
47 |
Correct |
239 ms |
44996 KB |
Output is correct |
48 |
Correct |
207 ms |
44812 KB |
Output is correct |
49 |
Correct |
148 ms |
45628 KB |
Output is correct |
50 |
Correct |
149 ms |
30988 KB |
Output is correct |
51 |
Correct |
263 ms |
49200 KB |
Output is correct |
52 |
Correct |
240 ms |
49116 KB |
Output is correct |
53 |
Correct |
9 ms |
14420 KB |
Output is correct |
54 |
Correct |
7 ms |
14420 KB |
Output is correct |
55 |
Correct |
8 ms |
14532 KB |
Output is correct |
56 |
Correct |
9 ms |
14688 KB |
Output is correct |
57 |
Correct |
9 ms |
14676 KB |
Output is correct |
58 |
Correct |
9 ms |
14568 KB |
Output is correct |
59 |
Correct |
10 ms |
14676 KB |
Output is correct |
60 |
Correct |
10 ms |
14560 KB |
Output is correct |
61 |
Correct |
11 ms |
14688 KB |
Output is correct |
62 |
Correct |
9 ms |
14696 KB |
Output is correct |
63 |
Correct |
9 ms |
14688 KB |
Output is correct |
64 |
Correct |
9 ms |
14656 KB |
Output is correct |
65 |
Correct |
11 ms |
14676 KB |
Output is correct |
66 |
Correct |
11 ms |
14740 KB |
Output is correct |
67 |
Correct |
170 ms |
44168 KB |
Output is correct |
68 |
Correct |
219 ms |
48276 KB |
Output is correct |
69 |
Correct |
285 ms |
48380 KB |
Output is correct |
70 |
Correct |
264 ms |
49968 KB |
Output is correct |
71 |
Correct |
272 ms |
50380 KB |
Output is correct |
72 |
Correct |
239 ms |
45900 KB |
Output is correct |
73 |
Correct |
200 ms |
53972 KB |
Output is correct |
74 |
Correct |
231 ms |
43228 KB |
Output is correct |
75 |
Correct |
188 ms |
43848 KB |
Output is correct |
76 |
Correct |
257 ms |
45168 KB |
Output is correct |
77 |
Correct |
199 ms |
49552 KB |
Output is correct |
78 |
Correct |
189 ms |
48628 KB |
Output is correct |
79 |
Correct |
186 ms |
43652 KB |
Output is correct |
80 |
Correct |
111 ms |
42812 KB |
Output is correct |
81 |
Correct |
321 ms |
52460 KB |
Output is correct |
82 |
Correct |
296 ms |
52464 KB |
Output is correct |
83 |
Correct |
204 ms |
51408 KB |
Output is correct |
84 |
Correct |
192 ms |
49532 KB |
Output is correct |
85 |
Correct |
319 ms |
52496 KB |
Output is correct |
86 |
Correct |
214 ms |
43672 KB |
Output is correct |
87 |
Correct |
235 ms |
43740 KB |
Output is correct |
88 |
Correct |
194 ms |
47592 KB |
Output is correct |
89 |
Correct |
221 ms |
48696 KB |
Output is correct |
90 |
Correct |
290 ms |
46140 KB |
Output is correct |
91 |
Correct |
295 ms |
47424 KB |
Output is correct |
92 |
Correct |
288 ms |
48816 KB |
Output is correct |
93 |
Correct |
258 ms |
49112 KB |
Output is correct |
94 |
Correct |
244 ms |
45000 KB |
Output is correct |
95 |
Correct |
163 ms |
44864 KB |
Output is correct |
96 |
Correct |
131 ms |
45620 KB |
Output is correct |
97 |
Correct |
146 ms |
30908 KB |
Output is correct |
98 |
Correct |
289 ms |
49200 KB |
Output is correct |
99 |
Correct |
216 ms |
49020 KB |
Output is correct |
100 |
Correct |
53 ms |
18764 KB |
Output is correct |
101 |
Correct |
326 ms |
48292 KB |
Output is correct |
102 |
Correct |
180 ms |
38976 KB |
Output is correct |
103 |
Correct |
255 ms |
40048 KB |
Output is correct |
104 |
Correct |
284 ms |
45060 KB |
Output is correct |