Submission #1025289

# Submission time Handle Problem Language Result Execution time Memory
1025289 2024-07-16T19:18:39 Z overwatch9 Stranded Far From Home (BOI22_island) C++17
15 / 100
1000 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 1;
ll S[maxn];
vector <int> adj[maxn];
vector <int> mark[maxn];
bool ans[maxn];
bool inserted[maxn], vis[maxn], in_marked[maxn];
int id[maxn];
struct DSU {
    vector <int> link, sz, lst_added;
    vector <ll> sum;
    DSU (int s) {
        lst_added = link = sz = vector <int> (s+1);
        sum = vector <ll> (s+1);
        for (int i = 1; i <= s; i++) {
            lst_added[i] = link[i] = i;
            sz[i] = 1;
            sum[i] = S[i];
        }
    }
    int head(int x) {
        while (x != link[x])
            x = link[x];
        return x;
    }
    bool same(int a, int b) {
        return head(a) == head(b);
    }
    void unite(int a, int b) {
        a = head(a);
        b = head(b);
        if (a == b)
            return;
        if (sz[a] > sz[b])
            swap(a, b);
        sz[a] += sz[b];
        sum[a] += sum[b];
        link[b] = a;
        if (id[lst_added[a]] > id[lst_added[b]])
            lst_added[a] = lst_added[a];
        else
            lst_added[a] = lst_added[b];
    }
};
void dfs(int s, bool x) {
    ans[s] &= x;
    for (auto i : mark[s])
        dfs(i, ans[s]);
}
int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int n, m;
    cin >> n >> m;
    fill(ans, ans + n + 1, true);
    for (int i = 1; i <= n; i++)
        cin >> S[i];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    DSU dsu(n+1);
    vector <pair <int, int>> nodes;
    for (int i = 1; i <= n; i++) {
        nodes.push_back({S[i], i});
    }
    sort(nodes.begin(), nodes.end());
    for (int i = 0; i < n; i++)
        id[nodes[i].second] = i;
    for (int i = 0; i < n; i++) {
        for (auto j : adj[nodes[i].second]) {
            if (!vis[j])
                continue;
            int x = dsu.lst_added[dsu.head(j)];
            if (dsu.sum[dsu.head(j)] < nodes[i].first)
                ans[x] = false;
            if (!in_marked[x]) {
                in_marked[x] = true;
                mark[nodes[i].second].push_back(x);
            }
            dsu.unite(nodes[i].second, j);
        }
        vis[nodes[i].second] = true;
    }
    dfs(nodes[n-1].second, true);
    for (int i = 1; i <= n; i++)
        cout << ans[i];
    cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Runtime error 388 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 210 ms 35692 KB Output is correct
4 Correct 167 ms 38852 KB Output is correct
5 Correct 206 ms 32416 KB Output is correct
6 Correct 196 ms 33224 KB Output is correct
7 Correct 188 ms 33272 KB Output is correct
8 Execution timed out 1083 ms 30520 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 210 ms 33340 KB Output is correct
3 Correct 205 ms 33468 KB Output is correct
4 Correct 194 ms 40644 KB Output is correct
5 Correct 154 ms 37548 KB Output is correct
6 Correct 207 ms 33472 KB Output is correct
7 Correct 211 ms 40640 KB Output is correct
8 Correct 235 ms 40708 KB Output is correct
9 Correct 146 ms 39876 KB Output is correct
10 Correct 203 ms 34332 KB Output is correct
11 Correct 175 ms 33012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Execution timed out 1077 ms 32948 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 388 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -