답안 #730320

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730320 2023-04-25T17:09:48 Z pls33 Stranded Far From Home (BOI22_island) C++17
100 / 100
207 ms 17764 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])
        {
            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
      |
# 결과 실행 시간 메모리 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 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 121 ms 16876 KB Output is correct
4 Correct 107 ms 16880 KB Output is correct
5 Correct 170 ms 16432 KB Output is correct
6 Correct 137 ms 16948 KB Output is correct
7 Correct 147 ms 17068 KB Output is correct
8 Correct 141 ms 16996 KB Output is correct
9 Correct 158 ms 16972 KB Output is correct
10 Correct 93 ms 17764 KB Output is correct
11 Correct 94 ms 17760 KB Output is correct
12 Correct 149 ms 17104 KB Output is correct
13 Correct 128 ms 16884 KB Output is correct
14 Correct 125 ms 16908 KB Output is correct
15 Correct 134 ms 16896 KB Output is correct
16 Correct 78 ms 16688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 173 ms 16768 KB Output is correct
3 Correct 171 ms 16904 KB Output is correct
4 Correct 125 ms 16848 KB Output is correct
5 Correct 113 ms 16964 KB Output is correct
6 Correct 188 ms 17008 KB Output is correct
7 Correct 138 ms 16952 KB Output is correct
8 Correct 119 ms 16884 KB Output is correct
9 Correct 84 ms 16704 KB Output is correct
10 Correct 132 ms 17088 KB Output is correct
11 Correct 129 ms 16876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 190 ms 16912 KB Output is correct
3 Correct 162 ms 17000 KB Output is correct
4 Correct 156 ms 17004 KB Output is correct
5 Correct 144 ms 16864 KB Output is correct
6 Correct 162 ms 16172 KB Output is correct
7 Correct 102 ms 17676 KB Output is correct
8 Correct 90 ms 16992 KB Output is correct
9 Correct 110 ms 9640 KB Output is correct
10 Correct 147 ms 16976 KB Output is correct
11 Correct 140 ms 16960 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 121 ms 16876 KB Output is correct
18 Correct 107 ms 16880 KB Output is correct
19 Correct 170 ms 16432 KB Output is correct
20 Correct 137 ms 16948 KB Output is correct
21 Correct 147 ms 17068 KB Output is correct
22 Correct 141 ms 16996 KB Output is correct
23 Correct 158 ms 16972 KB Output is correct
24 Correct 93 ms 17764 KB Output is correct
25 Correct 94 ms 17760 KB Output is correct
26 Correct 149 ms 17104 KB Output is correct
27 Correct 128 ms 16884 KB Output is correct
28 Correct 125 ms 16908 KB Output is correct
29 Correct 134 ms 16896 KB Output is correct
30 Correct 78 ms 16688 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 173 ms 16768 KB Output is correct
33 Correct 171 ms 16904 KB Output is correct
34 Correct 125 ms 16848 KB Output is correct
35 Correct 113 ms 16964 KB Output is correct
36 Correct 188 ms 17008 KB Output is correct
37 Correct 138 ms 16952 KB Output is correct
38 Correct 119 ms 16884 KB Output is correct
39 Correct 84 ms 16704 KB Output is correct
40 Correct 132 ms 17088 KB Output is correct
41 Correct 129 ms 16876 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 190 ms 16912 KB Output is correct
44 Correct 162 ms 17000 KB Output is correct
45 Correct 156 ms 17004 KB Output is correct
46 Correct 144 ms 16864 KB Output is correct
47 Correct 162 ms 16172 KB Output is correct
48 Correct 102 ms 17676 KB Output is correct
49 Correct 90 ms 16992 KB Output is correct
50 Correct 110 ms 9640 KB Output is correct
51 Correct 147 ms 16976 KB Output is correct
52 Correct 140 ms 16960 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Correct 2 ms 468 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 139 ms 16980 KB Output is correct
68 Correct 138 ms 16996 KB Output is correct
69 Correct 205 ms 16424 KB Output is correct
70 Correct 159 ms 16932 KB Output is correct
71 Correct 167 ms 16960 KB Output is correct
72 Correct 170 ms 16936 KB Output is correct
73 Correct 145 ms 16964 KB Output is correct
74 Correct 100 ms 17708 KB Output is correct
75 Correct 123 ms 17732 KB Output is correct
76 Correct 135 ms 16972 KB Output is correct
77 Correct 133 ms 16864 KB Output is correct
78 Correct 130 ms 16980 KB Output is correct
79 Correct 157 ms 16900 KB Output is correct
80 Correct 77 ms 16728 KB Output is correct
81 Correct 194 ms 16780 KB Output is correct
82 Correct 201 ms 16900 KB Output is correct
83 Correct 126 ms 16876 KB Output is correct
84 Correct 114 ms 16872 KB Output is correct
85 Correct 202 ms 16964 KB Output is correct
86 Correct 119 ms 16920 KB Output is correct
87 Correct 134 ms 16896 KB Output is correct
88 Correct 120 ms 16956 KB Output is correct
89 Correct 136 ms 16908 KB Output is correct
90 Correct 207 ms 16932 KB Output is correct
91 Correct 176 ms 16848 KB Output is correct
92 Correct 169 ms 17008 KB Output is correct
93 Correct 144 ms 16960 KB Output is correct
94 Correct 138 ms 16144 KB Output is correct
95 Correct 100 ms 17716 KB Output is correct
96 Correct 99 ms 16928 KB Output is correct
97 Correct 87 ms 9548 KB Output is correct
98 Correct 137 ms 16960 KB Output is correct
99 Correct 148 ms 16968 KB Output is correct
100 Correct 41 ms 2752 KB Output is correct
101 Correct 175 ms 16968 KB Output is correct
102 Correct 119 ms 13460 KB Output is correct
103 Correct 162 ms 14260 KB Output is correct
104 Correct 188 ms 16628 KB Output is correct