#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=2e5;
int n, m, s[mxN], p[mxN];
vector<int> adj[mxN], rts, tree[mxN];
map<int, vector<int>> mp;
bool ans[mxN];
set<ar<int, 2>> bigger[mxN];
ll sum[mxN];
int find(int i) {
return i^p[i]?p[i]=find(p[i]):i;
}
void mrg(int u, int v) {
if ((u=find(u))==(v=find(v)))
return;
if (s[u]<s[v])
swap(u, v);
p[v]=u;
sum[u]+=sum[v];
if (bigger[u].size()<bigger[v].size())
swap(bigger[u], bigger[v]);
for (ar<int, 2> i : bigger[v])
bigger[u].insert(i);
set<ar<int, 2>>().swap(bigger[v]);
while(bigger[u].size()&&(*bigger[u].begin())[0]<=s[u]) {
assert((*bigger[u].begin())[0]==s[u]);
bigger[u].erase(bigger[u].begin());
}
}
void dfs(int u) {
ans[u]=1;
for (int v : tree[u])
dfs(v);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i=0; i<n; ++i) {
cin >> s[i];
mp[s[i]].push_back(i);
p[i]=i, sum[i]=s[i];
}
for (int i=0; i<m; ++i) {
int u, v;
cin >> u >> v, --u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
if (s[v]>s[u])
bigger[u].insert({s[v], v});
if (s[u]>s[v])
bigger[v].insert({s[u], u});
}
for (int x : mp.rbegin()->second)
rts.push_back(x);
for (auto it=mp.begin(); it!=mp.end(); ++it) {
vector<int> nodes=it->second;
for (int u : nodes)
for (int v : adj[u])
if (s[v]<=s[u])
mrg(u, v);
for (int u : nodes) {
int v=find(u);
if (bigger[v].size()&&sum[v]>=(*bigger[v].begin())[0])
tree[(*bigger[v].begin())[1]].push_back(u);
}
}
for (int i : rts)
dfs(i);
for (int i=0; i<n; ++i)
cout << ans[i];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
11 ms |
19084 KB |
Output is correct |
3 |
Correct |
11 ms |
19116 KB |
Output is correct |
4 |
Correct |
12 ms |
19524 KB |
Output is correct |
5 |
Correct |
11 ms |
19536 KB |
Output is correct |
6 |
Correct |
11 ms |
19196 KB |
Output is correct |
7 |
Correct |
12 ms |
19404 KB |
Output is correct |
8 |
Correct |
12 ms |
19416 KB |
Output is correct |
9 |
Correct |
11 ms |
19284 KB |
Output is correct |
10 |
Correct |
12 ms |
19500 KB |
Output is correct |
11 |
Correct |
11 ms |
19540 KB |
Output is correct |
12 |
Correct |
11 ms |
19540 KB |
Output is correct |
13 |
Correct |
10 ms |
19152 KB |
Output is correct |
14 |
Correct |
11 ms |
19284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
19028 KB |
Output is correct |
2 |
Correct |
12 ms |
19028 KB |
Output is correct |
3 |
Correct |
319 ms |
63192 KB |
Output is correct |
4 |
Correct |
131 ms |
31624 KB |
Output is correct |
5 |
Correct |
359 ms |
60492 KB |
Output is correct |
6 |
Correct |
354 ms |
56984 KB |
Output is correct |
7 |
Correct |
362 ms |
62628 KB |
Output is correct |
8 |
Correct |
179 ms |
34268 KB |
Output is correct |
9 |
Correct |
302 ms |
57536 KB |
Output is correct |
10 |
Correct |
210 ms |
58576 KB |
Output is correct |
11 |
Correct |
132 ms |
34488 KB |
Output is correct |
12 |
Correct |
187 ms |
32920 KB |
Output is correct |
13 |
Correct |
128 ms |
31300 KB |
Output is correct |
14 |
Correct |
129 ms |
32404 KB |
Output is correct |
15 |
Correct |
394 ms |
67148 KB |
Output is correct |
16 |
Correct |
189 ms |
65860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19044 KB |
Output is correct |
2 |
Correct |
562 ms |
63348 KB |
Output is correct |
3 |
Correct |
495 ms |
57840 KB |
Output is correct |
4 |
Correct |
133 ms |
32960 KB |
Output is correct |
5 |
Correct |
139 ms |
31492 KB |
Output is correct |
6 |
Correct |
521 ms |
62328 KB |
Output is correct |
7 |
Correct |
319 ms |
65788 KB |
Output is correct |
8 |
Correct |
343 ms |
65764 KB |
Output is correct |
9 |
Correct |
187 ms |
64712 KB |
Output is correct |
10 |
Correct |
296 ms |
52904 KB |
Output is correct |
11 |
Correct |
256 ms |
41216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19080 KB |
Output is correct |
2 |
Correct |
388 ms |
40460 KB |
Output is correct |
3 |
Correct |
357 ms |
41688 KB |
Output is correct |
4 |
Correct |
356 ms |
40128 KB |
Output is correct |
5 |
Correct |
171 ms |
35396 KB |
Output is correct |
6 |
Correct |
216 ms |
33392 KB |
Output is correct |
7 |
Correct |
139 ms |
34512 KB |
Output is correct |
8 |
Correct |
123 ms |
39896 KB |
Output is correct |
9 |
Correct |
292 ms |
35176 KB |
Output is correct |
10 |
Correct |
168 ms |
31440 KB |
Output is correct |
11 |
Correct |
291 ms |
39032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
11 ms |
19084 KB |
Output is correct |
3 |
Correct |
11 ms |
19116 KB |
Output is correct |
4 |
Correct |
12 ms |
19524 KB |
Output is correct |
5 |
Correct |
11 ms |
19536 KB |
Output is correct |
6 |
Correct |
11 ms |
19196 KB |
Output is correct |
7 |
Correct |
12 ms |
19404 KB |
Output is correct |
8 |
Correct |
12 ms |
19416 KB |
Output is correct |
9 |
Correct |
11 ms |
19284 KB |
Output is correct |
10 |
Correct |
12 ms |
19500 KB |
Output is correct |
11 |
Correct |
11 ms |
19540 KB |
Output is correct |
12 |
Correct |
11 ms |
19540 KB |
Output is correct |
13 |
Correct |
10 ms |
19152 KB |
Output is correct |
14 |
Correct |
11 ms |
19284 KB |
Output is correct |
15 |
Correct |
12 ms |
19028 KB |
Output is correct |
16 |
Correct |
12 ms |
19028 KB |
Output is correct |
17 |
Correct |
319 ms |
63192 KB |
Output is correct |
18 |
Correct |
131 ms |
31624 KB |
Output is correct |
19 |
Correct |
359 ms |
60492 KB |
Output is correct |
20 |
Correct |
354 ms |
56984 KB |
Output is correct |
21 |
Correct |
362 ms |
62628 KB |
Output is correct |
22 |
Correct |
179 ms |
34268 KB |
Output is correct |
23 |
Correct |
302 ms |
57536 KB |
Output is correct |
24 |
Correct |
210 ms |
58576 KB |
Output is correct |
25 |
Correct |
132 ms |
34488 KB |
Output is correct |
26 |
Correct |
187 ms |
32920 KB |
Output is correct |
27 |
Correct |
128 ms |
31300 KB |
Output is correct |
28 |
Correct |
129 ms |
32404 KB |
Output is correct |
29 |
Correct |
394 ms |
67148 KB |
Output is correct |
30 |
Correct |
189 ms |
65860 KB |
Output is correct |
31 |
Correct |
10 ms |
19044 KB |
Output is correct |
32 |
Correct |
562 ms |
63348 KB |
Output is correct |
33 |
Correct |
495 ms |
57840 KB |
Output is correct |
34 |
Correct |
133 ms |
32960 KB |
Output is correct |
35 |
Correct |
139 ms |
31492 KB |
Output is correct |
36 |
Correct |
521 ms |
62328 KB |
Output is correct |
37 |
Correct |
319 ms |
65788 KB |
Output is correct |
38 |
Correct |
343 ms |
65764 KB |
Output is correct |
39 |
Correct |
187 ms |
64712 KB |
Output is correct |
40 |
Correct |
296 ms |
52904 KB |
Output is correct |
41 |
Correct |
256 ms |
41216 KB |
Output is correct |
42 |
Correct |
10 ms |
19080 KB |
Output is correct |
43 |
Correct |
388 ms |
40460 KB |
Output is correct |
44 |
Correct |
357 ms |
41688 KB |
Output is correct |
45 |
Correct |
356 ms |
40128 KB |
Output is correct |
46 |
Correct |
171 ms |
35396 KB |
Output is correct |
47 |
Correct |
216 ms |
33392 KB |
Output is correct |
48 |
Correct |
139 ms |
34512 KB |
Output is correct |
49 |
Correct |
123 ms |
39896 KB |
Output is correct |
50 |
Correct |
292 ms |
35176 KB |
Output is correct |
51 |
Correct |
168 ms |
31440 KB |
Output is correct |
52 |
Correct |
291 ms |
39032 KB |
Output is correct |
53 |
Correct |
10 ms |
19028 KB |
Output is correct |
54 |
Correct |
11 ms |
19028 KB |
Output is correct |
55 |
Correct |
10 ms |
19028 KB |
Output is correct |
56 |
Correct |
12 ms |
19540 KB |
Output is correct |
57 |
Correct |
12 ms |
19500 KB |
Output is correct |
58 |
Correct |
10 ms |
19156 KB |
Output is correct |
59 |
Correct |
14 ms |
19400 KB |
Output is correct |
60 |
Correct |
12 ms |
19404 KB |
Output is correct |
61 |
Correct |
13 ms |
19284 KB |
Output is correct |
62 |
Correct |
12 ms |
19452 KB |
Output is correct |
63 |
Correct |
14 ms |
19512 KB |
Output is correct |
64 |
Correct |
12 ms |
19496 KB |
Output is correct |
65 |
Correct |
12 ms |
19156 KB |
Output is correct |
66 |
Correct |
12 ms |
19268 KB |
Output is correct |
67 |
Correct |
305 ms |
64304 KB |
Output is correct |
68 |
Correct |
134 ms |
32172 KB |
Output is correct |
69 |
Correct |
352 ms |
59892 KB |
Output is correct |
70 |
Correct |
350 ms |
57100 KB |
Output is correct |
71 |
Correct |
360 ms |
61584 KB |
Output is correct |
72 |
Correct |
193 ms |
33780 KB |
Output is correct |
73 |
Correct |
283 ms |
57348 KB |
Output is correct |
74 |
Correct |
219 ms |
56832 KB |
Output is correct |
75 |
Correct |
129 ms |
33080 KB |
Output is correct |
76 |
Correct |
158 ms |
32372 KB |
Output is correct |
77 |
Correct |
122 ms |
31212 KB |
Output is correct |
78 |
Correct |
141 ms |
31240 KB |
Output is correct |
79 |
Correct |
325 ms |
66080 KB |
Output is correct |
80 |
Correct |
194 ms |
66800 KB |
Output is correct |
81 |
Correct |
493 ms |
62308 KB |
Output is correct |
82 |
Correct |
446 ms |
58056 KB |
Output is correct |
83 |
Correct |
152 ms |
30916 KB |
Output is correct |
84 |
Correct |
128 ms |
31964 KB |
Output is correct |
85 |
Correct |
469 ms |
64716 KB |
Output is correct |
86 |
Correct |
370 ms |
68148 KB |
Output is correct |
87 |
Correct |
328 ms |
68136 KB |
Output is correct |
88 |
Correct |
286 ms |
52556 KB |
Output is correct |
89 |
Correct |
240 ms |
38876 KB |
Output is correct |
90 |
Correct |
386 ms |
41056 KB |
Output is correct |
91 |
Correct |
347 ms |
42964 KB |
Output is correct |
92 |
Correct |
372 ms |
43212 KB |
Output is correct |
93 |
Correct |
164 ms |
34436 KB |
Output is correct |
94 |
Correct |
183 ms |
33604 KB |
Output is correct |
95 |
Correct |
133 ms |
36208 KB |
Output is correct |
96 |
Correct |
125 ms |
39512 KB |
Output is correct |
97 |
Correct |
262 ms |
35692 KB |
Output is correct |
98 |
Correct |
197 ms |
33096 KB |
Output is correct |
99 |
Correct |
249 ms |
40616 KB |
Output is correct |
100 |
Correct |
178 ms |
33024 KB |
Output is correct |
101 |
Correct |
537 ms |
60024 KB |
Output is correct |
102 |
Correct |
153 ms |
30560 KB |
Output is correct |
103 |
Correct |
582 ms |
51760 KB |
Output is correct |
104 |
Correct |
582 ms |
60212 KB |
Output is correct |