Submission #722986

# Submission time Handle Problem Language Result Execution time Memory
722986 2023-04-13T06:53:52 Z Mr_Husanboy Stranded Far From Home (BOI22_island) C++17
0 / 100
1000 ms 13260 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

void solve(){
    int n, m; cin >> n >> m;
    vector<int> s(n);
    for(auto &u : s) cin >> u;
    vector<vector<int>> g(n);
    for(int i = 0; i < m; i ++){
        int u, v; cin >> u >> v;
        u --; v --;
        g[u].push_back(v); g[v].push_back(u);
    }
    auto check = [&](int i)->int{
        priority_queue<pair<int,int>> q;
        ll cur = s[i];
        vector<int> used(n);
        used[i] = 1;
        for(auto u : g[i]){
            q.push({-s[u], u});
        }
        //cout << i << ": " << cur << endl;
        while(!q.empty()){
            int t = q.top().second;
            q.pop();
            if(s[t] <= cur){
                cur += s[t];
            }else{
                return 0;
            }
            for(auto u : g[t]){
                if(used[u]) continue;
                used[u] = 1;
                q.push({-s[u], u});
            }   
        }
        return 1;
    };

    for(int i = 0; i < n; i ++){
        cout << check(i);   
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcases = 1;
    //cin >> testcases;
    while(testcases --){
        solve();
        if(testcases) cout << '\n';
        #ifdef LOCAL
        else cout << '\n';
        cout << "___________________" << endl;
        #endif
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 145 ms 416 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 1089 ms 13260 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1064 ms 12748 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1062 ms 12936 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 145 ms 416 KB Output isn't correct
5 Halted 0 ms 0 KB -