답안 #646045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646045 2022-09-28T14:21:19 Z dooompy Stranded Far From Home (BOI22_island) C++17
0 / 100
133 ms 15820 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 a : tracker[a]) tracker[b].push_back(a);

    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) {
        if (s[a.first] == s[b.first]) {
            return s[a.second] < s[b.second];
        }
        return s[a.first] < s[b.first];
    });

    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 (sz[a] >= s[edge.second]) {
            // still ok
            merge(a, b);
        } else {
            for (auto cur : tracker[a]) {
                able[cur] = false;
            }

            tracker[a].clear(); tracker[a].shrink_to_fit();
            merge(a, b);
        }
    }

    for (int i = 1; i <= n; i++) {
        if (able[i]) cout << "1";
        else cout << "0";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 3 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 102 ms 15820 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 122 ms 15704 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 133 ms 15688 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 3 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -