Submission #1098977

#TimeUsernameProblemLanguageResultExecution timeMemory
1098977razivoStranded Far From Home (BOI22_island)C++14
0 / 100
192 ms33040 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; long long find(long long p, vector<long long> &dsu) { if(p==dsu[p]) return p; long long u = find(dsu[p],dsu); dsu[p]=u; return u; } void un(long long a,long long b,vector<long long> &dsu,vector<long long> &ev,vector<long long> &maxv,vector<vector<long long>> &group) { a=find(a,dsu); b=find(b,dsu); if(maxv[a]>ev[b]) group[b].clear(); if(maxv[b]>ev[a]) group[a].clear(); if(group[a].size()>group[b].size()) swap(a,b); dsu[a]=b; maxv[b]=max(maxv[b],maxv[a]); ev[b]+=ev[a]; } int main() { long long n,m; cin>>n>>m; vector<long long> v(n),ev(n),dsu(n),maxv(n); vector<vector<long long>> group(n); vector<pair<long long,long long>> s; for (long long i = 0; i < n; ++i) { long long x; cin>>x; ev[i]=x; maxv[i]=x; group[i].push_back(x); v[i]=x; s.push_back({x,i}); dsu[i]=i; } sort(s.begin(), s.end()); vector<pair<pair<long long,long long>,pair<long long,long long>>> ed; for (long long i = 0; i < m; ++i) { long long x,y; cin>>x>>y; x--; y--; if(v[x]>v[y]) swap(x,y); ed.push_back({{v[x],v[y]},{x,y}}); } sort(ed.begin(),ed.end()); for (auto [u,t]:ed) { auto [a,b] = t; if(ev[find(a,dsu)]>=v[b]) un(a,b,dsu,ev,maxv,group); } long long ma = find(s[n-1].second,dsu); for (long long i = 0; i < n; ++i) { if(ma==find(i,dsu))cout<<"1"; else cout<<"0"; } }

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:45:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |     for (auto [u,t]:ed) {
      |               ^
island.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |         auto [a,b] = t;
      |              ^
#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...