Submission #586500

#TimeUsernameProblemLanguageResultExecution timeMemory
586500MeloricStranded Far From Home (BOI22_island)C++14
100 / 100
239 ms36308 KiB
#include <bits/stdc++.h> #define pb push_back #define int int64_t #define pii pair<int, int> #define X first #define Y second #define all(x) (x).begin(),(x).end() #define lb lower_bound #define ub upper_bound using namespace std; const int inf = 1e18; void p(auto A){ for(auto e : A)cout << e << ' '; cout << '\n'; } void solve(){ int n, m; cin >> n >> m; vector<int>A(n); for(int i = 0; i< n; i++)cin >> A[i]; vector<vector<int>> g(n); for(int i = 0; i< m; i++){ int c, d; cin >> c >> d; c--; d--; g[c].pb(d); g[d].pb(c); } vector<int> par(n, -1); auto find = [&](auto&& self, int u)->int{ return par[u] < 0 ? u : par[u] = self(self, par[u]); }; auto uni = [&](int u, int v)->bool{ u = find(find, u); v = find(find, v); if(u == v)return false; par[u] += par[v]; par[v] = u; return true; }; vector<int> per(n); iota(all(per), 0); sort(all(per), [&](int i, int j)->bool{return A[i] < A[j];}); vector<vector<int>> tre(n); vector<int> vis(n); for(auto u : per){ vis[u] = 1; for(auto v : g[u])if(vis[v])if(find(find, v) != u){ tre[u].pb(find(find,v)); uni(u, v); } } vector<int>B = A; for(auto u : per)for(auto v : tre[u])B[u] += B[v]; reverse(all(per)); vector<int> ans(n); ans[per[0]] = 1; for(auto u : per)for(auto v : tre[u])if(B[v] >= A[u])ans[v] = ans[u]; for(auto e : ans)cout << e; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin >> t; while(t--)solve(); }

Compilation message (stderr)

island.cpp:15:8: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   15 | void p(auto A){
      |        ^~~~
#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...