Submission #1136462

#TimeUsernameProblemLanguageResultExecution timeMemory
1136462imarnStranded Far From Home (BOI22_island)C++20
100 / 100
159 ms49548 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define plx pair<ll,int> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() #define vi vector<int> #define vvi vector<vi> #define pp pair<ll,int> #define ub(x,i) upper_bound(all(x),i)-x.begin() using namespace std; const int mxn=5e5+5,inf=1e9+7; vector<int>g[mxn],ans[mxn]; ll a[mxn]; ll s[mxn]{0}; int pr[mxn]{0}; bool vis[mxn]{0}; int get(int r){ return pr[r]==r?r:pr[r]=get(pr[r]); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n,m;cin>>n>>m;vector<pll>vx; for(int i=1;i<=n;i++)cin>>a[i],s[i]=a[i],pr[i]=i,vx.pb({a[i],i}),ans[i].pb(i); for(int i=1;i<=m;i++){ int a,b;cin>>a>>b;g[a].pb(b);g[b].pb(a); }sort(all(vx)); for(auto [w,u] : vx){ for(auto v:g[u]){ if(a[u]>=a[v]){ int x=get(v); int y=get(u); if(x==y)continue; if(s[x]>=a[u]){ pr[x]=y; s[y]+=s[x]; if(ans[x].size()>ans[y].size())swap(ans[x],ans[y]); for(auto it : ans[x])ans[y].pb(it); } else if(s[x]<a[u]){ pr[x]=y; s[y]+=s[x]; } } } } for(auto it : ans[get(vx.back().s)])vis[it]=1; for(int i=1;i<=n;i++)cout<<vis[i]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...