#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,val[200010],tag[200010],subsum[200010],dsu[200010],ans[200010];
vector<ll> e[200010],te[200010];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
int f(int now){
if(dsu[now]!=now) dsu[now]=f(dsu[now]);
return dsu[now];
}
int onion(int a,int b){
a=f(a);
b=f(b);
if(a==b)return 0;
else dsu[b]=a,subsum[a]+=subsum[b];
}
void dfs(int now,int x){
ans[now]=x;
if(tag[now]==1)ans[now]=0;
for(auto ne:te[now]){
dfs(ne,ans[now]);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
int last=0;
for(int i=1;i<=n;i++)cin>>val[i],pq.push(make_pair(val[i],i)),dsu[i]=i,subsum[i]=val[i];
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
if(val[a]>val[b])e[a].push_back(b);
else e[b].push_back(a);
}
while(!pq.empty()){
auto x=pq.top();
pq.pop();
last=x.second;
for(auto ne:e[x.second]){
ne=f(ne);
if(ne==x.second)continue;
te[x.second].push_back(ne);
if(subsum[ne]<x.first)tag[ne]=1;
onion(x.second,ne);
}
}
dfs(last,1);
for(int i=1;i<=n;i++)cout<<ans[i];
cout<<"\n";
return 0;
}
Compilation message
island.cpp: In function 'int onion(int, int)':
island.cpp:15:28: warning: control reaches end of non-void function [-Wreturn-type]
15 | else dsu[b]=a,subsum[a]+=subsum[b];
| ~~~~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
19696 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
13 ms |
19584 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9720 KB |
Output is correct |
2 |
Runtime error |
86 ms |
45052 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9728 KB |
Output is correct |
2 |
Runtime error |
94 ms |
45272 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
19696 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |