답안 #723065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723065 2023-04-13T08:11:51 Z Mr_Husanboy Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 13408 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});
            used[u] = 1;
        }
        int cnt = 1;
        while(!q.empty()){
            int t = q.top().second;
            q.pop();
            //cout << t + 1 << endl;
            if(s[t] <= cur){
                cur += s[t];
                cnt ++;
            }else{
                return 0;
            }

            for(auto u : g[t]){
                if(used[u]) continue;
                used[u] = 1;
                q.push({-s[u], u});
            }
        }
        //for(auto u : used) cout << u << ' '; cout<< endl;
        return cnt == n;
    };

    for(int i = 0; i < n; i ++){
        cout << check(i);
        #ifdef LOCAL 
        cout << endl; 
        #endif 
    }
}

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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 153 ms 340 KB Output is correct
5 Correct 144 ms 428 KB Output is correct
6 Correct 218 ms 460 KB Output is correct
7 Correct 151 ms 412 KB Output is correct
8 Correct 103 ms 396 KB Output is correct
9 Correct 210 ms 340 KB Output is correct
10 Correct 66 ms 424 KB Output is correct
11 Correct 62 ms 428 KB Output is correct
12 Correct 61 ms 420 KB Output is correct
13 Correct 112 ms 424 KB Output is correct
14 Correct 90 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 1067 ms 13408 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1061 ms 12732 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1084 ms 12948 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 153 ms 340 KB Output is correct
5 Correct 144 ms 428 KB Output is correct
6 Correct 218 ms 460 KB Output is correct
7 Correct 151 ms 412 KB Output is correct
8 Correct 103 ms 396 KB Output is correct
9 Correct 210 ms 340 KB Output is correct
10 Correct 66 ms 424 KB Output is correct
11 Correct 62 ms 428 KB Output is correct
12 Correct 61 ms 420 KB Output is correct
13 Correct 112 ms 424 KB Output is correct
14 Correct 90 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Execution timed out 1067 ms 13408 KB Time limit exceeded
18 Halted 0 ms 0 KB -