답안 #599401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
599401 2022-07-19T13:40:50 Z SlavicG Stranded Far From Home (BOI22_island) C++17
0 / 100
8 ms 480 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const int N = 2005;
vector<int> adj[N];
int a[N], n, m;
ll sum = 0;
bool possible(int start) {
    set<pair<int, int>> s;
    vector<bool> vis(n, false);
    for(auto x: adj[start]) {
        s.insert({a[x], x});
    }
    int cnt = a[start];
    vis[start] = true;
    while(!s.empty()) {
        auto it = s.begin();
        if(it->first > cnt) break;
        cnt += it->first;
        int v = it->second;
        vis[v] = true;
        s.erase(it);
        for(auto x: adj[v]) {
            if(!vis[x]) {
                s.insert({a[x], x});
                vis[x] = true;
            }
        }
    }
    return cnt == sum;
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    for(int i = 0; i < m; ++i) {
        int u, v; cin >> u >> v; --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 0; i < n; ++i) cout << possible(i);
    cout << "\n";
}
# 결과 실행 시간 메모리 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 3 ms 340 KB Output isn't correct
5 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 Runtime error 6 ms 468 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 6 ms 468 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 8 ms 480 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 3 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -