#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,tag[200010],subsum[200010],dsu[200010],ans[200010],vis[200010];
vector<ll> e[200010],te[200010];
pair<ll,ll> val[200010];
int f(int a){
if(dsu[a]!=a){
dsu[a]=f(dsu[a]);
return dsu[a];
}else{
return a;
}
}
void dfs(int now,int x){
vis[now]=1;
tag[now]==1?ans[now]=0:ans[now]=x;
for(auto ne:te[now]){
dfs(ne,ans[now]);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>val[i].first;
val[i].second=i;
dsu[i]=i;
subsum[i]=val[i].first;
}
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
if(a>b)swap(a,b);
if(val[a].first>val[b].first)e[a].push_back(b);
else e[b].push_back(a);
}
sort(&val[1],&val[n+1]);
for(int i=1;i<=n;i++){
ll x=val[i].second;
ll y=val[i].first;
cout<<x<<" "<<y<<"\n";
for(auto ne:e[x]){
ne=f(ne);
if(ne==x)continue;
te[x].push_back(ne);
if(subsum[ne]<y)tag[ne]=1;
dsu[ne]=x;
subsum[x]+=subsum[ne];
}
}
for(int i=n;i>0;i--){
if(vis[val[i].second]==0)dfs(val[i].second,1);
}
for(int i=1;i<=n;i++)cout<<ans[i];
cout<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |