#include<bits/stdc++.h>
using namespace std;
const int NN=2e5+1;
long long node[NN];
int par[NN];
bitset<NN> ans;
int fp(int i){
if(i==par[i]) return i;
int p=fp(par[i]);
if(ans[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;
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(node[p1]<node[p2]) swap(p1,p2);
if(node[p1]>node[p2]) ans[p2]=0;
par[p2]=p1;
node[p1]+=node[p2];
}
for(int i=1;i<=n;i++){
fp(i);
cout<<ans[i];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
74 ms |
8936 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
83 ms |
9156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
73 ms |
8920 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |