Submission #602203

#TimeUsernameProblemLanguageResultExecution timeMemory
602203VanillaStranded Far From Home (BOI22_island)C++17
10 / 100
1099 ms31596 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int64; const int maxn = 2e5 + 2; int a[maxn], dsu[maxn]; int64 sum[maxn]; vector <pair <int, int> > ad [maxn]; vector <int> comp [maxn]; int rs [maxn]; int dad (int x) { return dsu[x] = (x == dsu[x] ? x: dad(dsu[x])); } int main() { int n,m; cin >> n >> m; vector <pair <int, int> > v; for (int i = 1; i <= n; i++){ cin >> a[i]; dsu[i] = i; sum[i] = a[i]; comp[i].push_back(i); v.push_back({a[i], i}); } for (int i = 1; i <= m; i++){ int x,y; cin >> x >> y; ad[x].push_back({a[y], y}); ad[y].push_back({a[x], x}); } sort(v.begin(), v.end()); for (auto [val, x]: v) { sort(ad[x].rbegin(), ad[x].rend()); while (!ad[x].empty() && ad[x].back().first <= val) { int y = ad[x].back().second; int p1 = dad(x), p2 = dad(y); // cout << x << " " << y << p1 << " " << p2 << "\n"; if (val > sum[p2]) comp[p2].clear(); if (p1 != p2) { if (comp[p1].size() < comp[p2].size()) swap(p1, p2); dsu[p2] = p1; sum[p1] += sum[p2]; while (!comp[p2].empty()) { comp[p1].push_back(comp[p2].back()); comp[p2].pop_back(); } } ad[x].pop_back(); } } map <int, int> dd; for (int i = 1; i <= n; i++){ if (!dd.count(dad(i))) { dd[i] = 1; for (int j: comp[dad(i)]) rs[j] = 1; } } for (int i = 1; i <= n; i++) cout << rs[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...