답안 #1098914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098914 2024-10-10T10:14:42 Z crafticat Stranded Far From Home (BOI22_island) C++17
0 / 100
1000 ms 12976 KB
#include <bits/stdc++.h>

#include <utility>

using namespace std;
#define F0R(i, n) for (int i= 0; i < n;i++)
template<typename T>
using V = vector<T>;
using vi = V<int>;
using vvi = V<vi>;
#define pb push_back
using pi = pair<int, int>;
#define all(x) begin(x), end(x)
#define f first
#define s second
vvi g;

bool pos(int x, vi sum) {
    priority_queue<pi,V<pi>, greater<>> nodes;
    nodes.push({sum[x], x});
    int gs = 0;
    V<bool> vis(sum.size());
    int visited = 0;

    while (!nodes.empty()) {
        auto [nodeS, a] = nodes.top(); nodes.pop();
        if (vis[a]) continue;
        vis[a] = true;
        if (nodeS > gs && gs != 0) return false;
        gs += nodeS;
        visited++;

        for (auto child : g[a]) {
            if (vis[child]) continue;
            nodes.emplace(sum[child], child);
        }
    }

    return visited == sum.size() - 1;
}

int main() {
    int n, m; cin >> n >> m;
    vi init(n + 1);
    F0R(i, n)
        cin >> init[i + 1];

    g.resize(n + 1);

    F0R(i, m) {
        int a, b; cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }

    F0R(i, n)
        cout << pos(i + 1, init);
}

Compilation message

island.cpp: In function 'bool pos(int, vi)':
island.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     return visited == sum.size() - 1;
      |            ~~~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 2 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 1051 ms 12884 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1095 ms 12720 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1080 ms 12976 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 2 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -