답안 #730322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730322 2023-04-25T17:14:01 Z pls33 Stranded Far From Home (BOI22_island) C++17
100 / 100
190 ms 17756 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);
    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 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 1 ms 468 KB Output is correct
7 Correct 1 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 2 ms 468 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 143 ms 16976 KB Output is correct
4 Correct 141 ms 16924 KB Output is correct
5 Correct 152 ms 16440 KB Output is correct
6 Correct 145 ms 17000 KB Output is correct
7 Correct 141 ms 16972 KB Output is correct
8 Correct 145 ms 16948 KB Output is correct
9 Correct 123 ms 16940 KB Output is correct
10 Correct 104 ms 17736 KB Output is correct
11 Correct 97 ms 17644 KB Output is correct
12 Correct 134 ms 16988 KB Output is correct
13 Correct 112 ms 16972 KB Output is correct
14 Correct 115 ms 16872 KB Output is correct
15 Correct 120 ms 16868 KB Output is correct
16 Correct 82 ms 16716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 174 ms 16888 KB Output is correct
3 Correct 154 ms 16912 KB Output is correct
4 Correct 136 ms 16908 KB Output is correct
5 Correct 116 ms 16888 KB Output is correct
6 Correct 190 ms 16912 KB Output is correct
7 Correct 149 ms 16956 KB Output is correct
8 Correct 135 ms 16908 KB Output is correct
9 Correct 74 ms 16720 KB Output is correct
10 Correct 127 ms 16884 KB Output is correct
11 Correct 146 ms 16868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 158 ms 16940 KB Output is correct
3 Correct 161 ms 16884 KB Output is correct
4 Correct 155 ms 17016 KB Output is correct
5 Correct 145 ms 16908 KB Output is correct
6 Correct 148 ms 16124 KB Output is correct
7 Correct 106 ms 17736 KB Output is correct
8 Correct 84 ms 16968 KB Output is correct
9 Correct 88 ms 9596 KB Output is correct
10 Correct 139 ms 17024 KB Output is correct
11 Correct 134 ms 16924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 1 ms 468 KB Output is correct
7 Correct 1 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 2 ms 468 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 143 ms 16976 KB Output is correct
18 Correct 141 ms 16924 KB Output is correct
19 Correct 152 ms 16440 KB Output is correct
20 Correct 145 ms 17000 KB Output is correct
21 Correct 141 ms 16972 KB Output is correct
22 Correct 145 ms 16948 KB Output is correct
23 Correct 123 ms 16940 KB Output is correct
24 Correct 104 ms 17736 KB Output is correct
25 Correct 97 ms 17644 KB Output is correct
26 Correct 134 ms 16988 KB Output is correct
27 Correct 112 ms 16972 KB Output is correct
28 Correct 115 ms 16872 KB Output is correct
29 Correct 120 ms 16868 KB Output is correct
30 Correct 82 ms 16716 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 174 ms 16888 KB Output is correct
33 Correct 154 ms 16912 KB Output is correct
34 Correct 136 ms 16908 KB Output is correct
35 Correct 116 ms 16888 KB Output is correct
36 Correct 190 ms 16912 KB Output is correct
37 Correct 149 ms 16956 KB Output is correct
38 Correct 135 ms 16908 KB Output is correct
39 Correct 74 ms 16720 KB Output is correct
40 Correct 127 ms 16884 KB Output is correct
41 Correct 146 ms 16868 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 158 ms 16940 KB Output is correct
44 Correct 161 ms 16884 KB Output is correct
45 Correct 155 ms 17016 KB Output is correct
46 Correct 145 ms 16908 KB Output is correct
47 Correct 148 ms 16124 KB Output is correct
48 Correct 106 ms 17736 KB Output is correct
49 Correct 84 ms 16968 KB Output is correct
50 Correct 88 ms 9596 KB Output is correct
51 Correct 139 ms 17024 KB Output is correct
52 Correct 134 ms 16924 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 340 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 1 ms 468 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 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 1 ms 468 KB Output is correct
66 Correct 2 ms 468 KB Output is correct
67 Correct 118 ms 16996 KB Output is correct
68 Correct 125 ms 16908 KB Output is correct
69 Correct 134 ms 16448 KB Output is correct
70 Correct 135 ms 16972 KB Output is correct
71 Correct 136 ms 17036 KB Output is correct
72 Correct 165 ms 16968 KB Output is correct
73 Correct 143 ms 16892 KB Output is correct
74 Correct 109 ms 17728 KB Output is correct
75 Correct 101 ms 17756 KB Output is correct
76 Correct 142 ms 16912 KB Output is correct
77 Correct 120 ms 16884 KB Output is correct
78 Correct 114 ms 16884 KB Output is correct
79 Correct 126 ms 16936 KB Output is correct
80 Correct 79 ms 16716 KB Output is correct
81 Correct 158 ms 16852 KB Output is correct
82 Correct 160 ms 16872 KB Output is correct
83 Correct 115 ms 16908 KB Output is correct
84 Correct 114 ms 17064 KB Output is correct
85 Correct 158 ms 16912 KB Output is correct
86 Correct 138 ms 16972 KB Output is correct
87 Correct 132 ms 16884 KB Output is correct
88 Correct 129 ms 16888 KB Output is correct
89 Correct 139 ms 16968 KB Output is correct
90 Correct 171 ms 16856 KB Output is correct
91 Correct 177 ms 16896 KB Output is correct
92 Correct 155 ms 17012 KB Output is correct
93 Correct 152 ms 17100 KB Output is correct
94 Correct 149 ms 16144 KB Output is correct
95 Correct 103 ms 17732 KB Output is correct
96 Correct 84 ms 16888 KB Output is correct
97 Correct 97 ms 9548 KB Output is correct
98 Correct 142 ms 17020 KB Output is correct
99 Correct 135 ms 16904 KB Output is correct
100 Correct 35 ms 2764 KB Output is correct
101 Correct 172 ms 16996 KB Output is correct
102 Correct 129 ms 13400 KB Output is correct
103 Correct 145 ms 14296 KB Output is correct
104 Correct 166 ms 16732 KB Output is correct