#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<P> vp;
typedef vector<vp> vvp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define pb emplace_back
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){for(auto x:v)outv(x);}
template<class T> void outvp(T v){rep(i,v.size()){cout<<'('<<v[i].fi<<','<<v[i].se<<')';}cout<<endl;}
template<class T> void outvvp(T v){for(auto x:v)outvp(x);}
struct UF{
vi par;
UF(ll n):par(n,-1){}
ll root(ll i){
if(par[i]==-1)return i;
par[i]=root(par[i]);
return par[i];
}
};
int main(){
ll n,m;cin>>n>>m;
vi v(n);rep(i,n)cin>>v[i];
vector<PP> srt(m);
rep(i,m){
ll a,b;cin>>a>>b;a--;b--;
if(P(v[a],a)<P(v[b],b))swap(a,b);
srt[i]=PP(v[a],a,b);
}
sort(all(srt));
UF uf(n);
vvi ch(n);
for(auto x:srt){
ll t,a,b;tie(t,a,b)=x;
b=uf.root(b);
if(a==b)continue;
ch[a].pb(b);
uf.par[b]=a;
}
ll rt=uf.root(0);
vi sub(n);
auto dfs=[&](auto && self,ll i) -> void {
sub[i]=v[i];
for(ll x:ch[i]){
self(self,x);
sub[i]+=sub[x];
}
};dfs(dfs,rt);
string ans(n,'0');
auto dfs2=[&](auto && self,ll i) -> void {
ans[i]='1';
for(ll x:ch[i])if(sub[x]>=v[i]){
self(self,x);
}
};dfs2(dfs2,rt);
out(ans);
}
# |
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 |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
222 ms |
21700 KB |
Output is correct |
4 |
Correct |
174 ms |
26524 KB |
Output is correct |
5 |
Correct |
252 ms |
18508 KB |
Output is correct |
6 |
Correct |
271 ms |
19080 KB |
Output is correct |
7 |
Correct |
273 ms |
19268 KB |
Output is correct |
8 |
Correct |
235 ms |
27028 KB |
Output is correct |
9 |
Correct |
203 ms |
17976 KB |
Output is correct |
10 |
Correct |
182 ms |
16444 KB |
Output is correct |
11 |
Correct |
182 ms |
27028 KB |
Output is correct |
12 |
Correct |
229 ms |
21276 KB |
Output is correct |
13 |
Correct |
203 ms |
27144 KB |
Output is correct |
14 |
Correct |
177 ms |
26516 KB |
Output is correct |
15 |
Correct |
227 ms |
27148 KB |
Output is correct |
16 |
Correct |
174 ms |
26956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
241 ms |
18928 KB |
Output is correct |
3 |
Correct |
236 ms |
19092 KB |
Output is correct |
4 |
Correct |
221 ms |
27068 KB |
Output is correct |
5 |
Correct |
164 ms |
25168 KB |
Output is correct |
6 |
Correct |
248 ms |
19096 KB |
Output is correct |
7 |
Correct |
223 ms |
27064 KB |
Output is correct |
8 |
Correct |
233 ms |
31516 KB |
Output is correct |
9 |
Correct |
176 ms |
30508 KB |
Output is correct |
10 |
Correct |
203 ms |
24796 KB |
Output is correct |
11 |
Correct |
178 ms |
23244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
284 ms |
19524 KB |
Output is correct |
3 |
Correct |
265 ms |
19268 KB |
Output is correct |
4 |
Correct |
266 ms |
19224 KB |
Output is correct |
5 |
Correct |
344 ms |
19400 KB |
Output is correct |
6 |
Correct |
247 ms |
19148 KB |
Output is correct |
7 |
Correct |
219 ms |
22300 KB |
Output is correct |
8 |
Correct |
185 ms |
27076 KB |
Output is correct |
9 |
Correct |
156 ms |
12808 KB |
Output is correct |
10 |
Correct |
210 ms |
19220 KB |
Output is correct |
11 |
Correct |
182 ms |
20248 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 |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
222 ms |
21700 KB |
Output is correct |
18 |
Correct |
174 ms |
26524 KB |
Output is correct |
19 |
Correct |
252 ms |
18508 KB |
Output is correct |
20 |
Correct |
271 ms |
19080 KB |
Output is correct |
21 |
Correct |
273 ms |
19268 KB |
Output is correct |
22 |
Correct |
235 ms |
27028 KB |
Output is correct |
23 |
Correct |
203 ms |
17976 KB |
Output is correct |
24 |
Correct |
182 ms |
16444 KB |
Output is correct |
25 |
Correct |
182 ms |
27028 KB |
Output is correct |
26 |
Correct |
229 ms |
21276 KB |
Output is correct |
27 |
Correct |
203 ms |
27144 KB |
Output is correct |
28 |
Correct |
177 ms |
26516 KB |
Output is correct |
29 |
Correct |
227 ms |
27148 KB |
Output is correct |
30 |
Correct |
174 ms |
26956 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
241 ms |
18928 KB |
Output is correct |
33 |
Correct |
236 ms |
19092 KB |
Output is correct |
34 |
Correct |
221 ms |
27068 KB |
Output is correct |
35 |
Correct |
164 ms |
25168 KB |
Output is correct |
36 |
Correct |
248 ms |
19096 KB |
Output is correct |
37 |
Correct |
223 ms |
27064 KB |
Output is correct |
38 |
Correct |
233 ms |
31516 KB |
Output is correct |
39 |
Correct |
176 ms |
30508 KB |
Output is correct |
40 |
Correct |
203 ms |
24796 KB |
Output is correct |
41 |
Correct |
178 ms |
23244 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
284 ms |
19524 KB |
Output is correct |
44 |
Correct |
265 ms |
19268 KB |
Output is correct |
45 |
Correct |
266 ms |
19224 KB |
Output is correct |
46 |
Correct |
344 ms |
19400 KB |
Output is correct |
47 |
Correct |
247 ms |
19148 KB |
Output is correct |
48 |
Correct |
219 ms |
22300 KB |
Output is correct |
49 |
Correct |
185 ms |
27076 KB |
Output is correct |
50 |
Correct |
156 ms |
12808 KB |
Output is correct |
51 |
Correct |
210 ms |
19220 KB |
Output is correct |
52 |
Correct |
182 ms |
20248 KB |
Output is correct |
53 |
Correct |
1 ms |
304 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
2 ms |
468 KB |
Output is correct |
57 |
Correct |
3 ms |
468 KB |
Output is correct |
58 |
Correct |
2 ms |
468 KB |
Output is correct |
59 |
Correct |
3 ms |
468 KB |
Output is correct |
60 |
Correct |
2 ms |
468 KB |
Output is correct |
61 |
Correct |
2 ms |
468 KB |
Output is correct |
62 |
Correct |
3 ms |
468 KB |
Output is correct |
63 |
Correct |
3 ms |
468 KB |
Output is correct |
64 |
Correct |
3 ms |
508 KB |
Output is correct |
65 |
Correct |
2 ms |
564 KB |
Output is correct |
66 |
Correct |
2 ms |
432 KB |
Output is correct |
67 |
Correct |
220 ms |
26160 KB |
Output is correct |
68 |
Correct |
198 ms |
29624 KB |
Output is correct |
69 |
Correct |
264 ms |
22904 KB |
Output is correct |
70 |
Correct |
268 ms |
23476 KB |
Output is correct |
71 |
Correct |
281 ms |
23596 KB |
Output is correct |
72 |
Correct |
234 ms |
31440 KB |
Output is correct |
73 |
Correct |
205 ms |
22332 KB |
Output is correct |
74 |
Correct |
191 ms |
20132 KB |
Output is correct |
75 |
Correct |
201 ms |
30504 KB |
Output is correct |
76 |
Correct |
211 ms |
24344 KB |
Output is correct |
77 |
Correct |
179 ms |
30012 KB |
Output is correct |
78 |
Correct |
186 ms |
29580 KB |
Output is correct |
79 |
Correct |
234 ms |
31516 KB |
Output is correct |
80 |
Correct |
186 ms |
30540 KB |
Output is correct |
81 |
Correct |
232 ms |
23336 KB |
Output is correct |
82 |
Correct |
245 ms |
23600 KB |
Output is correct |
83 |
Correct |
262 ms |
31620 KB |
Output is correct |
84 |
Correct |
200 ms |
28040 KB |
Output is correct |
85 |
Correct |
245 ms |
23556 KB |
Output is correct |
86 |
Correct |
238 ms |
31532 KB |
Output is correct |
87 |
Correct |
238 ms |
31492 KB |
Output is correct |
88 |
Correct |
223 ms |
24748 KB |
Output is correct |
89 |
Correct |
224 ms |
23224 KB |
Output is correct |
90 |
Correct |
299 ms |
23884 KB |
Output is correct |
91 |
Correct |
299 ms |
23528 KB |
Output is correct |
92 |
Correct |
286 ms |
23668 KB |
Output is correct |
93 |
Correct |
286 ms |
23612 KB |
Output is correct |
94 |
Correct |
272 ms |
23500 KB |
Output is correct |
95 |
Correct |
232 ms |
26748 KB |
Output is correct |
96 |
Correct |
224 ms |
30340 KB |
Output is correct |
97 |
Correct |
192 ms |
15408 KB |
Output is correct |
98 |
Correct |
243 ms |
22068 KB |
Output is correct |
99 |
Correct |
257 ms |
23176 KB |
Output is correct |
100 |
Correct |
139 ms |
7316 KB |
Output is correct |
101 |
Correct |
328 ms |
23692 KB |
Output is correct |
102 |
Correct |
251 ms |
21808 KB |
Output is correct |
103 |
Correct |
298 ms |
22532 KB |
Output is correct |
104 |
Correct |
317 ms |
24008 KB |
Output is correct |