Submission #576719

# Submission time Handle Problem Language Result Execution time Memory
576719 2022-06-13T10:42:01 Z InternetPerson10 Stranded Far From Home (BOI22_island) C++17
0 / 100
124 ms 9068 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;
        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[x] = 0;
        if(uf.getsiz(y) < nums[x]) ans[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 1 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 99 ms 9048 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 103 ms 9068 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 124 ms 9020 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 1 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -