Submission #723101

# Submission time Handle Problem Language Result Execution time Memory
723101 2023-04-13T08:41:59 Z Mr_Husanboy Stranded Far From Home (BOI22_island) C++17
20 / 100
231 ms 23628 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

void sub1(int &n, int &m, vector<vector<int>> &g, vector<int> &s){
    if(n > 2000) return;
    #ifdef LOCAL
    cout << "sub1" << endl;
    #endif
    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});
            }
        }
        return cnt == n;
    };

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

}

void sub2(int &n, int &m, vector<vector<int>> &g, vector<int> &s){
    vector<int> cnt(n);
    vector<ll> calc(n);
    for(int i = 0; i < n; i ++){
        //calc[i] = s[i];
        for(auto u : g[i]){
            if(u < i) cnt[i] ++;
            //calc[i] += s[u];
        }
    }
    for(int i = 1; i < n; i ++){
        if(cnt[i] != 1) return;
    }

    for(int i = 1; i < n; i ++){
        if(s[i] > s[i - 1]) return;
    }
    #ifdef LOCAL
    cout << "sub2" << endl;
    #endif
    vector<int> dp(n); dp[0] = 1;
    auto dfs = [&](auto & dfs, int i, int p)->void{
        calc[i] = s[i];
        for(auto u : g[i]){
            if(u == p) continue;
            dfs(dfs, u, i);
            calc[i] += calc[u];
        }
    };
    dfs(dfs, 0, 0);
    auto dfs2 = [&](auto &dfs2, int i, int p)->void{
        for(auto u : g[i]){
            if(u == p) continue;
            if(calc[u] >= s[i]) dp[u] |= dp[i];
            dfs2(dfs2, u, i);
        }
    };
    dfs2(dfs2, 0, 0);
    for(auto u : dp) cout << u;
        exit(0);
}

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);
    }

    sub2(n, m, g, s);
    sub1(n, m, g, s);

}

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 Correct 155 ms 340 KB Output is correct
5 Correct 150 ms 440 KB Output is correct
6 Correct 231 ms 408 KB Output is correct
7 Correct 156 ms 420 KB Output is correct
8 Correct 108 ms 392 KB Output is correct
9 Correct 224 ms 440 KB Output is correct
10 Correct 69 ms 340 KB Output is correct
11 Correct 70 ms 440 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 123 ms 340 KB Output is correct
14 Correct 97 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 141 ms 18516 KB Output is correct
4 Correct 120 ms 18508 KB Output is correct
5 Correct 148 ms 15032 KB Output is correct
6 Correct 162 ms 15540 KB Output is correct
7 Correct 189 ms 15636 KB Output is correct
8 Correct 196 ms 15600 KB Output is correct
9 Correct 145 ms 15576 KB Output is correct
10 Correct 94 ms 16328 KB Output is correct
11 Correct 95 ms 16204 KB Output is correct
12 Correct 189 ms 15580 KB Output is correct
13 Correct 139 ms 23628 KB Output is correct
14 Correct 159 ms 23408 KB Output is correct
15 Correct 140 ms 23468 KB Output is correct
16 Correct 113 ms 23252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 113 ms 14320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 117 ms 14388 KB Output isn't correct
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 Correct 155 ms 340 KB Output is correct
5 Correct 150 ms 440 KB Output is correct
6 Correct 231 ms 408 KB Output is correct
7 Correct 156 ms 420 KB Output is correct
8 Correct 108 ms 392 KB Output is correct
9 Correct 224 ms 440 KB Output is correct
10 Correct 69 ms 340 KB Output is correct
11 Correct 70 ms 440 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 123 ms 340 KB Output is correct
14 Correct 97 ms 452 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 141 ms 18516 KB Output is correct
18 Correct 120 ms 18508 KB Output is correct
19 Correct 148 ms 15032 KB Output is correct
20 Correct 162 ms 15540 KB Output is correct
21 Correct 189 ms 15636 KB Output is correct
22 Correct 196 ms 15600 KB Output is correct
23 Correct 145 ms 15576 KB Output is correct
24 Correct 94 ms 16328 KB Output is correct
25 Correct 95 ms 16204 KB Output is correct
26 Correct 189 ms 15580 KB Output is correct
27 Correct 139 ms 23628 KB Output is correct
28 Correct 159 ms 23408 KB Output is correct
29 Correct 140 ms 23468 KB Output is correct
30 Correct 113 ms 23252 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 113 ms 14320 KB Output isn't correct
33 Halted 0 ms 0 KB -