Submission #877886

# Submission time Handle Problem Language Result Execution time Memory
877886 2023-11-23T20:17:08 Z VMaksimoski008 Stranded Far From Home (BOI22_island) C++14
100 / 100
76 ms 10832 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

struct Edge {
    int a, b, w;
    bool operator<(Edge &e) {
        return w < e.w;
    } 
};

struct DSU {
    int n, comp;
    vector<int> par, mx;
    vector<ll> total;
    vector<bool> bad;

    DSU(int &_n, vector<int> &_v) {
        n = _n + 1;
        comp = _n;
        par.resize(n+1);
        mx.resize(n+1);
        total.resize(n+1);
        bad.resize(n+1);
        for(int i=1; i<=n; i++) {
            par[i] = i;
            bad[i] = 0;
            total[i] = mx[i] = _v[i];
        }
    }

    int find(int x) {
        if(x == par[x]) return x;
        int p = find(par[x]);
        if(bad[par[x]]) bad[x] = 1;
        return par[x] = p;
    }

    bool uni(int a, int b) {
        a = find(a);
        b = find(b);

        if(a == b) return false;
        if(mx[a] < mx[b]) swap(a, b);
        if(mx[a] > total[b]) bad[b] = 1;
        par[b] = a;
        total[a] += total[b];
        comp--;
        
        return true;
    }

    bool check(int a) {
        find(a);
        return bad[a];
    }

    int getComp() { return comp; }
};

int32_t main() {
    setIO();

    int n, m;
    cin >> n >> m;
    vector<int> val(n+1);
    for(int i=1; i<=n; i++) cin >> val[i];

    vector<Edge> edges(m);
    for(Edge &e : edges) {
        cin >> e.a >> e.b;
        e.w = max(val[e.a], val[e.b]);
    }

    DSU dsu(n, val);
    sort(all(edges));
    for(Edge &e : edges) dsu.uni(e.a, e.b);

    //cout << "COMPS: " << dsu.getComp() << '\n';
    for(int i=1; i<=n; i++)
        cout << !dsu.check(i);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 65 ms 6904 KB Output is correct
4 Correct 50 ms 6740 KB Output is correct
5 Correct 65 ms 9044 KB Output is correct
6 Correct 68 ms 9300 KB Output is correct
7 Correct 68 ms 9500 KB Output is correct
8 Correct 65 ms 9468 KB Output is correct
9 Correct 64 ms 9392 KB Output is correct
10 Correct 53 ms 9224 KB Output is correct
11 Correct 55 ms 9948 KB Output is correct
12 Correct 55 ms 8828 KB Output is correct
13 Correct 51 ms 8800 KB Output is correct
14 Correct 54 ms 8636 KB Output is correct
15 Correct 68 ms 9452 KB Output is correct
16 Correct 51 ms 8976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 70 ms 6740 KB Output is correct
3 Correct 70 ms 9392 KB Output is correct
4 Correct 57 ms 9300 KB Output is correct
5 Correct 57 ms 8788 KB Output is correct
6 Correct 70 ms 9484 KB Output is correct
7 Correct 65 ms 9300 KB Output is correct
8 Correct 64 ms 9296 KB Output is correct
9 Correct 48 ms 9044 KB Output is correct
10 Correct 60 ms 9208 KB Output is correct
11 Correct 55 ms 8780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 71 ms 6716 KB Output is correct
3 Correct 68 ms 9304 KB Output is correct
4 Correct 69 ms 9560 KB Output is correct
5 Correct 62 ms 9220 KB Output is correct
6 Correct 62 ms 9040 KB Output is correct
7 Correct 61 ms 10832 KB Output is correct
8 Correct 52 ms 8788 KB Output is correct
9 Correct 49 ms 6336 KB Output is correct
10 Correct 55 ms 8648 KB Output is correct
11 Correct 55 ms 8856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 65 ms 6904 KB Output is correct
18 Correct 50 ms 6740 KB Output is correct
19 Correct 65 ms 9044 KB Output is correct
20 Correct 68 ms 9300 KB Output is correct
21 Correct 68 ms 9500 KB Output is correct
22 Correct 65 ms 9468 KB Output is correct
23 Correct 64 ms 9392 KB Output is correct
24 Correct 53 ms 9224 KB Output is correct
25 Correct 55 ms 9948 KB Output is correct
26 Correct 55 ms 8828 KB Output is correct
27 Correct 51 ms 8800 KB Output is correct
28 Correct 54 ms 8636 KB Output is correct
29 Correct 68 ms 9452 KB Output is correct
30 Correct 51 ms 8976 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 70 ms 6740 KB Output is correct
33 Correct 70 ms 9392 KB Output is correct
34 Correct 57 ms 9300 KB Output is correct
35 Correct 57 ms 8788 KB Output is correct
36 Correct 70 ms 9484 KB Output is correct
37 Correct 65 ms 9300 KB Output is correct
38 Correct 64 ms 9296 KB Output is correct
39 Correct 48 ms 9044 KB Output is correct
40 Correct 60 ms 9208 KB Output is correct
41 Correct 55 ms 8780 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 71 ms 6716 KB Output is correct
44 Correct 68 ms 9304 KB Output is correct
45 Correct 69 ms 9560 KB Output is correct
46 Correct 62 ms 9220 KB Output is correct
47 Correct 62 ms 9040 KB Output is correct
48 Correct 61 ms 10832 KB Output is correct
49 Correct 52 ms 8788 KB Output is correct
50 Correct 49 ms 6336 KB Output is correct
51 Correct 55 ms 8648 KB Output is correct
52 Correct 55 ms 8856 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 548 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 508 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 66 ms 9416 KB Output is correct
68 Correct 59 ms 8516 KB Output is correct
69 Correct 65 ms 9132 KB Output is correct
70 Correct 68 ms 9252 KB Output is correct
71 Correct 68 ms 9296 KB Output is correct
72 Correct 75 ms 9332 KB Output is correct
73 Correct 65 ms 9300 KB Output is correct
74 Correct 52 ms 9044 KB Output is correct
75 Correct 55 ms 9984 KB Output is correct
76 Correct 57 ms 8840 KB Output is correct
77 Correct 51 ms 8760 KB Output is correct
78 Correct 53 ms 8628 KB Output is correct
79 Correct 74 ms 9300 KB Output is correct
80 Correct 51 ms 9556 KB Output is correct
81 Correct 70 ms 9324 KB Output is correct
82 Correct 70 ms 9300 KB Output is correct
83 Correct 58 ms 9296 KB Output is correct
84 Correct 50 ms 8784 KB Output is correct
85 Correct 73 ms 9428 KB Output is correct
86 Correct 66 ms 9284 KB Output is correct
87 Correct 66 ms 9296 KB Output is correct
88 Correct 57 ms 9024 KB Output is correct
89 Correct 60 ms 8636 KB Output is correct
90 Correct 69 ms 9348 KB Output is correct
91 Correct 68 ms 9300 KB Output is correct
92 Correct 68 ms 9292 KB Output is correct
93 Correct 66 ms 9460 KB Output is correct
94 Correct 68 ms 9108 KB Output is correct
95 Correct 60 ms 10828 KB Output is correct
96 Correct 52 ms 8788 KB Output is correct
97 Correct 47 ms 6224 KB Output is correct
98 Correct 58 ms 8772 KB Output is correct
99 Correct 54 ms 8788 KB Output is correct
100 Correct 35 ms 2652 KB Output is correct
101 Correct 74 ms 6740 KB Output is correct
102 Correct 58 ms 5964 KB Output is correct
103 Correct 75 ms 6080 KB Output is correct
104 Correct 76 ms 6736 KB Output is correct