#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];
}
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])continue;
if(sz[root(f)]<s[curr]){
for(int k:can[root(f)])notok[k]=true;
can[root(f)].clear();
}
sz[root(curr)]+=sz[root(f)];
dsu[root(f)]=root(curr);
}
can[root(curr)].push_back(curr);
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 |
5 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 |
Incorrect |
7 ms |
9812 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
146 ms |
27480 KB |
Output is correct |
4 |
Incorrect |
150 ms |
27288 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
220 ms |
27420 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
218 ms |
27388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 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 |
Incorrect |
7 ms |
9812 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |