답안 #753855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753855 2023-06-06T08:27:05 Z jakobrs Stranded Far From Home (BOI22_island) C++17
0 / 100
1000 ms 20000 KB
#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[i]) {
                if (!visited[j]) {
                    visited[j] = true;
                    q.push(Node { .size = a[j], .idx = j });
                }
            }
        }

        result.push_back(q.empty() ? '1' : '0');
    }

    std::cout << result;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 2 ms 496 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1074 ms 20000 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1068 ms 18888 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Execution timed out 1060 ms 19836 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 2 ms 496 KB Output isn't correct
5 Halted 0 ms 0 KB -