Submission #646075

# Submission time Handle Problem Language Result Execution time Memory
646075 2022-09-28T14:53:07 Z dooompy Stranded Far From Home (BOI22_island) C++17
0 / 100
124 ms 15732 KB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

int s[200005];
int par[200005];
int sz[200005];

vector<int> tracker[200005];

bool able[200005];

int findset(int i) {
    return (par[i] == i ? i : par[i] = findset(par[i]));
}

void merge(int a, int b) {
    if (a == b) return;

    if (tracker[a].size() > tracker[b].size()) swap(a, b);

    for (auto cur : tracker[a]) tracker[b].push_back(cur);

    par[a] = b;
    sz[b] += sz[a];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> s[i];

    for (int i = 1; i <= n; i++) {
        par[i] = i;
        sz[i] = s[i];
        tracker[i].push_back(i);
    }

    vector<pair<int, int>> edges;

    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        if (s[a] < s[b]) edges.emplace_back(a, b);
        else edges.emplace_back(b, a);
    }

    sort(edges.begin(), edges.end(), [](pair<int, int> a, pair<int, int> b) {
        return s[a.second] < s[b.second];
    });

    for (int i = 1; i <= n; i++) able[i] =true;

    for (auto edge : edges) {
        int a = findset(edge.first), b = findset(edge.second);

        // check if edge.first -> edge.second

        if (a == b) continue;

        if (sz[a] >= s[edge.second]) {
            // still ok
        } else {
            for (auto cur : tracker[a]) {
                able[cur] = false;
            }

            tracker[a].clear(); tracker[a].shrink_to_fit();
        }

        if (tracker[a].size() < tracker[b].size()) tracker[a].swap(tracker[b]);

        for (auto cur : tracker[b]) tracker[a].push_back(cur);

        sz[a] += sz[b];
        par[b] = a;
    }

    for (int i = 1; i <= n; i++) {
        if (able[i]) cout << "1";
        else cout << "0";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Incorrect 3 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Incorrect 111 ms 15728 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 124 ms 15684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Incorrect 120 ms 15732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Incorrect 3 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -