#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct ufds{
vector<int> par;
ufds(int n): par(n){
iota(par.begin(), par.end(), 0);
}
int find(int a){
return a == par[a] ? a : par[a] = find(par[a]);
}
int unite(int a,int b){
a = find(a), b = find(b);
if(a == b) return 0;
par[b] = a;
return 1;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
vector<int> s(n);
for(int &x: s){
cin >> x;
}
vector<vector<int>> g(n);
while(m--){
int u,v;
cin >> u >> v,u--,v--;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> ok(n);
vector<pair<int,int>> srt;
for(int i = 0; i < n; i++){
srt.emplace_back(s[i],i);
}
sort(srt.begin(), srt.end());
vector<vector<int>> tree(n);
ufds ds(n);
for(auto [x,v]: srt){
for(int u: g[v]) if(ok[u]){
if(ok[u] && ds.find(u) != ds.find(v)){
tree[v].push_back(ds.find(u));
ds.unite(v,u);
}
}
ok[v] = 1;
}
vector<ll> sums;
for(auto x: s){
sums.push_back(x);
}
vector<int> ans(n);
function <void(int)> dfs = [&](int v){
ans[v] = 1;
for(int u: tree[v]){
dfs(u);
ans[u] &= s[v] <= sums[u];
sums[v] += sums[u];
}
};
function <void(int)> dfs1 = [&](int v){
for(int u: tree[v]){
ans[u] &= ans[v];
dfs1(u);
}
};
dfs(ds.find(0));
dfs1(ds.find(0));
for(int x: ans){
cout << x;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
150 ms |
34148 KB |
Output is correct |
4 |
Correct |
181 ms |
45676 KB |
Output is correct |
5 |
Correct |
214 ms |
26180 KB |
Output is correct |
6 |
Correct |
189 ms |
26860 KB |
Output is correct |
7 |
Correct |
221 ms |
26876 KB |
Output is correct |
8 |
Correct |
189 ms |
47528 KB |
Output is correct |
9 |
Correct |
146 ms |
26196 KB |
Output is correct |
10 |
Correct |
137 ms |
25276 KB |
Output is correct |
11 |
Correct |
151 ms |
48240 KB |
Output is correct |
12 |
Correct |
214 ms |
29996 KB |
Output is correct |
13 |
Correct |
171 ms |
47372 KB |
Output is correct |
14 |
Correct |
191 ms |
45564 KB |
Output is correct |
15 |
Correct |
147 ms |
47408 KB |
Output is correct |
16 |
Correct |
103 ms |
46976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
218 ms |
27000 KB |
Output is correct |
3 |
Correct |
199 ms |
27060 KB |
Output is correct |
4 |
Correct |
176 ms |
47396 KB |
Output is correct |
5 |
Correct |
159 ms |
41416 KB |
Output is correct |
6 |
Correct |
225 ms |
27092 KB |
Output is correct |
7 |
Correct |
163 ms |
47420 KB |
Output is correct |
8 |
Correct |
166 ms |
47452 KB |
Output is correct |
9 |
Correct |
129 ms |
46912 KB |
Output is correct |
10 |
Correct |
139 ms |
34876 KB |
Output is correct |
11 |
Correct |
157 ms |
30116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
286 ms |
27452 KB |
Output is correct |
3 |
Correct |
219 ms |
26796 KB |
Output is correct |
4 |
Correct |
217 ms |
26944 KB |
Output is correct |
5 |
Correct |
240 ms |
26804 KB |
Output is correct |
6 |
Correct |
183 ms |
27636 KB |
Output is correct |
7 |
Correct |
119 ms |
37424 KB |
Output is correct |
8 |
Correct |
120 ms |
47380 KB |
Output is correct |
9 |
Correct |
136 ms |
15468 KB |
Output is correct |
10 |
Correct |
202 ms |
26992 KB |
Output is correct |
11 |
Correct |
172 ms |
30048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
150 ms |
34148 KB |
Output is correct |
18 |
Correct |
181 ms |
45676 KB |
Output is correct |
19 |
Correct |
214 ms |
26180 KB |
Output is correct |
20 |
Correct |
189 ms |
26860 KB |
Output is correct |
21 |
Correct |
221 ms |
26876 KB |
Output is correct |
22 |
Correct |
189 ms |
47528 KB |
Output is correct |
23 |
Correct |
146 ms |
26196 KB |
Output is correct |
24 |
Correct |
137 ms |
25276 KB |
Output is correct |
25 |
Correct |
151 ms |
48240 KB |
Output is correct |
26 |
Correct |
214 ms |
29996 KB |
Output is correct |
27 |
Correct |
171 ms |
47372 KB |
Output is correct |
28 |
Correct |
191 ms |
45564 KB |
Output is correct |
29 |
Correct |
147 ms |
47408 KB |
Output is correct |
30 |
Correct |
103 ms |
46976 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
218 ms |
27000 KB |
Output is correct |
33 |
Correct |
199 ms |
27060 KB |
Output is correct |
34 |
Correct |
176 ms |
47396 KB |
Output is correct |
35 |
Correct |
159 ms |
41416 KB |
Output is correct |
36 |
Correct |
225 ms |
27092 KB |
Output is correct |
37 |
Correct |
163 ms |
47420 KB |
Output is correct |
38 |
Correct |
166 ms |
47452 KB |
Output is correct |
39 |
Correct |
129 ms |
46912 KB |
Output is correct |
40 |
Correct |
139 ms |
34876 KB |
Output is correct |
41 |
Correct |
157 ms |
30116 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
286 ms |
27452 KB |
Output is correct |
44 |
Correct |
219 ms |
26796 KB |
Output is correct |
45 |
Correct |
217 ms |
26944 KB |
Output is correct |
46 |
Correct |
240 ms |
26804 KB |
Output is correct |
47 |
Correct |
183 ms |
27636 KB |
Output is correct |
48 |
Correct |
119 ms |
37424 KB |
Output is correct |
49 |
Correct |
120 ms |
47380 KB |
Output is correct |
50 |
Correct |
136 ms |
15468 KB |
Output is correct |
51 |
Correct |
202 ms |
26992 KB |
Output is correct |
52 |
Correct |
172 ms |
30048 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
596 KB |
Output is correct |
57 |
Correct |
1 ms |
596 KB |
Output is correct |
58 |
Correct |
2 ms |
468 KB |
Output is correct |
59 |
Correct |
1 ms |
596 KB |
Output is correct |
60 |
Correct |
1 ms |
468 KB |
Output is correct |
61 |
Correct |
1 ms |
724 KB |
Output is correct |
62 |
Correct |
2 ms |
468 KB |
Output is correct |
63 |
Correct |
2 ms |
468 KB |
Output is correct |
64 |
Correct |
1 ms |
468 KB |
Output is correct |
65 |
Correct |
1 ms |
724 KB |
Output is correct |
66 |
Correct |
2 ms |
596 KB |
Output is correct |
67 |
Correct |
143 ms |
34228 KB |
Output is correct |
68 |
Correct |
152 ms |
45632 KB |
Output is correct |
69 |
Correct |
208 ms |
26304 KB |
Output is correct |
70 |
Correct |
186 ms |
26824 KB |
Output is correct |
71 |
Correct |
194 ms |
26956 KB |
Output is correct |
72 |
Correct |
178 ms |
47508 KB |
Output is correct |
73 |
Correct |
182 ms |
26052 KB |
Output is correct |
74 |
Correct |
139 ms |
25224 KB |
Output is correct |
75 |
Correct |
145 ms |
48272 KB |
Output is correct |
76 |
Correct |
236 ms |
29956 KB |
Output is correct |
77 |
Correct |
159 ms |
47424 KB |
Output is correct |
78 |
Correct |
166 ms |
45576 KB |
Output is correct |
79 |
Correct |
155 ms |
47424 KB |
Output is correct |
80 |
Correct |
127 ms |
46912 KB |
Output is correct |
81 |
Correct |
212 ms |
26968 KB |
Output is correct |
82 |
Correct |
212 ms |
27060 KB |
Output is correct |
83 |
Correct |
170 ms |
47424 KB |
Output is correct |
84 |
Correct |
153 ms |
41384 KB |
Output is correct |
85 |
Correct |
194 ms |
27072 KB |
Output is correct |
86 |
Correct |
160 ms |
47452 KB |
Output is correct |
87 |
Correct |
181 ms |
47412 KB |
Output is correct |
88 |
Correct |
149 ms |
34884 KB |
Output is correct |
89 |
Correct |
160 ms |
30084 KB |
Output is correct |
90 |
Correct |
241 ms |
27440 KB |
Output is correct |
91 |
Correct |
225 ms |
26812 KB |
Output is correct |
92 |
Correct |
269 ms |
26976 KB |
Output is correct |
93 |
Correct |
235 ms |
26924 KB |
Output is correct |
94 |
Correct |
203 ms |
27656 KB |
Output is correct |
95 |
Correct |
144 ms |
37320 KB |
Output is correct |
96 |
Correct |
116 ms |
47420 KB |
Output is correct |
97 |
Correct |
134 ms |
15508 KB |
Output is correct |
98 |
Correct |
223 ms |
26948 KB |
Output is correct |
99 |
Correct |
170 ms |
30084 KB |
Output is correct |
100 |
Correct |
39 ms |
3264 KB |
Output is correct |
101 |
Correct |
267 ms |
26968 KB |
Output is correct |
102 |
Correct |
186 ms |
26508 KB |
Output is correct |
103 |
Correct |
230 ms |
27312 KB |
Output is correct |
104 |
Correct |
246 ms |
27992 KB |
Output is correct |