이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
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];
| ~~~~~~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |