Submission #850468

# Submission time Handle Problem Language Result Execution time Memory
850468 2023-09-16T15:23:47 Z MinaRagy06 Stranded Far From Home (BOI22_island) C++17
25 / 100
1000 ms 55220 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

const int N = 200'005;
int par[N], sz[N], bad[N], a[N];
ll cnt[N];
set<array<int, 3>> adj[N];
pair<int, int> find(int u) {
    if (par[u] == u) {
        return {u, bad[u]};
    }
    pair<int, int> v = find(par[u]);
    bad[u] |= v.second;
    par[u] = v.first;
    return {par[u], bad[u]};
}
void join(int u, int v) {
    u = find(u).first, v = find(v).first;
    if (u == v) return;
    par[v] = u, sz[u] += sz[v], cnt[u] += cnt[v];
    for (auto [vnxt, nxt, src] : adj[v]) {
        int x = find(nxt).first;
        if (x != u) {
            adj[u].insert({a[nxt], nxt, src});
        } else {
            adj[u].erase({a[nxt], nxt, src});
        }
    }
    adj[v].clear();
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        par[i] = i, sz[i] = 1, bad[i] = 0;
        cin >> cnt[i];
        a[i] = cnt[i];
    }
    for (int i = 0, u, v; i < m; i++) {
        cin >> u >> v;
        u--, v--;
        adj[u].insert({a[v], v, u});
        adj[v].insert({a[u], u, v});
    }
    priority_queue<pair<ll, int>> pq;
    for (int i = 0; i < n; i++) {
        pq.push({-cnt[i], i});
    }
    while (pq.size()) {
        int node = pq.top().second;
        ll val = -pq.top().first;
        pq.pop();
        if (node != par[node]) {
            continue;
        }
        if (val != cnt[node]) {
            continue;
        }
        if (sz[node] == n) {
            continue;
        }
        int x = -1;
        for (auto [vnxt, nxt, src] : adj[node]) {
            if (find(nxt).first != node && val >= vnxt) {
                x = find(nxt).first;
                break;
            }
        }
        if (x == -1) {
            bad[node] = 1;
            continue;
        }
        join(node, x);
        int New = find(node).first;
        pq.push({-cnt[New], New});
    }
    for (int i = 0; i < n; i++) {
        cout << !find(i).second;
    }
    cout << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12888 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 6 ms 13148 KB Output is correct
5 Correct 4 ms 13148 KB Output is correct
6 Correct 5 ms 13144 KB Output is correct
7 Correct 5 ms 13400 KB Output is correct
8 Correct 5 ms 13144 KB Output is correct
9 Correct 50 ms 13260 KB Output is correct
10 Correct 4 ms 13148 KB Output is correct
11 Correct 4 ms 13148 KB Output is correct
12 Correct 5 ms 13144 KB Output is correct
13 Correct 4 ms 13144 KB Output is correct
14 Correct 5 ms 13144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12888 KB Output is correct
2 Correct 3 ms 12888 KB Output is correct
3 Execution timed out 1030 ms 45496 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12888 KB Output is correct
2 Correct 359 ms 43880 KB Output is correct
3 Correct 374 ms 44944 KB Output is correct
4 Correct 270 ms 45248 KB Output is correct
5 Correct 258 ms 44892 KB Output is correct
6 Correct 353 ms 45508 KB Output is correct
7 Correct 197 ms 45384 KB Output is correct
8 Correct 192 ms 44944 KB Output is correct
9 Correct 111 ms 44228 KB Output is correct
10 Correct 282 ms 45088 KB Output is correct
11 Correct 331 ms 45224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 517 ms 44180 KB Output is correct
3 Correct 461 ms 45108 KB Output is correct
4 Correct 470 ms 46084 KB Output is correct
5 Correct 368 ms 44996 KB Output is correct
6 Correct 464 ms 45092 KB Output is correct
7 Execution timed out 1042 ms 55220 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12888 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 6 ms 13148 KB Output is correct
5 Correct 4 ms 13148 KB Output is correct
6 Correct 5 ms 13144 KB Output is correct
7 Correct 5 ms 13400 KB Output is correct
8 Correct 5 ms 13144 KB Output is correct
9 Correct 50 ms 13260 KB Output is correct
10 Correct 4 ms 13148 KB Output is correct
11 Correct 4 ms 13148 KB Output is correct
12 Correct 5 ms 13144 KB Output is correct
13 Correct 4 ms 13144 KB Output is correct
14 Correct 5 ms 13144 KB Output is correct
15 Correct 2 ms 12888 KB Output is correct
16 Correct 3 ms 12888 KB Output is correct
17 Execution timed out 1030 ms 45496 KB Time limit exceeded
18 Halted 0 ms 0 KB -