Submission #646078

# Submission time Handle Problem Language Result Execution time Memory
646078 2022-09-28T15:15:05 Z dooompy Stranded Far From Home (BOI22_island) C++17
100 / 100
150 ms 29748 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;

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

vector<int> tracker[200005];

bool able[200005];

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

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 (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

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

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

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

    for (auto cur : tracker[findset(1)]) {
        able[cur] = true;
    }

    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 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 4 ms 5080 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 4 ms 5204 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 3 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 96 ms 18632 KB Output is correct
4 Correct 120 ms 27524 KB Output is correct
5 Correct 107 ms 24068 KB Output is correct
6 Correct 109 ms 24848 KB Output is correct
7 Correct 110 ms 24752 KB Output is correct
8 Correct 131 ms 27080 KB Output is correct
9 Correct 95 ms 25896 KB Output is correct
10 Correct 75 ms 20620 KB Output is correct
11 Correct 91 ms 22352 KB Output is correct
12 Correct 112 ms 22064 KB Output is correct
13 Correct 130 ms 28188 KB Output is correct
14 Correct 128 ms 27268 KB Output is correct
15 Correct 106 ms 23500 KB Output is correct
16 Correct 69 ms 22508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 120 ms 21080 KB Output is correct
3 Correct 150 ms 25780 KB Output is correct
4 Correct 135 ms 29748 KB Output is correct
5 Correct 129 ms 28144 KB Output is correct
6 Correct 122 ms 25492 KB Output is correct
7 Correct 97 ms 23368 KB Output is correct
8 Correct 93 ms 23352 KB Output is correct
9 Correct 70 ms 22572 KB Output is correct
10 Correct 105 ms 24888 KB Output is correct
11 Correct 120 ms 24888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 128 ms 18800 KB Output is correct
3 Correct 118 ms 23852 KB Output is correct
4 Correct 122 ms 25000 KB Output is correct
5 Correct 150 ms 26268 KB Output is correct
6 Correct 133 ms 24004 KB Output is correct
7 Correct 113 ms 23648 KB Output is correct
8 Correct 84 ms 23308 KB Output is correct
9 Correct 77 ms 15260 KB Output is correct
10 Correct 130 ms 25272 KB Output is correct
11 Correct 108 ms 24996 KB Output is correct
# 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 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 4 ms 5080 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 4 ms 5204 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 3 ms 5204 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 96 ms 18632 KB Output is correct
18 Correct 120 ms 27524 KB Output is correct
19 Correct 107 ms 24068 KB Output is correct
20 Correct 109 ms 24848 KB Output is correct
21 Correct 110 ms 24752 KB Output is correct
22 Correct 131 ms 27080 KB Output is correct
23 Correct 95 ms 25896 KB Output is correct
24 Correct 75 ms 20620 KB Output is correct
25 Correct 91 ms 22352 KB Output is correct
26 Correct 112 ms 22064 KB Output is correct
27 Correct 130 ms 28188 KB Output is correct
28 Correct 128 ms 27268 KB Output is correct
29 Correct 106 ms 23500 KB Output is correct
30 Correct 69 ms 22508 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 120 ms 21080 KB Output is correct
33 Correct 150 ms 25780 KB Output is correct
34 Correct 135 ms 29748 KB Output is correct
35 Correct 129 ms 28144 KB Output is correct
36 Correct 122 ms 25492 KB Output is correct
37 Correct 97 ms 23368 KB Output is correct
38 Correct 93 ms 23352 KB Output is correct
39 Correct 70 ms 22572 KB Output is correct
40 Correct 105 ms 24888 KB Output is correct
41 Correct 120 ms 24888 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 128 ms 18800 KB Output is correct
44 Correct 118 ms 23852 KB Output is correct
45 Correct 122 ms 25000 KB Output is correct
46 Correct 150 ms 26268 KB Output is correct
47 Correct 133 ms 24004 KB Output is correct
48 Correct 113 ms 23648 KB Output is correct
49 Correct 84 ms 23308 KB Output is correct
50 Correct 77 ms 15260 KB Output is correct
51 Correct 130 ms 25272 KB Output is correct
52 Correct 108 ms 24996 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 4 ms 5316 KB Output is correct
57 Correct 3 ms 5172 KB Output is correct
58 Correct 4 ms 5076 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 3 ms 5076 KB Output is correct
61 Correct 4 ms 5332 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 5 ms 5204 KB Output is correct
64 Correct 5 ms 5176 KB Output is correct
65 Correct 4 ms 5172 KB Output is correct
66 Correct 4 ms 5204 KB Output is correct
67 Correct 96 ms 23124 KB Output is correct
68 Correct 117 ms 27576 KB Output is correct
69 Correct 102 ms 24156 KB Output is correct
70 Correct 116 ms 24816 KB Output is correct
71 Correct 107 ms 24848 KB Output is correct
72 Correct 139 ms 27060 KB Output is correct
73 Correct 100 ms 25912 KB Output is correct
74 Correct 73 ms 20640 KB Output is correct
75 Correct 89 ms 22308 KB Output is correct
76 Correct 112 ms 22072 KB Output is correct
77 Correct 125 ms 28076 KB Output is correct
78 Correct 116 ms 27252 KB Output is correct
79 Correct 95 ms 23328 KB Output is correct
80 Correct 69 ms 22572 KB Output is correct
81 Correct 122 ms 25588 KB Output is correct
82 Correct 120 ms 25672 KB Output is correct
83 Correct 133 ms 29604 KB Output is correct
84 Correct 124 ms 28088 KB Output is correct
85 Correct 125 ms 25572 KB Output is correct
86 Correct 95 ms 23400 KB Output is correct
87 Correct 95 ms 23372 KB Output is correct
88 Correct 111 ms 24888 KB Output is correct
89 Correct 117 ms 24820 KB Output is correct
90 Correct 116 ms 23204 KB Output is correct
91 Correct 116 ms 23848 KB Output is correct
92 Correct 119 ms 24884 KB Output is correct
93 Correct 130 ms 26316 KB Output is correct
94 Correct 120 ms 23988 KB Output is correct
95 Correct 96 ms 23600 KB Output is correct
96 Correct 76 ms 23356 KB Output is correct
97 Correct 76 ms 15212 KB Output is correct
98 Correct 119 ms 25256 KB Output is correct
99 Correct 109 ms 24984 KB Output is correct
100 Correct 46 ms 8816 KB Output is correct
101 Correct 127 ms 24068 KB Output is correct
102 Correct 110 ms 21132 KB Output is correct
103 Correct 116 ms 20556 KB Output is correct
104 Correct 125 ms 22760 KB Output is correct