Submission #1109597

#TimeUsernameProblemLanguageResultExecution timeMemory
1109597dwuyStranded Far From Home (BOI22_island)C++14
100 / 100
187 ms43192 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MX = 200005; int f[MX]; int e[MX]; int n, m; int a[MX]; vector<int> ans[MX]; vector<int> G[MX]; int fp(int u){ return e[u] < 0? u : e[u] = fp(e[u]); } void unon(int u, int v){ u = fp(u); v = fp(v); if(u == v) return; if(e[u] > e[v]) swap(u, v); e[u] += e[v]; f[u] += f[v]; e[v] = u; f[v] = 0; if(ans[u].size() < ans[v].size()) swap(ans[u], ans[v]); for(int x: ans[v]) ans[u].push_back(x); ans[v].clear(); } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<=m; i++){ int u, v; cin >> u >> v; G[u].push_back(v); G[v].push_back(u); } vector<int> b(n); for(int i=1; i<=n; i++) b[i - 1] = i; sort(b.begin(), b.end(), [&](const int &i, const int &j) -> bool { return a[i] < a[j]; }); for(int i=1; i<=n; i++) f[i] = a[i]; for(int i=1; i<=n; i++) e[i] = -1; for(int i=1; i<=n; i++) ans[i].push_back(i); bitset<MX> active = 0; for(int u: b){ int cur = u; active[u] = 1; for(int v: G[u]) if(active[v] && cur != fp(v)){ v = fp(v); if(f[v] < a[u]) ans[v].clear(); unon(cur, v); cur = fp(cur); } } int u = fp(1); bitset<MX> homo = 0; for(int x: ans[u]) homo[x] =1; for(int i=1; i<=n; i++) cout << homo[i]; return 0; }
#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...