Submission #722995

# Submission time Handle Problem Language Result Execution time Memory
722995 2023-04-13T07:01:55 Z dxz05 Stranded Far From Home (BOI22_island) C++17
0 / 100
1000 ms 34028 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 200500;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int n;
vector<int> g[N];
int s[N];

bool can[N];

bool check(const vector<int> &source){
    queue<int> q;
    vector<bool> used(n, false);

    for (int v : source){
        q.push(v);
        used[v] = true;
    }

    ll sum = 0;
    set<pair<int, int>> blocked;
    while (!q.empty()){
        int v = q.front();
        q.pop();

        sum += s[v];

        while (!blocked.empty() && blocked.begin()->first <= sum){
            int x = blocked.begin()->second;
            q.push(x);
            used[x] = true;
            if (can[x]) return true;
            blocked.erase(blocked.begin());
        }

        for (int u : g[v]){
            if (used[u]) continue;
            if (s[u] <= sum){
                q.push(u);
                used[u] = true;
                if (can[u]) return true;
            } else {
                blocked.emplace(s[u], u);
            }
        }
    }

    return count(all(used), true) == n;
}

void solve(){
    int m;
    cin >> n >> m;

    map<int, vector<int>> mp;
    for (int i = 0; i < n; i++){
        cin >> s[i];
        mp[s[i]].push_back(i);
    }

    while (m--){
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    for (auto [_s, v] : mp){
        bool res = check(v);
        for (int i : v) can[i] = res;
    }

    for (int i = 0; i < n; i++){
        cout << can[i];
    }
    cout << endl;

}

int main() {
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 5 ms 5204 KB Output is correct
5 Incorrect 6 ms 5204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Execution timed out 1075 ms 34028 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Execution timed out 1073 ms 33948 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Incorrect 166 ms 13704 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 5 ms 5204 KB Output is correct
5 Incorrect 6 ms 5204 KB Output isn't correct
6 Halted 0 ms 0 KB -