#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
const int MAXN=200005;
int par[MAXN];
long long a[MAXN];
vector<int> all[MAXN];
vector<piii> edges;
int find(int x){
if(par[x]==x)return par[x];
return par[x]=find(par[x]);
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m,u,v;
cin >> n >> m;
for(int i=1;i<=n;i++){
cin >> a[i];
par[i]=i;
all[i].push_back(i);
}
for(int i=1;i<=m;i++){
cin >> u >> v;
if(a[u]>a[v])edges.push_back({a[u],{u,v}});
else edges.push_back({a[v],{v,u}});
}
sort(edges.begin(),edges.end());
for(auto isi : edges){
int aa=find(isi.second.first),bb=find(isi.second.second);
if(aa==bb)continue;
if(a[bb]>=isi.first){
if(all[aa].size()<all[bb].size())all[aa].swap(all[bb]);
for(auto isi : all[bb])all[aa].push_back(isi);
}
a[bb]+=a[aa];
par[aa]=bb;
}
string ans="";
for(int i=0;i<n;i++)ans+='0';
for(auto isi : all[find(1)]){
ans[isi-1]='1';
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
138 ms |
16684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
153 ms |
16736 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |