Submission #599396

# Submission time Handle Problem Language Result Execution time Memory
599396 2022-07-19T13:38:12 Z SlavicG Stranded Far From Home (BOI22_island) C++17
0 / 100
7 ms 724 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;
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 s.empty();
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
        cin >> 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";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 4 ms 424 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Runtime error 7 ms 724 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 7 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 7 ms 684 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 4 ms 424 KB Output isn't correct
5 Halted 0 ms 0 KB -