답안 #587124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587124 2022-07-01T10:55:35 Z proma Stranded Far From Home (BOI22_island) C++17
0 / 100
53 ms 596 KB
#include <bits/stdc++.h>

#define int long long
#define see(x) cout<<#x<<"="<<x<<"\n";
#define endl "\n"

using namespace std;

const int N = 2005;

int n, m, s[N], used[N];
vector <int> g[N];


void bfs(int v) {
    memset(used, 0, sizeof(used));
    queue <int> q;
    q.push(v);
    used[v] = 1;
    int sum = s[v];
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto i: g[v]) {
            if (!used[i] and sum >= s[i]) {
                sum += s[i];
                used[i] = 1;
                q.push(i);
            }
        }
        for (auto i: g[v]) {
            if (!used[i] and sum >= s[i]) {
                sum += s[i];
                used[i] = 1;
                q.push(i);
            }
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
/*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
*/

    cin >> n >> m;

    for (int i = 1; i <= n; i ++) {
        cin >> s[i];
    }

    for (int i = 0; i < m; i ++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    for (int i = 1; i <= n; i ++) {
        bfs(i);
        int cnt = 0;
        for (int j = 1; j <= n; j ++) {
            cnt += used[j];
        }
        if (cnt == n) cout << "1";
        else cout << "0";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 53 ms 476 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Runtime error 1 ms 596 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 1 ms 596 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 1 ms 520 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 53 ms 476 KB Output isn't correct
5 Halted 0 ms 0 KB -