#include<bits/stdc++.h>
#define MAXN 200007
using namespace std;
int n,m,a,b,curr;
long long s[MAXN];
vector<int> v[MAXN];
int p[MAXN],dsu[MAXN];
long long sz[MAXN];
vector<int> can[MAXN];
bool in[MAXN],notok[MAXN];
bool cmp(int x,int y){
return s[x]<s[y];
}
int root(int x){
if(dsu[x]==x)return dsu[x];
dsu[x]=root(dsu[x]);
return dsu[x];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>s[i];
p[i]=i; dsu[i]=i;
sz[i]=s[i]; can[i]={i};
}
sort(p+1,p+n+1,cmp);
for(int i=1;i<=m;i++){
cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
}
for(int i=1;i<=n;i++){
curr=p[i];
for(int f:v[curr]){
if(!in[f] or root(curr)==root(f))continue;
if(sz[root(f)]<s[curr]){
for(int k:can[root(f)])notok[k]=true;
can[root(f)].clear();
}
if(can[root(f)].size()<can[root(curr)].size()){
for(int k:can[root(f)])can[root(curr)].push_back(k);
sz[root(curr)]+=sz[root(f)];
dsu[root(f)]=root(curr);
}else{
for(int k:can[root(curr)])can[root(f)].push_back(k);
sz[root(f)]+=sz[root(curr)];
dsu[root(curr)]=root(f);
}
}
in[curr]=true;
}
for(int i=1;i<=n;i++){
if(notok[i])cout<<0;
else cout<<1;
}
cout<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
9 ms |
9812 KB |
Output is correct |
5 |
Correct |
7 ms |
9940 KB |
Output is correct |
6 |
Correct |
8 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
8 ms |
9864 KB |
Output is correct |
9 |
Correct |
6 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
7 ms |
9912 KB |
Output is correct |
12 |
Correct |
6 ms |
9940 KB |
Output is correct |
13 |
Correct |
6 ms |
9868 KB |
Output is correct |
14 |
Correct |
6 ms |
9940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
161 ms |
28588 KB |
Output is correct |
4 |
Correct |
159 ms |
31416 KB |
Output is correct |
5 |
Correct |
193 ms |
29720 KB |
Output is correct |
6 |
Correct |
226 ms |
30476 KB |
Output is correct |
7 |
Correct |
181 ms |
30288 KB |
Output is correct |
8 |
Correct |
180 ms |
29488 KB |
Output is correct |
9 |
Correct |
180 ms |
31552 KB |
Output is correct |
10 |
Correct |
160 ms |
28188 KB |
Output is correct |
11 |
Correct |
116 ms |
29352 KB |
Output is correct |
12 |
Correct |
172 ms |
29196 KB |
Output is correct |
13 |
Correct |
172 ms |
31884 KB |
Output is correct |
14 |
Correct |
169 ms |
31552 KB |
Output is correct |
15 |
Correct |
143 ms |
28188 KB |
Output is correct |
16 |
Correct |
96 ms |
28048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
226 ms |
31036 KB |
Output is correct |
3 |
Correct |
255 ms |
31140 KB |
Output is correct |
4 |
Correct |
155 ms |
31856 KB |
Output is correct |
5 |
Correct |
156 ms |
31844 KB |
Output is correct |
6 |
Correct |
244 ms |
31284 KB |
Output is correct |
7 |
Correct |
166 ms |
28152 KB |
Output is correct |
8 |
Correct |
161 ms |
28228 KB |
Output is correct |
9 |
Correct |
95 ms |
27972 KB |
Output is correct |
10 |
Correct |
153 ms |
29420 KB |
Output is correct |
11 |
Correct |
193 ms |
30764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
209 ms |
29008 KB |
Output is correct |
3 |
Correct |
226 ms |
29528 KB |
Output is correct |
4 |
Correct |
260 ms |
30260 KB |
Output is correct |
5 |
Correct |
188 ms |
30996 KB |
Output is correct |
6 |
Correct |
170 ms |
28612 KB |
Output is correct |
7 |
Correct |
127 ms |
29336 KB |
Output is correct |
8 |
Correct |
116 ms |
30096 KB |
Output is correct |
9 |
Correct |
108 ms |
20332 KB |
Output is correct |
10 |
Correct |
184 ms |
32040 KB |
Output is correct |
11 |
Correct |
181 ms |
31000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
9 ms |
9812 KB |
Output is correct |
5 |
Correct |
7 ms |
9940 KB |
Output is correct |
6 |
Correct |
8 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
8 ms |
9864 KB |
Output is correct |
9 |
Correct |
6 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
7 ms |
9912 KB |
Output is correct |
12 |
Correct |
6 ms |
9940 KB |
Output is correct |
13 |
Correct |
6 ms |
9868 KB |
Output is correct |
14 |
Correct |
6 ms |
9940 KB |
Output is correct |
15 |
Correct |
8 ms |
9684 KB |
Output is correct |
16 |
Correct |
6 ms |
9684 KB |
Output is correct |
17 |
Correct |
161 ms |
28588 KB |
Output is correct |
18 |
Correct |
159 ms |
31416 KB |
Output is correct |
19 |
Correct |
193 ms |
29720 KB |
Output is correct |
20 |
Correct |
226 ms |
30476 KB |
Output is correct |
21 |
Correct |
181 ms |
30288 KB |
Output is correct |
22 |
Correct |
180 ms |
29488 KB |
Output is correct |
23 |
Correct |
180 ms |
31552 KB |
Output is correct |
24 |
Correct |
160 ms |
28188 KB |
Output is correct |
25 |
Correct |
116 ms |
29352 KB |
Output is correct |
26 |
Correct |
172 ms |
29196 KB |
Output is correct |
27 |
Correct |
172 ms |
31884 KB |
Output is correct |
28 |
Correct |
169 ms |
31552 KB |
Output is correct |
29 |
Correct |
143 ms |
28188 KB |
Output is correct |
30 |
Correct |
96 ms |
28048 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
226 ms |
31036 KB |
Output is correct |
33 |
Correct |
255 ms |
31140 KB |
Output is correct |
34 |
Correct |
155 ms |
31856 KB |
Output is correct |
35 |
Correct |
156 ms |
31844 KB |
Output is correct |
36 |
Correct |
244 ms |
31284 KB |
Output is correct |
37 |
Correct |
166 ms |
28152 KB |
Output is correct |
38 |
Correct |
161 ms |
28228 KB |
Output is correct |
39 |
Correct |
95 ms |
27972 KB |
Output is correct |
40 |
Correct |
153 ms |
29420 KB |
Output is correct |
41 |
Correct |
193 ms |
30764 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
209 ms |
29008 KB |
Output is correct |
44 |
Correct |
226 ms |
29528 KB |
Output is correct |
45 |
Correct |
260 ms |
30260 KB |
Output is correct |
46 |
Correct |
188 ms |
30996 KB |
Output is correct |
47 |
Correct |
170 ms |
28612 KB |
Output is correct |
48 |
Correct |
127 ms |
29336 KB |
Output is correct |
49 |
Correct |
116 ms |
30096 KB |
Output is correct |
50 |
Correct |
108 ms |
20332 KB |
Output is correct |
51 |
Correct |
184 ms |
32040 KB |
Output is correct |
52 |
Correct |
181 ms |
31000 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9624 KB |
Output is correct |
55 |
Correct |
5 ms |
9732 KB |
Output is correct |
56 |
Correct |
6 ms |
9812 KB |
Output is correct |
57 |
Correct |
6 ms |
9940 KB |
Output is correct |
58 |
Correct |
7 ms |
9812 KB |
Output is correct |
59 |
Correct |
6 ms |
9812 KB |
Output is correct |
60 |
Correct |
6 ms |
9812 KB |
Output is correct |
61 |
Correct |
6 ms |
9812 KB |
Output is correct |
62 |
Correct |
7 ms |
9940 KB |
Output is correct |
63 |
Correct |
7 ms |
9932 KB |
Output is correct |
64 |
Correct |
7 ms |
9940 KB |
Output is correct |
65 |
Correct |
7 ms |
9960 KB |
Output is correct |
66 |
Correct |
6 ms |
9940 KB |
Output is correct |
67 |
Correct |
157 ms |
28540 KB |
Output is correct |
68 |
Correct |
152 ms |
31364 KB |
Output is correct |
69 |
Correct |
202 ms |
29780 KB |
Output is correct |
70 |
Correct |
211 ms |
30532 KB |
Output is correct |
71 |
Correct |
191 ms |
30456 KB |
Output is correct |
72 |
Correct |
187 ms |
29436 KB |
Output is correct |
73 |
Correct |
158 ms |
31472 KB |
Output is correct |
74 |
Correct |
156 ms |
28212 KB |
Output is correct |
75 |
Correct |
119 ms |
29392 KB |
Output is correct |
76 |
Correct |
193 ms |
29156 KB |
Output is correct |
77 |
Correct |
159 ms |
31964 KB |
Output is correct |
78 |
Correct |
157 ms |
31452 KB |
Output is correct |
79 |
Correct |
142 ms |
28228 KB |
Output is correct |
80 |
Correct |
101 ms |
28060 KB |
Output is correct |
81 |
Correct |
226 ms |
31072 KB |
Output is correct |
82 |
Correct |
216 ms |
31132 KB |
Output is correct |
83 |
Correct |
178 ms |
31824 KB |
Output is correct |
84 |
Correct |
150 ms |
31804 KB |
Output is correct |
85 |
Correct |
214 ms |
31168 KB |
Output is correct |
86 |
Correct |
171 ms |
28276 KB |
Output is correct |
87 |
Correct |
165 ms |
28212 KB |
Output is correct |
88 |
Correct |
149 ms |
29500 KB |
Output is correct |
89 |
Correct |
167 ms |
30804 KB |
Output is correct |
90 |
Correct |
229 ms |
28920 KB |
Output is correct |
91 |
Correct |
212 ms |
29548 KB |
Output is correct |
92 |
Correct |
216 ms |
30312 KB |
Output is correct |
93 |
Correct |
260 ms |
31040 KB |
Output is correct |
94 |
Correct |
170 ms |
28628 KB |
Output is correct |
95 |
Correct |
124 ms |
29360 KB |
Output is correct |
96 |
Correct |
112 ms |
30024 KB |
Output is correct |
97 |
Correct |
105 ms |
20328 KB |
Output is correct |
98 |
Correct |
222 ms |
32168 KB |
Output is correct |
99 |
Correct |
169 ms |
30960 KB |
Output is correct |
100 |
Correct |
40 ms |
12252 KB |
Output is correct |
101 |
Correct |
236 ms |
29636 KB |
Output is correct |
102 |
Correct |
170 ms |
25044 KB |
Output is correct |
103 |
Correct |
182 ms |
25372 KB |
Output is correct |
104 |
Correct |
223 ms |
28436 KB |
Output is correct |