Submission #695200

#TimeUsernameProblemLanguageResultExecution timeMemory
695200finn__Stranded Far From Home (BOI22_island)C++17
0 / 100
150 ms19248 KiB
#include <bits/stdc++.h> using namespace std; struct DSU { vector<int64_t> parent, weight; vector<bool> is_bad; DSU(size_t n, vector<int64_t> const &s) { parent = vector<int64_t>(n, -1); weight = vector<int64_t>(s.begin(), s.end()); is_bad = vector<bool>(n, 0); } void update_bad(int u) { if (parent[u] >= 0) { update_bad(parent[u]); is_bad[u] = is_bad[u] || is_bad[parent[u]]; } } int root(int u) { if (parent[u] < 0) return u; return parent[u] = root(parent[u]); } void merge(int u, int v) { update_bad(u); update_bad(v); u = root(u), v = root(v); if (u == v) return; if (parent[u] > parent[v]) swap(u, v); weight[u] += weight[v]; parent[u] += parent[v]; parent[v] = u; } void mark_bad(int u) { is_bad[root(u)] = 1; } int64_t component_weight(int u) { update_bad(u); return weight[root(u)]; } bool get_bad(int u) { update_bad(u); return is_bad[u]; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); size_t n, m; cin >> n >> m; vector<int64_t> s(n); for (int64_t &x : s) cin >> x; vector<pair<int64_t, unsigned>> nodes(n); for (size_t i = 0; i < n; i++) nodes[i] = {s[i], i}; sort(nodes.begin(), nodes.end()); vector<vector<unsigned>> g(n); for (size_t i = 0; i < m; i++) { unsigned u, v; cin >> u >> v; g[u - 1].push_back(v - 1); g[v - 1].push_back(u - 1); } DSU dsu(n, s); for (auto const &[x, u] : nodes) { for (unsigned const &v : g[u]) { if (s[v] <= x) { if (dsu.component_weight(v) >= x) dsu.merge(u, v); } } } for (int i = 0; i < n; i++) cout << (dsu.root(i) == dsu.root(nodes.back().second) ? 1 : 0); cout << '\n'; }

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:106:23: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for (int i = 0; i < n; 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...