Submission #730316

# Submission time Handle Problem Language Result Execution time Memory
730316 2023-04-25T17:04:58 Z pls33 Stranded Far From Home (BOI22_island) C++17
100 / 100
223 ms 22180 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#pragma region dalykai
template <typename F>
void _debug(F f)
{
    f();
}

#ifndef _AAAAAAAAA
#define debug(x)
#else
#define debug(x) _debug(x)
#endif
using p32 = pair<int, int>;
using p32u = pair<uint32_t, uint32_t>;
using p64 = pair<int64_t, int64_t>;
using p64u = pair<uint64_t, uint64_t>;
using vi16 = vector<int16_t>;
using vi16u = vector<uint16_t>;
using vi32 = vector<int>;
using vi32u = vector<uint32_t>;
using vi64 = vector<int64_t>;
using vi64u = vector<uint64_t>;
using vp32 = vector<p32>;
using vp32u = vector<p32u>;
using vp64 = vector<p64>;
using vp64u = vector<p64u>;
using vvi32 = vector<vi32>;
using vvi32u = vector<vi32u>;
using vvi64 = vector<vi64>;
using vvi64u = vector<vi64u>;
using vvp32 = vector<vp32>;
using vvp32u = vector<vp32u>;
using vvp64 = vector<vp64>;
using vvp64u = vector<vp64u>;
using f80 = long double;
#pragma endregion

using state_t = bitset<(int)2e5>;

struct dsu_t
{
    vi32 parent;
    vi32 size;
    vi64 weight;
    state_t marked;

    dsu_t(int n) : parent(n), size(n, 1), weight(n)
    {
        iota(parent.begin(), parent.end(), 0);
    }

    int find_set(int a)
    {
        if (parent[a] == a)
        {
            return a;
        }

        int p = a;
        while (p != parent[p])
        {
            if (marked[p])
            {
                marked[a] = true;
            }
            p = parent[p];
        }

        return p;
    }

    void unite(int a, int b)
    {
        a = find_set(a);
        b = find_set(b);

        if (a == b)
        {
            return;
        }

        if ((weight[a] == weight[b])
                ? size[a] < size[b]
                : weight[a] < weight[b])
        {
            swap(a, b);
        }

        parent[b] = a;
        size[a] += size[b];
        weight[a] += weight[b];
    }
};

