Submission #1109513

# Submission time Handle Problem Language Result Execution time Memory
1109513 2024-11-07T01:02:46 Z Zero_OP Stranded Far From Home (BOI22_island) C++14
10 / 100
1000 ms 17172 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

#ifdef LOCAL
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
#endif // LOCAL

    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }

    vector<vector<int>> adj(N);
    while(M--){
        int u, v;
        cin >> u >> v;
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<bool> vis(N);
    auto solve = [&](int s) -> bool{
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
        fill(vis.begin(), vis.end(), false);

        long long have = a[s];
        vis[s] = true;
        for(int u : adj[s]){
            if(!vis[u]){
                vis[u] = true;
                pq.push({a[u], u});
            }
        }

        while(!pq.empty()){
            int demand, u;
            tie(demand, u) = pq.top(); pq.pop();
            if(demand > have) return false;
            have += demand;

            for(auto v : adj[u]){
                if(!vis[v]){
                    vis[v] = true;
                    pq.push({a[v], v});
                }
            }
        }

        return true;
    };

    for(int i = 0; i < N; ++i){
        cout << solve(i);
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 128 ms 592 KB Output is correct
5 Correct 106 ms 592 KB Output is correct
6 Correct 145 ms 336 KB Output is correct
7 Correct 122 ms 592 KB Output is correct
8 Correct 93 ms 336 KB Output is correct
9 Correct 130 ms 592 KB Output is correct
10 Correct 46 ms 508 KB Output is correct
11 Correct 44 ms 760 KB Output is correct
12 Correct 35 ms 592 KB Output is correct
13 Correct 85 ms 592 KB Output is correct
14 Correct 64 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Execution timed out 1088 ms 17172 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Execution timed out 1086 ms 16340 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Execution timed out 1083 ms 16748 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 128 ms 592 KB Output is correct
5 Correct 106 ms 592 KB Output is correct
6 Correct 145 ms 336 KB Output is correct
7 Correct 122 ms 592 KB Output is correct
8 Correct 93 ms 336 KB Output is correct
9 Correct 130 ms 592 KB Output is correct
10 Correct 46 ms 508 KB Output is correct
11 Correct 44 ms 760 KB Output is correct
12 Correct 35 ms 592 KB Output is correct
13 Correct 85 ms 592 KB Output is correct
14 Correct 64 ms 592 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Execution timed out 1088 ms 17172 KB Time limit exceeded
18 Halted 0 ms 0 KB -