#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 |
3 ms |
13144 KB |
Output is correct |
2 |
Correct |
3 ms |
13144 KB |
Output is correct |
3 |
Correct |
3 ms |
13148 KB |
Output is correct |
4 |
Correct |
5 ms |
13144 KB |
Output is correct |
5 |
Correct |
5 ms |
13144 KB |
Output is correct |
6 |
Correct |
6 ms |
13144 KB |
Output is correct |
7 |
Correct |
5 ms |
13144 KB |
Output is correct |
8 |
Correct |
5 ms |
13144 KB |
Output is correct |
9 |
Correct |
4 ms |
13144 KB |
Output is correct |
10 |
Correct |
5 ms |
13148 KB |
Output is correct |
11 |
Correct |
5 ms |
13144 KB |
Output is correct |
12 |
Correct |
6 ms |
13144 KB |
Output is correct |
13 |
Correct |
4 ms |
13144 KB |
Output is correct |
14 |
Correct |
4 ms |
13144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
13144 KB |
Output is correct |
2 |
Correct |
3 ms |
13148 KB |
Output is correct |
3 |
Correct |
220 ms |
31400 KB |
Output is correct |
4 |
Correct |
208 ms |
31164 KB |
Output is correct |
5 |
Correct |
234 ms |
32448 KB |
Output is correct |
6 |
Correct |
263 ms |
33148 KB |
Output is correct |
7 |
Correct |
240 ms |
33212 KB |
Output is correct |
8 |
Correct |
250 ms |
31844 KB |
Output is correct |
9 |
Correct |
212 ms |
34024 KB |
Output is correct |
10 |
Correct |
192 ms |
30240 KB |
Output is correct |
11 |
Correct |
212 ms |
31848 KB |
Output is correct |
12 |
Correct |
233 ms |
30376 KB |
Output is correct |
13 |
Correct |
181 ms |
31164 KB |
Output is correct |
14 |
Correct |
205 ms |
30908 KB |
Output is correct |
15 |
Correct |
219 ms |
31632 KB |
Output is correct |
16 |
Correct |
166 ms |
30952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Correct |
274 ms |
33976 KB |
Output is correct |
3 |
Correct |
279 ms |
33948 KB |
Output is correct |
4 |
Correct |
228 ms |
31584 KB |
Output is correct |
5 |
Correct |
172 ms |
30764 KB |
Output is correct |
6 |
Correct |
269 ms |
33860 KB |
Output is correct |
7 |
Correct |
225 ms |
31936 KB |
Output is correct |
8 |
Correct |
220 ms |
31676 KB |
Output is correct |
9 |
Correct |
180 ms |
31248 KB |
Output is correct |
10 |
Correct |
211 ms |
30232 KB |
Output is correct |
11 |
Correct |
225 ms |
30908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Correct |
280 ms |
31676 KB |
Output is correct |
3 |
Correct |
280 ms |
32028 KB |
Output is correct |
4 |
Correct |
293 ms |
33344 KB |
Output is correct |
5 |
Correct |
284 ms |
34536 KB |
Output is correct |
6 |
Correct |
262 ms |
32260 KB |
Output is correct |
7 |
Correct |
208 ms |
32444 KB |
Output is correct |
8 |
Correct |
168 ms |
30656 KB |
Output is correct |
9 |
Correct |
144 ms |
23488 KB |
Output is correct |
10 |
Correct |
235 ms |
35004 KB |
Output is correct |
11 |
Correct |
212 ms |
30656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Correct |
3 ms |
13144 KB |
Output is correct |
3 |
Correct |
3 ms |
13148 KB |
Output is correct |
4 |
Correct |
5 ms |
13144 KB |
Output is correct |
5 |
Correct |
5 ms |
13144 KB |
Output is correct |
6 |
Correct |
6 ms |
13144 KB |
Output is correct |
7 |
Correct |
5 ms |
13144 KB |
Output is correct |
8 |
Correct |
5 ms |
13144 KB |
Output is correct |
9 |
Correct |
4 ms |
13144 KB |
Output is correct |
10 |
Correct |
5 ms |
13148 KB |
Output is correct |
11 |
Correct |
5 ms |
13144 KB |
Output is correct |
12 |
Correct |
6 ms |
13144 KB |
Output is correct |
13 |
Correct |
4 ms |
13144 KB |
Output is correct |
14 |
Correct |
4 ms |
13144 KB |
Output is correct |
15 |
Correct |
4 ms |
13144 KB |
Output is correct |
16 |
Correct |
3 ms |
13148 KB |
Output is correct |
17 |
Correct |
220 ms |
31400 KB |
Output is correct |
18 |
Correct |
208 ms |
31164 KB |
Output is correct |
19 |
Correct |
234 ms |
32448 KB |
Output is correct |
20 |
Correct |
263 ms |
33148 KB |
Output is correct |
21 |
Correct |
240 ms |
33212 KB |
Output is correct |
22 |
Correct |
250 ms |
31844 KB |
Output is correct |
23 |
Correct |
212 ms |
34024 KB |
Output is correct |
24 |
Correct |
192 ms |
30240 KB |
Output is correct |
25 |
Correct |
212 ms |
31848 KB |
Output is correct |
26 |
Correct |
233 ms |
30376 KB |
Output is correct |
27 |
Correct |
181 ms |
31164 KB |
Output is correct |
28 |
Correct |
205 ms |
30908 KB |
Output is correct |
29 |
Correct |
219 ms |
31632 KB |
Output is correct |
30 |
Correct |
166 ms |
30952 KB |
Output is correct |
31 |
Correct |
3 ms |
13144 KB |
Output is correct |
32 |
Correct |
274 ms |
33976 KB |
Output is correct |
33 |
Correct |
279 ms |
33948 KB |
Output is correct |
34 |
Correct |
228 ms |
31584 KB |
Output is correct |
35 |
Correct |
172 ms |
30764 KB |
Output is correct |
36 |
Correct |
269 ms |
33860 KB |
Output is correct |
37 |
Correct |
225 ms |
31936 KB |
Output is correct |
38 |
Correct |
220 ms |
31676 KB |
Output is correct |
39 |
Correct |
180 ms |
31248 KB |
Output is correct |
40 |
Correct |
211 ms |
30232 KB |
Output is correct |
41 |
Correct |
225 ms |
30908 KB |
Output is correct |
42 |
Correct |
3 ms |
13144 KB |
Output is correct |
43 |
Correct |
280 ms |
31676 KB |
Output is correct |
44 |
Correct |
280 ms |
32028 KB |
Output is correct |
45 |
Correct |
293 ms |
33344 KB |
Output is correct |
46 |
Correct |
284 ms |
34536 KB |
Output is correct |
47 |
Correct |
262 ms |
32260 KB |
Output is correct |
48 |
Correct |
208 ms |
32444 KB |
Output is correct |
49 |
Correct |
168 ms |
30656 KB |
Output is correct |
50 |
Correct |
144 ms |
23488 KB |
Output is correct |
51 |
Correct |
235 ms |
35004 KB |
Output is correct |
52 |
Correct |
212 ms |
30656 KB |
Output is correct |
53 |
Correct |
3 ms |
13144 KB |
Output is correct |
54 |
Correct |
3 ms |
13144 KB |
Output is correct |
55 |
Correct |
3 ms |
13144 KB |
Output is correct |
56 |
Correct |
4 ms |
13144 KB |
Output is correct |
57 |
Correct |
5 ms |
13144 KB |
Output is correct |
58 |
Correct |
5 ms |
13144 KB |
Output is correct |
59 |
Correct |
5 ms |
13148 KB |
Output is correct |
60 |
Correct |
4 ms |
13144 KB |
Output is correct |
61 |
Correct |
4 ms |
13144 KB |
Output is correct |
62 |
Correct |
5 ms |
13148 KB |
Output is correct |
63 |
Correct |
5 ms |
13144 KB |
Output is correct |
64 |
Correct |
5 ms |
13144 KB |
Output is correct |
65 |
Correct |
5 ms |
13144 KB |
Output is correct |
66 |
Correct |
5 ms |
13144 KB |
Output is correct |
67 |
Correct |
212 ms |
31440 KB |
Output is correct |
68 |
Correct |
203 ms |
31164 KB |
Output is correct |
69 |
Correct |
228 ms |
32444 KB |
Output is correct |
70 |
Correct |
271 ms |
33648 KB |
Output is correct |
71 |
Correct |
251 ms |
33268 KB |
Output is correct |
72 |
Correct |
241 ms |
31700 KB |
Output is correct |
73 |
Correct |
226 ms |
34236 KB |
Output is correct |
74 |
Correct |
202 ms |
30208 KB |
Output is correct |
75 |
Correct |
207 ms |
31928 KB |
Output is correct |
76 |
Correct |
257 ms |
30360 KB |
Output is correct |
77 |
Correct |
174 ms |
30952 KB |
Output is correct |
78 |
Correct |
201 ms |
30836 KB |
Output is correct |
79 |
Correct |
202 ms |
31680 KB |
Output is correct |
80 |
Correct |
197 ms |
30932 KB |
Output is correct |
81 |
Correct |
272 ms |
33980 KB |
Output is correct |
82 |
Correct |
277 ms |
33896 KB |
Output is correct |
83 |
Correct |
242 ms |
31704 KB |
Output is correct |
84 |
Correct |
186 ms |
30652 KB |
Output is correct |
85 |
Correct |
265 ms |
33980 KB |
Output is correct |
86 |
Correct |
237 ms |
31596 KB |
Output is correct |
87 |
Correct |
231 ms |
31560 KB |
Output is correct |
88 |
Correct |
218 ms |
30396 KB |
Output is correct |
89 |
Correct |
219 ms |
30584 KB |
Output is correct |
90 |
Correct |
270 ms |
31828 KB |
Output is correct |
91 |
Correct |
287 ms |
32192 KB |
Output is correct |
92 |
Correct |
278 ms |
33220 KB |
Output is correct |
93 |
Correct |
273 ms |
34412 KB |
Output is correct |
94 |
Correct |
241 ms |
32020 KB |
Output is correct |
95 |
Correct |
206 ms |
32448 KB |
Output is correct |
96 |
Correct |
168 ms |
30428 KB |
Output is correct |
97 |
Correct |
146 ms |
23488 KB |
Output is correct |
98 |
Correct |
240 ms |
35128 KB |
Output is correct |
99 |
Correct |
206 ms |
30680 KB |
Output is correct |
100 |
Correct |
78 ms |
16720 KB |
Output is correct |
101 |
Correct |
272 ms |
32492 KB |
Output is correct |
102 |
Correct |
225 ms |
28896 KB |
Output is correct |
103 |
Correct |
234 ms |
28348 KB |
Output is correct |
104 |
Correct |
277 ms |
31164 KB |
Output is correct |