#include<bits/stdc++.h>
using namespace std;
const int NN=2e5+1;
long long node[NN],sum[NN];
int par[NN];
bitset<NN> ans;
int fp(int i){
if(i==par[i]) return i;
int p=fp(par[i]);
if(!ans[par[i]]) ans[i]=ans[par[i]];
par[i]=p;
return p;
}
struct edl
{
int a,b;
bool operator < (const edl &rhs) const{
return max(node[a],node[b])<max(node[rhs.a],node[rhs.b]);
}
};
vector<edl> v;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n,m,a,b;
cin>>n>>m;
for(int i=1;i<=n;i++) {cin>>node[i],par[i]=i; sum[i]=node[i];}
while(m--){
cin>>a>>b;
v.push_back({a,b});
}
sort(v.begin(),v.end());
ans.set();
for(auto i:v){
int p1=fp(i.a);
int p2=fp(i.b);
if(p1==p2) continue;
// cout<<p1<<" "<<p2<<"\n";
if(sum[p1]<sum[p2]) swap(p1,p2);
if(node[p1]>node[p2]) ans[p2]=0;
par[p2]=p1;
sum[p1]+=sum[p2];
}
for(int i=1;i<=n;i++){
fp(i);
cout<<ans[i];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
89 ms |
8684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
75 ms |
8808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |