Submission #723080

# Submission time Handle Problem Language Result Execution time Memory
723080 2023-04-13T08:21:53 Z The_Samurai Stranded Far From Home (BOI22_island) C++17
0 / 100
353 ms 26316 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int INF = 2e9;

struct dsu {
    vector<int> p, size;
    void init(int n) {
        p.assign(n + 1, 0);
        size.assign(n + 1, 1);
        for (int i = 1; i <= n; i++)
            p[i] = i;
    }
    int get(int a) {
        return (p[a] == a ? a : get(p[a]));
    }
    void add(int a, int b) {
        a = get(a);
        b = get(b);
        if (size[a] > size[b]) swap(a, b);
        p[a] = b;
        size[b] += size[a];
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    vector<vector<int>> g(n + 1);
    vector<int> ans(n + 1, -1), sum(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum[i] = a[i];
    }
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    vector<vector<int>> v(n + 1);
    dsu ds;
    ds.init(n + 1);
    int no_ans = n + 1;
    for (int i = n; i > 0; i--) {
        v[i].emplace_back(i);
        for (int j : g[i]) {
            if (i <= j) continue;
//            cout << i << ' ' << j << endl;
            if (sum[i] < a[j]) {
                no_ans = i;
            }
            int x = sum[i] + sum[j];
            sum[j] = x;
            sum[i] = x;
            ds.add(i, j);
        }
    }
//    cout << no_ans << endl;
    for (int i = 1; i <= n; i++) {
        cout << (no_ans <= i ? 0 : 1);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int queries = 1;
#ifdef test_cases
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> queries;
#else
    //    cin >> queries;
#endif

    for (int test_case = 1; test_case <= queries; test_case++) {
        solve();
//        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 2 ms 468 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 1 ms 212 KB Output is correct
3 Incorrect 153 ms 26316 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 129 ms 26152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 353 ms 26192 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 2 ms 468 KB Output isn't correct
5 Halted 0 ms 0 KB -