Submission #753861

#TimeUsernameProblemLanguageResultExecution timeMemory
753861jakobrsStranded Far From Home (BOI22_island)C++17
10 / 100
1058 ms16656 KiB
#include <iostream> #include <vector> #include <queue> #include <tuple> #include <utility> using i64 = int64_t; int main() { std::cin.tie(nullptr)->sync_with_stdio(false); i64 n, m; std::cin >> n >> m; std::vector<i64> a(n); for (i64 i = 0; i < n; i++) std::cin >> a[i]; std::vector<std::vector<i64>> adj(n); for (i64 i = 0; i < m; i++) { i64 u, v; std::cin >> u >> v; u--, v--; adj[u].push_back(v); adj[v].push_back(u); } std::string result; result.reserve(n); std::vector<i64> visited(n); for (i64 i = 0; i < n; i++) { struct Node { i64 size; i64 idx; bool operator<(const Node &rhs) const { return std::tie(rhs.size, idx) < std::tie(size, rhs.idx); } }; std::priority_queue<Node> q; std::fill(visited.begin(), visited.end(), false); visited[i] = true; i64 mass = a[i]; q.push(Node { .size = 0, .idx = i }); while (!q.empty()) { Node node = q.top(); if (node.size > mass) break; mass += node.size; q.pop(); for (i64 j : adj[node.idx]) { if (!visited[j]) { visited[j] = true; q.push(Node { .size = a[j], .idx = j }); } } } result.push_back(q.empty() ? '1' : '0'); } std::cout << result; }
#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...