Submission #598566

#TimeUsernameProblemLanguageResultExecution timeMemory
598566someoneStranded Far From Home (BOI22_island)C++14
0 / 100
178 ms42120 KiB
#include <bits/stdc++.h> #define int long long using namespace std; struct Node { int id, nbHab; }; const int N = 2e5 + 42, MOD = 1e9 + 7; bool ans[N]; Node node[N]; set<int> win[N]; vector<int> adj[N]; int n, m, see = 1, par[N], sum[N], lastSeen[N]; int F(int i) { if(par[i] == i) return i; return par[i] = F(par[i]); } void U(int a, int b) { a = F(a), b = F(b); if(a == b) return; if(win[a].size() > win[b].size()) swap(a, b); par[a] = b; sum[b] += sum[a]; for(int i : win[a]) win[b].insert(i); } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0; i < n; i++) { node[i].id = i; cin >> node[i].nbHab; par[i] = i; win[i].insert(i); sum[i] = node[i].nbHab; } for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; if(a > b) swap(a, b); if(node[a].nbHab > node[b].nbHab) swap(a, b); adj[b].push_back(a); } sort(node, node + n, [](Node a, Node b) { if(a.nbHab == b.nbHab) return a.id < b.id; return a.nbHab < b.nbHab; }); for(int i = 0; i < n; i++) { see++; for(int j : adj[node[i].id]) { j = F(j); if(j == F(node[i].id) || lastSeen[j] != see) { lastSeen[j] = see; if(sum[j] >= node[i].nbHab) U(j, node[i].id); } } } for(int i : win[F(node[n-1].id)]) ans[i] = true; for(int i = 0; i < n; i++) cout << ans[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...