int main()
{
#ifndef _AAAAAAAAA
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#else
    freopen("sala.in", "r", stdin);
#ifndef __linux__
    atexit([]()
           {
        freopen("con", "r", stdin);
        system("pause"); });
#endif
#endif

    int v, e;
    cin >> v >> e;

    vi64 weight(v);
    for (auto &w : weight)
    {
        cin >> w;
    }

    vi32 order(v);
    iota(order.begin(), order.end(), 0);
    stable_sort(order.begin(), order.end(),
                [&](int a, int b)
                {
                    return weight[a] < weight[b];
                    //
                });

    vvi32 adj(v);
    for (int i = 0; i < e; i++)
    {
        int a, b;
        cin >> a >> b;

        a--;
        b--;

        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    dsu_t dsu(v);
    dsu.weight = weight;

    for (auto &i : order)
    {
        for (auto &next : adj[i])
        {
            if (weight[next] > weight[i])
            {
                continue;
            }

            next = dsu.find_set(next);

            if (dsu.weight[next] < weight[i])
            {
                dsu.marked[next] = true;
            }
            dsu.unite(i, next);
        }
    }

    for (int i = 0; i < v; i++)
    {
        dsu.find_set(i);
        cout << !dsu.marked[i];
    }
    cout << '\n';

    return 0;
}

Compilation message

island.cpp:8: warning: ignoring '#pragma region dalykai' [-Wunknown-pragmas]
    8 | #pragma region dalykai
      | 
island.cpp:43: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
   43 | #pragma endregion
      |
# 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 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
# 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 138 ms 16948 KB Output is correct
4 Correct 138 ms 16928 KB Output is correct
5 Correct 164 ms 20684 KB Output is correct
6 Correct 150 ms 21504 KB Output is correct
7 Correct 152 ms 21352 KB Output is correct
8 Correct 157 ms 21416 KB Output is correct
9 Correct 128 ms 21200 KB Output is correct
10 Correct 113 ms 21344 KB Output is correct
11 Correct 95 ms 21088 KB Output is correct
12 Correct 138 ms 19948 KB Output is correct
13 Correct 129 ms 19884 KB Output is correct
14 Correct 144 ms 19952 KB Output is correct
15 Correct 151 ms 21332 KB Output is correct
16 Correct 81 ms 20520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 168 ms 16752 KB Output is correct
3 Correct 181 ms 21368 KB Output is correct
4 Correct 146 ms 21352 KB Output is correct
5 Correct 116 ms 19780 KB Output is correct
6 Correct 171 ms 21308 KB Output is correct
7 Correct 137 ms 21476 KB Output is correct
8 Correct 150 ms 21332 KB Output is correct
9 Correct 82 ms 20520 KB Output is correct
10 Correct 133 ms 20692 KB Output is correct
11 Correct 149 ms 19908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 190 ms 16972 KB Output is correct
3 Correct 182 ms 21328 KB Output is correct
4 Correct 190 ms 21456 KB Output is correct
5 Correct 175 ms 21372 KB Output is correct
6 Correct 175 ms 20520 KB Output is correct
7 Correct 119 ms 22104 KB Output is correct
8 Correct 85 ms 20156 KB Output is correct
9 Correct 126 ms 12252 KB Output is correct
10 Correct 150 ms 19936 KB Output is correct
11 Correct 147 ms 20020 KB Output is correct
# 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 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 138 ms 16948 KB Output is correct
18 Correct 138 ms 16928 KB Output is correct
19 Correct 164 ms 20684 KB Output is correct
20 Correct 150 ms 21504 KB Output is correct
21 Correct 152 ms 21352 KB Output is correct
22 Correct 157 ms 21416 KB Output is correct
23 Correct 128 ms 21200 KB Output is correct
24 Correct 113 ms 21344 KB Output is correct
25 Correct 95 ms 21088 KB Output is correct
26 Correct 138 ms 19948 KB Output is correct
27 Correct 129 ms 19884 KB Output is correct
28 Correct 144 ms 19952 KB Output is correct
29 Correct 151 ms 21332 KB Output is correct
30 Correct 81 ms 20520 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 168 ms 16752 KB Output is correct
33 Correct 181 ms 21368 KB Output is correct
34 Correct 146 ms 21352 KB Output is correct
35 Correct 116 ms 19780 KB Output is correct
36 Correct 171 ms 21308 KB Output is correct
37 Correct 137 ms 21476 KB Output is correct
38 Correct 150 ms 21332 KB Output is correct
39 Correct 82 ms 20520 KB Output is correct
40 Correct 133 ms 20692 KB Output is correct
41 Correct 149 ms 19908 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 190 ms 16972 KB Output is correct
44 Correct 182 ms 21328 KB Output is correct
45 Correct 190 ms 21456 KB Output is correct
46 Correct 175 ms 21372 KB Output is correct
47 Correct 175 ms 20520 KB Output is correct
48 Correct 119 ms 22104 KB Output is correct
49 Correct 85 ms 20156 KB Output is correct
50 Correct 126 ms 12252 KB Output is correct
51 Correct 150 ms 19936 KB Output is correct
52 Correct 147 ms 20020 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 1 ms 480 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 2 ms 480 KB Output is correct
64 Correct 2 ms 468 KB Output is correct
65 Correct 1 ms 468 KB Output is correct
66 Correct 2 ms 468 KB Output is correct
67 Correct 152 ms 21376 KB Output is correct
68 Correct 143 ms 20192 KB Output is correct
69 Correct 160 ms 20812 KB Output is correct
70 Correct 201 ms 21336 KB Output is correct
71 Correct 151 ms 21380 KB Output is correct
72 Correct 140 ms 21344 KB Output is correct
73 Correct 168 ms 21208 KB Output is correct
74 Correct 108 ms 21244 KB Output is correct
75 Correct 114 ms 21100 KB Output is correct
76 Correct 160 ms 20032 KB Output is correct
77 Correct 127 ms 19788 KB Output is correct
78 Correct 125 ms 19996 KB Output is correct
79 Correct 163 ms 21312 KB Output is correct
80 Correct 103 ms 20584 KB Output is correct
81 Correct 165 ms 21188 KB Output is correct
82 Correct 193 ms 21348 KB Output is correct
83 Correct 183 ms 21496 KB Output is correct
84 Correct 126 ms 19776 KB Output is correct
85 Correct 192 ms 21424 KB Output is correct
86 Correct 158 ms 21396 KB Output is correct
87 Correct 148 ms 21444 KB Output is correct
88 Correct 146 ms 20736 KB Output is correct
89 Correct 143 ms 19872 KB Output is correct
90 Correct 206 ms 21336 KB Output is correct
91 Correct 191 ms 21332 KB Output is correct
92 Correct 200 ms 21480 KB Output is correct
93 Correct 220 ms 21440 KB Output is correct
94 Correct 160 ms 20588 KB Output is correct
95 Correct 130 ms 22180 KB Output is correct
96 Correct 90 ms 20208 KB Output is correct
97 Correct 90 ms 12176 KB Output is correct
98 Correct 167 ms 19868 KB Output is correct
99 Correct 156 ms 19936 KB Output is correct
100 Correct 40 ms 4684 KB Output is correct
101 Correct 223 ms 21508 KB Output is correct
102 Correct 139 ms 17428 KB Output is correct
103 Correct 183 ms 18360 KB Output is correct
104 Correct 190 ms 21056 KB Output is correct