답안 #723073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723073 2023-04-13T08:18:06 Z Mr_Husanboy Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 18332 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;


void solve(){
    int n, m; cin >> n >> m;
    if(n == 1){
        cout << '1'; return;
    }
    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);
    }
    vector<int> us(n);
    auto com = [&](auto &com, int i)->int{
        int res = 0;
        us[i] = 1;
        for(auto u : g[i]){
            if(us[u]) continue;
            res += com(com, u) + 1;
        }
        return res;
    };
    if(com(com, 0) != n - 1){
        cout << string(n,'0');
        return;
    }
    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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 159 ms 436 KB Output is correct
5 Correct 156 ms 436 KB Output is correct
6 Correct 289 ms 424 KB Output is correct
7 Correct 157 ms 428 KB Output is correct
8 Correct 107 ms 416 KB Output is correct
9 Correct 233 ms 464 KB Output is correct
10 Correct 70 ms 472 KB Output is correct
11 Correct 69 ms 468 KB Output is correct
12 Correct 69 ms 436 KB Output is correct
13 Correct 117 ms 480 KB Output is correct
14 Correct 103 ms 436 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 1056 ms 16068 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1072 ms 18332 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 1068 ms 14076 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 159 ms 436 KB Output is correct
5 Correct 156 ms 436 KB Output is correct
6 Correct 289 ms 424 KB Output is correct
7 Correct 157 ms 428 KB Output is correct
8 Correct 107 ms 416 KB Output is correct
9 Correct 233 ms 464 KB Output is correct
10 Correct 70 ms 472 KB Output is correct
11 Correct 69 ms 468 KB Output is correct
12 Correct 69 ms 436 KB Output is correct
13 Correct 117 ms 480 KB Output is correct
14 Correct 103 ms 436 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 1056 ms 16068 KB Time limit exceeded
18 Halted 0 ms 0 KB -