#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long int
#define oo 4e18
#define pii pair<int, int>
const int MAX = 2e5 + 5;
int par[MAX];
ll sum[MAX];
vector<int> st[MAX];
int findset(int u){
if(par[u] < 0) return u;
return par[u] = findset(par[u]);
}
bool unite(int u, int v){
u = findset(u), v = findset(v);
if(u == v) return false;
if(-par[v] > -par[u]){
swap(u, v);
}
if(st[u].size() < st[v].size()) swap(st[v], st[u]);
for(int a:st[v]){
st[u].push_back(a);
}
par[u] += par[v];
par[v] = u;
sum[u] += sum[v];
return true;
}
int arr[MAX];
bool ans[MAX];
vector<int> g[MAX];
int main(){
memset(par, -1, sizeof(par));
fill(ans, ans + MAX, 1);
int n, m; cin >> n >> m;
vector<pii> v;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
sum[i] = arr[i];
st[i].push_back(i);
v.push_back({arr[i], i});
}
sort(v.begin(), v.end());
for (int i = 0; i < m; i++)
{
int a, b; cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for(pii node : v){
for(int to : g[node.second]){
if(arr[to] > arr[node.second]) continue;
int pto = findset(to), pnode = findset(node.second);
if(pto == pnode) continue;
if(sum[pto] < arr[node.second]){
for(int a : st[pto]){
ans[a] = 0;
}
st[pto].clear();
}
unite(to, node.second);
}
}
for (int i = 1; i <= n; i++)
{
cout << ans[i];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10580 KB |
Output is correct |
2 |
Correct |
5 ms |
10580 KB |
Output is correct |
3 |
Correct |
5 ms |
10672 KB |
Output is correct |
4 |
Correct |
7 ms |
10828 KB |
Output is correct |
5 |
Correct |
7 ms |
10832 KB |
Output is correct |
6 |
Correct |
6 ms |
10836 KB |
Output is correct |
7 |
Correct |
7 ms |
10836 KB |
Output is correct |
8 |
Correct |
6 ms |
10828 KB |
Output is correct |
9 |
Correct |
6 ms |
10836 KB |
Output is correct |
10 |
Correct |
7 ms |
10836 KB |
Output is correct |
11 |
Correct |
9 ms |
10836 KB |
Output is correct |
12 |
Correct |
7 ms |
10876 KB |
Output is correct |
13 |
Correct |
6 ms |
10780 KB |
Output is correct |
14 |
Correct |
7 ms |
10836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10688 KB |
Output is correct |
2 |
Correct |
5 ms |
10604 KB |
Output is correct |
3 |
Correct |
204 ms |
33268 KB |
Output is correct |
4 |
Correct |
201 ms |
32100 KB |
Output is correct |
5 |
Correct |
228 ms |
34200 KB |
Output is correct |
6 |
Correct |
292 ms |
35040 KB |
Output is correct |
7 |
Correct |
231 ms |
35040 KB |
Output is correct |
8 |
Correct |
219 ms |
33508 KB |
Output is correct |
9 |
Correct |
207 ms |
36180 KB |
Output is correct |
10 |
Correct |
185 ms |
31612 KB |
Output is correct |
11 |
Correct |
204 ms |
33292 KB |
Output is correct |
12 |
Correct |
217 ms |
31452 KB |
Output is correct |
13 |
Correct |
170 ms |
31968 KB |
Output is correct |
14 |
Correct |
184 ms |
32024 KB |
Output is correct |
15 |
Correct |
201 ms |
33444 KB |
Output is correct |
16 |
Correct |
191 ms |
32676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10580 KB |
Output is correct |
2 |
Correct |
260 ms |
35660 KB |
Output is correct |
3 |
Correct |
285 ms |
35760 KB |
Output is correct |
4 |
Correct |
213 ms |
33536 KB |
Output is correct |
5 |
Correct |
173 ms |
31676 KB |
Output is correct |
6 |
Correct |
264 ms |
35644 KB |
Output is correct |
7 |
Correct |
231 ms |
33464 KB |
Output is correct |
8 |
Correct |
214 ms |
33464 KB |
Output is correct |
9 |
Correct |
164 ms |
32616 KB |
Output is correct |
10 |
Correct |
187 ms |
31900 KB |
Output is correct |
11 |
Correct |
221 ms |
31676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10580 KB |
Output is correct |
2 |
Correct |
287 ms |
33500 KB |
Output is correct |
3 |
Correct |
262 ms |
33848 KB |
Output is correct |
4 |
Correct |
268 ms |
34988 KB |
Output is correct |
5 |
Correct |
301 ms |
36228 KB |
Output is correct |
6 |
Correct |
237 ms |
33756 KB |
Output is correct |
7 |
Correct |
219 ms |
34188 KB |
Output is correct |
8 |
Correct |
166 ms |
31824 KB |
Output is correct |
9 |
Correct |
143 ms |
23260 KB |
Output is correct |
10 |
Correct |
219 ms |
36132 KB |
Output is correct |
11 |
Correct |
216 ms |
31672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10580 KB |
Output is correct |
2 |
Correct |
5 ms |
10580 KB |
Output is correct |
3 |
Correct |
5 ms |
10672 KB |
Output is correct |
4 |
Correct |
7 ms |
10828 KB |
Output is correct |
5 |
Correct |
7 ms |
10832 KB |
Output is correct |
6 |
Correct |
6 ms |
10836 KB |
Output is correct |
7 |
Correct |
7 ms |
10836 KB |
Output is correct |
8 |
Correct |
6 ms |
10828 KB |
Output is correct |
9 |
Correct |
6 ms |
10836 KB |
Output is correct |
10 |
Correct |
7 ms |
10836 KB |
Output is correct |
11 |
Correct |
9 ms |
10836 KB |
Output is correct |
12 |
Correct |
7 ms |
10876 KB |
Output is correct |
13 |
Correct |
6 ms |
10780 KB |
Output is correct |
14 |
Correct |
7 ms |
10836 KB |
Output is correct |
15 |
Correct |
5 ms |
10688 KB |
Output is correct |
16 |
Correct |
5 ms |
10604 KB |
Output is correct |
17 |
Correct |
204 ms |
33268 KB |
Output is correct |
18 |
Correct |
201 ms |
32100 KB |
Output is correct |
19 |
Correct |
228 ms |
34200 KB |
Output is correct |
20 |
Correct |
292 ms |
35040 KB |
Output is correct |
21 |
Correct |
231 ms |
35040 KB |
Output is correct |
22 |
Correct |
219 ms |
33508 KB |
Output is correct |
23 |
Correct |
207 ms |
36180 KB |
Output is correct |
24 |
Correct |
185 ms |
31612 KB |
Output is correct |
25 |
Correct |
204 ms |
33292 KB |
Output is correct |
26 |
Correct |
217 ms |
31452 KB |
Output is correct |
27 |
Correct |
170 ms |
31968 KB |
Output is correct |
28 |
Correct |
184 ms |
32024 KB |
Output is correct |
29 |
Correct |
201 ms |
33444 KB |
Output is correct |
30 |
Correct |
191 ms |
32676 KB |
Output is correct |
31 |
Correct |
5 ms |
10580 KB |
Output is correct |
32 |
Correct |
260 ms |
35660 KB |
Output is correct |
33 |
Correct |
285 ms |
35760 KB |
Output is correct |
34 |
Correct |
213 ms |
33536 KB |
Output is correct |
35 |
Correct |
173 ms |
31676 KB |
Output is correct |
36 |
Correct |
264 ms |
35644 KB |
Output is correct |
37 |
Correct |
231 ms |
33464 KB |
Output is correct |
38 |
Correct |
214 ms |
33464 KB |
Output is correct |
39 |
Correct |
164 ms |
32616 KB |
Output is correct |
40 |
Correct |
187 ms |
31900 KB |
Output is correct |
41 |
Correct |
221 ms |
31676 KB |
Output is correct |
42 |
Correct |
5 ms |
10580 KB |
Output is correct |
43 |
Correct |
287 ms |
33500 KB |
Output is correct |
44 |
Correct |
262 ms |
33848 KB |
Output is correct |
45 |
Correct |
268 ms |
34988 KB |
Output is correct |
46 |
Correct |
301 ms |
36228 KB |
Output is correct |
47 |
Correct |
237 ms |
33756 KB |
Output is correct |
48 |
Correct |
219 ms |
34188 KB |
Output is correct |
49 |
Correct |
166 ms |
31824 KB |
Output is correct |
50 |
Correct |
143 ms |
23260 KB |
Output is correct |
51 |
Correct |
219 ms |
36132 KB |
Output is correct |
52 |
Correct |
216 ms |
31672 KB |
Output is correct |
53 |
Correct |
5 ms |
10692 KB |
Output is correct |
54 |
Correct |
5 ms |
10580 KB |
Output is correct |
55 |
Correct |
6 ms |
10692 KB |
Output is correct |
56 |
Correct |
6 ms |
10836 KB |
Output is correct |
57 |
Correct |
6 ms |
10836 KB |
Output is correct |
58 |
Correct |
6 ms |
10836 KB |
Output is correct |
59 |
Correct |
6 ms |
10828 KB |
Output is correct |
60 |
Correct |
6 ms |
10836 KB |
Output is correct |
61 |
Correct |
8 ms |
10828 KB |
Output is correct |
62 |
Correct |
7 ms |
10824 KB |
Output is correct |
63 |
Correct |
6 ms |
10912 KB |
Output is correct |
64 |
Correct |
6 ms |
10860 KB |
Output is correct |
65 |
Correct |
6 ms |
10820 KB |
Output is correct |
66 |
Correct |
6 ms |
10836 KB |
Output is correct |
67 |
Correct |
219 ms |
33404 KB |
Output is correct |
68 |
Correct |
187 ms |
32128 KB |
Output is correct |
69 |
Correct |
224 ms |
34180 KB |
Output is correct |
70 |
Correct |
249 ms |
35108 KB |
Output is correct |
71 |
Correct |
261 ms |
35012 KB |
Output is correct |
72 |
Correct |
226 ms |
33520 KB |
Output is correct |
73 |
Correct |
218 ms |
36160 KB |
Output is correct |
74 |
Correct |
191 ms |
31576 KB |
Output is correct |
75 |
Correct |
222 ms |
33260 KB |
Output is correct |
76 |
Correct |
231 ms |
31684 KB |
Output is correct |
77 |
Correct |
176 ms |
31972 KB |
Output is correct |
78 |
Correct |
179 ms |
32000 KB |
Output is correct |
79 |
Correct |
231 ms |
33460 KB |
Output is correct |
80 |
Correct |
167 ms |
32652 KB |
Output is correct |
81 |
Correct |
270 ms |
35640 KB |
Output is correct |
82 |
Correct |
333 ms |
35860 KB |
Output is correct |
83 |
Correct |
278 ms |
33672 KB |
Output is correct |
84 |
Correct |
199 ms |
31676 KB |
Output is correct |
85 |
Correct |
308 ms |
35756 KB |
Output is correct |
86 |
Correct |
268 ms |
33540 KB |
Output is correct |
87 |
Correct |
267 ms |
33564 KB |
Output is correct |
88 |
Correct |
234 ms |
31892 KB |
Output is correct |
89 |
Correct |
256 ms |
31688 KB |
Output is correct |
90 |
Correct |
290 ms |
33456 KB |
Output is correct |
91 |
Correct |
319 ms |
33860 KB |
Output is correct |
92 |
Correct |
303 ms |
34940 KB |
Output is correct |
93 |
Correct |
294 ms |
36184 KB |
Output is correct |
94 |
Correct |
233 ms |
33764 KB |
Output is correct |
95 |
Correct |
224 ms |
34300 KB |
Output is correct |
96 |
Correct |
165 ms |
31796 KB |
Output is correct |
97 |
Correct |
192 ms |
23308 KB |
Output is correct |
98 |
Correct |
246 ms |
36068 KB |
Output is correct |
99 |
Correct |
213 ms |
31676 KB |
Output is correct |
100 |
Correct |
81 ms |
15088 KB |
Output is correct |
101 |
Correct |
315 ms |
34284 KB |
Output is correct |
102 |
Correct |
226 ms |
29916 KB |
Output is correct |
103 |
Correct |
339 ms |
29796 KB |
Output is correct |
104 |
Correct |
317 ms |
32928 KB |
Output is correct |