답안 #1025303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025303 2024-07-16T19:35:07 Z overwatch9 Stranded Far From Home (BOI22_island) C++17
100 / 100
131 ms 40904 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 1;
ll S[maxn];
vector <int> adj[maxn];
vector <int> mark[maxn];
bool ans[maxn];
bool inserted[maxn], vis[maxn], in_marked[maxn];
int id[maxn];
struct DSU {
    vector <int> link, sz, lst_added;
    vector <ll> sum;
    DSU (int s) {
        lst_added = link = sz = vector <int> (s+1);
        sum = vector <ll> (s+1);
        for (int i = 1; i <= s; i++) {
            lst_added[i] = link[i] = i;
            sz[i] = 1;
            sum[i] = S[i];
        }
    }
    int head(int x) {
        if (x == link[x])
            return x;
        return link[x] = head(link[x]);
    }
    bool same(int a, int b) {
        return head(a) == head(b);
    }
    void unite(int a, int b) {
        a = head(a);
        b = head(b);
        if (a == b)
            return;
        if (sz[a] > sz[b])
            swap(a, b);
        sz[a] += sz[b];
        sum[a] += sum[b];
        link[b] = a;
        if (id[lst_added[a]] > id[lst_added[b]])
            lst_added[a] = lst_added[a];
        else
            lst_added[a] = lst_added[b];
    }
};
void dfs(int s, bool x) {
    ans[s] &= x;
    for (auto i : mark[s])
        dfs(i, ans[s]);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int n, m;
    cin >> n >> m;
    fill(ans, ans + n + 1, true);
    for (int i = 1; i <= n; i++)
        cin >> S[i];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    DSU dsu(n+1);
    vector <pair <int, int>> nodes;
    for (int i = 1; i <= n; i++) {
        nodes.push_back({S[i], i});
    }
    sort(nodes.begin(), nodes.end());
    for (int i = 0; i < n; i++)
        id[nodes[i].second] = i;
    for (int i = 0; i < n; i++) {
        for (auto j : adj[nodes[i].second]) {
            if (!vis[j])
                continue;
            int x = dsu.lst_added[dsu.head(j)];
            if (dsu.sum[dsu.head(j)] < nodes[i].first)
                ans[x] = false;
            if (!in_marked[x] && nodes[i].second != x) {
                in_marked[x] = true;
                mark[nodes[i].second].push_back(x);
            }
            dsu.unite(nodes[i].second, j);
        }
        vis[nodes[i].second] = true;
    }
    dfs(nodes[n-1].second, true);
    for (int i = 1; i <= n; i++)
        cout << ans[i];
    cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 3 ms 12780 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12792 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 4 ms 13144 KB Output is correct
9 Correct 3 ms 12892 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 3 ms 12892 KB Output is correct
12 Correct 2 ms 12940 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 3 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 93 ms 31176 KB Output is correct
4 Correct 87 ms 35776 KB Output is correct
5 Correct 104 ms 28356 KB Output is correct
6 Correct 96 ms 28756 KB Output is correct
7 Correct 99 ms 28872 KB Output is correct
8 Correct 108 ms 36404 KB Output is correct
9 Correct 81 ms 32192 KB Output is correct
10 Correct 73 ms 31036 KB Output is correct
11 Correct 98 ms 40512 KB Output is correct
12 Correct 116 ms 34024 KB Output is correct
13 Correct 86 ms 39124 KB Output is correct
14 Correct 84 ms 38960 KB Output is correct
15 Correct 81 ms 40640 KB Output is correct
16 Correct 65 ms 39880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 95 ms 28808 KB Output is correct
3 Correct 105 ms 29120 KB Output is correct
4 Correct 90 ms 36288 KB Output is correct
5 Correct 85 ms 34500 KB Output is correct
6 Correct 93 ms 28864 KB Output is correct
7 Correct 86 ms 36220 KB Output is correct
8 Correct 85 ms 36288 KB Output is correct
9 Correct 59 ms 36032 KB Output is correct
10 Correct 68 ms 30660 KB Output is correct
11 Correct 78 ms 29888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 108 ms 29156 KB Output is correct
3 Correct 123 ms 33220 KB Output is correct
4 Correct 116 ms 33256 KB Output is correct
5 Correct 115 ms 33216 KB Output is correct
6 Correct 104 ms 33092 KB Output is correct
7 Correct 76 ms 36796 KB Output is correct
8 Correct 71 ms 39492 KB Output is correct
9 Correct 75 ms 24928 KB Output is correct
10 Correct 95 ms 31708 KB Output is correct
11 Correct 92 ms 32964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 3 ms 12780 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12792 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 4 ms 13144 KB Output is correct
9 Correct 3 ms 12892 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 3 ms 12892 KB Output is correct
12 Correct 2 ms 12940 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 3 ms 12892 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 93 ms 31176 KB Output is correct
18 Correct 87 ms 35776 KB Output is correct
19 Correct 104 ms 28356 KB Output is correct
20 Correct 96 ms 28756 KB Output is correct
21 Correct 99 ms 28872 KB Output is correct
22 Correct 108 ms 36404 KB Output is correct
23 Correct 81 ms 32192 KB Output is correct
24 Correct 73 ms 31036 KB Output is correct
25 Correct 98 ms 40512 KB Output is correct
26 Correct 116 ms 34024 KB Output is correct
27 Correct 86 ms 39124 KB Output is correct
28 Correct 84 ms 38960 KB Output is correct
29 Correct 81 ms 40640 KB Output is correct
30 Correct 65 ms 39880 KB Output is correct
31 Correct 2 ms 12636 KB Output is correct
32 Correct 95 ms 28808 KB Output is correct
33 Correct 105 ms 29120 KB Output is correct
34 Correct 90 ms 36288 KB Output is correct
35 Correct 85 ms 34500 KB Output is correct
36 Correct 93 ms 28864 KB Output is correct
37 Correct 86 ms 36220 KB Output is correct
38 Correct 85 ms 36288 KB Output is correct
39 Correct 59 ms 36032 KB Output is correct
40 Correct 68 ms 30660 KB Output is correct
41 Correct 78 ms 29888 KB Output is correct
42 Correct 2 ms 12636 KB Output is correct
43 Correct 108 ms 29156 KB Output is correct
44 Correct 123 ms 33220 KB Output is correct
45 Correct 116 ms 33256 KB Output is correct
46 Correct 115 ms 33216 KB Output is correct
47 Correct 104 ms 33092 KB Output is correct
48 Correct 76 ms 36796 KB Output is correct
49 Correct 71 ms 39492 KB Output is correct
50 Correct 75 ms 24928 KB Output is correct
51 Correct 95 ms 31708 KB Output is correct
52 Correct 92 ms 32964 KB Output is correct
53 Correct 2 ms 12636 KB Output is correct
54 Correct 2 ms 12780 KB Output is correct
55 Correct 2 ms 12636 KB Output is correct
56 Correct 2 ms 12892 KB Output is correct
57 Correct 3 ms 12980 KB Output is correct
58 Correct 2 ms 12892 KB Output is correct
59 Correct 3 ms 12892 KB Output is correct
60 Correct 2 ms 12892 KB Output is correct
61 Correct 3 ms 12892 KB Output is correct
62 Correct 4 ms 12860 KB Output is correct
63 Correct 3 ms 12892 KB Output is correct
64 Correct 2 ms 12892 KB Output is correct
65 Correct 3 ms 12892 KB Output is correct
66 Correct 3 ms 12892 KB Output is correct
67 Correct 83 ms 35576 KB Output is correct
68 Correct 93 ms 38852 KB Output is correct
69 Correct 88 ms 32604 KB Output is correct
70 Correct 94 ms 33220 KB Output is correct
71 Correct 111 ms 33228 KB Output is correct
72 Correct 99 ms 40904 KB Output is correct
73 Correct 71 ms 32192 KB Output is correct
74 Correct 65 ms 31040 KB Output is correct
75 Correct 90 ms 40380 KB Output is correct
76 Correct 98 ms 34024 KB Output is correct
77 Correct 84 ms 39108 KB Output is correct
78 Correct 78 ms 38892 KB Output is correct
79 Correct 90 ms 40640 KB Output is correct
80 Correct 70 ms 39876 KB Output is correct
81 Correct 113 ms 33220 KB Output is correct
82 Correct 112 ms 33476 KB Output is correct
83 Correct 103 ms 40644 KB Output is correct
84 Correct 77 ms 37568 KB Output is correct
85 Correct 109 ms 33476 KB Output is correct
86 Correct 104 ms 40640 KB Output is correct
87 Correct 100 ms 40640 KB Output is correct
88 Correct 79 ms 34388 KB Output is correct
89 Correct 95 ms 32960 KB Output is correct
90 Correct 124 ms 33476 KB Output is correct
91 Correct 121 ms 33216 KB Output is correct
92 Correct 123 ms 33216 KB Output is correct
93 Correct 114 ms 33216 KB Output is correct
94 Correct 97 ms 32996 KB Output is correct
95 Correct 79 ms 36672 KB Output is correct
96 Correct 68 ms 39616 KB Output is correct
97 Correct 74 ms 25024 KB Output is correct
98 Correct 91 ms 31764 KB Output is correct
99 Correct 90 ms 32964 KB Output is correct
100 Correct 29 ms 16980 KB Output is correct
101 Correct 114 ms 33340 KB Output is correct
102 Correct 99 ms 31172 KB Output is correct
103 Correct 114 ms 31876 KB Output is correct
104 Correct 131 ms 33480 KB Output is correct