Submission #576721

# Submission time Handle Problem Language Result Execution time Memory
576721 2022-06-13T10:48:31 Z InternetPerson10 Stranded Far From Home (BOI22_island) C++17
0 / 100
111 ms 9084 KB
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

vector<int> nums;
vector<bool> ans;
vector<pair<int, pair<int, int>>> pairs;

struct dsu {
    vector<ll> par, siz;
    dsu(int n) {
        par.resize(n);
        siz.resize(n);
        for(int i = 0; i < n; i++) {
            par[i] = i;
            siz[i] = nums[i];
        }
    }
    int get(int x) {
        if(x == par[x]) return x;
        if(ans[par[x]] == 0) ans[x] = 0;
        get(par[x]);
        if(ans[par[x]] == 0) ans[x] = 0;
        return par[x] = get(par[x]);
    }
    int getsiz(int x) {
        return siz[get(x)];
    }
    bool unite(int x, int y) {
        x = get(x); y = get(y);
        if(x == y) return false;
        if(siz[x] > siz[y]) swap(x, y);
        par[x] = y;
        siz[y] += siz[x];
        return true;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    nums.resize(n);
    ans.resize(n, 1);
    pairs.resize(m);
    for(int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    dsu uf(n);
    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        pairs.push_back({max(nums[x], nums[y]), {x, y}});
    }
    sort(pairs.begin(), pairs.end());
    for(auto p : pairs) {
        int x, y;
        tie(x, y) = p.second;
        if(uf.getsiz(x) < nums[y]) ans[uf.get(x)] = 0;
        if(uf.getsiz(y) < nums[x]) ans[uf.get(y)] = 0;
        uf.unite(x, y);
    }
    for(int i = 0; i < n; i++) {
        uf.get(i);
        cout << ans[i];
    }
    cout << '\n';
}
# 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 Incorrect 1 ms 340 KB Output isn't correct
5 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 Incorrect 102 ms 9064 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 108 ms 9064 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 Incorrect 111 ms 9084 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 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -