Submission #1098866

#TimeUsernameProblemLanguageResultExecution timeMemory
1098866not_amirStranded Far From Home (BOI22_island)C++14
100 / 100
113 ms21452 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<pii> village(n); vector<vector<int>> G(n + 1); vector<int> parent(n + 1), parent1(n + 1); vector<ll> vsize(n + 1); for(int i = 1; i <= n; i++) { int a; cin >> a; village[i - 1] = {a, i}; parent1[i] = parent[i] = i; } sort(village.begin(), village.end()); for(int i = 1; i <= m; i++) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } vector<bool> visited(n + 1); for(auto [vs, v] : village) { vsize[v] = vs; visited[v] = true; for(int u : G[v]) { if(!visited[u]) continue; while(u != parent[u]) u = parent[u] = parent[parent[u]]; if(u == v) continue; vsize[v] += vsize[u]; parent[u] = v; if(vsize[u] >= vs) parent1[u] = v; } } int v = village.back().second; for(int i = 1; i <= n; i++) { int u = i; while(u != parent1[u]) u = parent1[u] = parent1[parent1[u]]; if(u == v) cout << '1'; else cout << '0'; } }

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:30:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |     for(auto [vs, v] : village) {
      |              ^
#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...