#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int sz=200005;
int n, m, sizel[sz], fa[sz];
int folk[sz], sm[sz];
bool ans[sz];
inline void init(){
for(int i=1; i<=n; ++i) sizel[i]=1, fa[i]=i, ans[i]=true;
return;
}
int find_set(int &v){
if(fa[v] == v)
return v;
if(!ans[fa[v]]) ans[v]=0;
return fa[v]=find_set(fa[v]);
}
//b->a
bool Union(int a, int b){
a = find_set(a);
b = find_set(b);
if(a ^ b){
if(folk[a]<folk[b]) swap(a,b);
if(folk[a]>sm[b]) ans[b]=0;
fa[b]=a;
sm[a]+=sm[b];
return true;
}
return false;
}
struct edge{
int a, b;
int maxf;
};
bool cmp(edge e1, edge e2){
return e1.maxf<e2.maxf;
}
vector<edge> e;
int a, b, maxf;
inline void Solution(){
cin>>n>>m;
init();
for(int i=1; i<=n; ++i){
cin>>folk[i];
}
for(int i=1; i<=m; ++i){
cin>>a>>b;
e.emplace_back((edge){a,b,max(folk[a], folk[b])});
}
sort(e.begin(), e.end(), cmp);
for(int i=0; i<m; ++i){
Union(e[i].a, e[i].b);
}
for(int i=1; i<=n; ++i) cout<<!ans[i];
return;
}
int main(){
ios_base::sync_with_stdio(false);
Solution();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |