답안 #850476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850476 2023-09-16T15:46:56 Z MinaRagy06 Stranded Far From Home (BOI22_island) C++17
100 / 100
625 ms 63016 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

const int N = 200'005;
int par[N], sz[N], par2[N], bad[N], a[N];
ll cnt[N];
set<array<int, 3>> adj[N];
pair<int, int> find2(int u) {
    if (par2[u] == u) {
        return {u, bad[u]};
    }
    pair<int, int> v = find2(par2[u]);
    bad[u] |= v.second;
    par2[u] = v.first;
    return {par2[u], bad[u]};
}
pair<int, int> find(int u) {
    if (par[u] == u) {
        return {u, bad[u]};
    }
    pair<int, int> v = find(par[u]);
    par[u] = v.first;
    return {par[u], bad[u]};
}
void join2(int u, int v) {
    u = find2(u).first;
    v = find2(v).first;
    if (u == v) return;
    par2[v] = u;
}
void join(int u, int v) {
    u = find(u).first, v = find(v).first;
    if (u == v) return;
    if (sz[u] < sz[v]) swap(u, v);
    par[v] = u, sz[u] += sz[v], cnt[u] += cnt[v];
    for (auto [vnxt, nxt, src] : adj[v]) {
        int x = find(nxt).first;
        if (x != u) {
            adj[u].insert({a[nxt], nxt, src});
        } else {
            adj[u].erase({a[src], src, nxt});
        }
    }
    adj[v].clear();
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        par[i] = i, par2[i] = i, sz[i] = 1, bad[i] = 0;
        cin >> cnt[i];
        a[i] = cnt[i];
    }
    for (int i = 0, u, v; i < m; i++) {
        cin >> u >> v;
        u--, v--;
        adj[u].insert({a[v], v, u});
        adj[v].insert({a[u], u, v});
    }
    priority_queue<pair<ll, pair<int, int>>> pq;
    for (int i = 0; i < n; i++) {
        pq.push({-cnt[i], {i, i}});
    }
    while (pq.size()) {
        int node = pq.top().second.first;
        int node2 = pq.top().second.second;
        ll val = -pq.top().first;
        pq.pop();
        if (node != par[node]) {
            continue;
        }
        if (val != cnt[node]) {
            continue;
        }
        if (sz[node] == n) {
            continue;
        }
        if (adj[node].empty() || val < (*adj[node].begin())[0]) {
            bad[node2] = 1;
            continue;
        }
        int x = (*adj[node].begin())[1];
        join(node, x);
        int New = find(node).first;
        join2(node2, x);
        int New2 = find2(node).first;
        pq.push({-cnt[New], {New, New2}});
    }
    for (int i = 0; i < n; i++) {
        cout << !find2(i).second;
    }
    cout << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 2 ms 14936 KB Output is correct
4 Correct 4 ms 15192 KB Output is correct
5 Correct 4 ms 15192 KB Output is correct
6 Correct 4 ms 15192 KB Output is correct
7 Correct 5 ms 15196 KB Output is correct
8 Correct 4 ms 15192 KB Output is correct
9 Correct 4 ms 15192 KB Output is correct
10 Correct 5 ms 15192 KB Output is correct
11 Correct 4 ms 15192 KB Output is correct
12 Correct 4 ms 15192 KB Output is correct
13 Correct 4 ms 15192 KB Output is correct
14 Correct 4 ms 15192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 2 ms 14936 KB Output is correct
3 Correct 290 ms 46000 KB Output is correct
4 Correct 257 ms 45408 KB Output is correct
5 Correct 293 ms 44484 KB Output is correct
6 Correct 322 ms 44484 KB Output is correct
7 Correct 343 ms 45152 KB Output is correct
8 Correct 336 ms 44688 KB Output is correct
9 Correct 322 ms 45276 KB Output is correct
10 Correct 355 ms 57100 KB Output is correct
11 Correct 365 ms 62428 KB Output is correct
12 Correct 344 ms 45880 KB Output is correct
13 Correct 229 ms 44480 KB Output is correct
14 Correct 242 ms 45004 KB Output is correct
15 Correct 184 ms 45900 KB Output is correct
16 Correct 125 ms 45760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 344 ms 45644 KB Output is correct
3 Correct 330 ms 45252 KB Output is correct
4 Correct 245 ms 44912 KB Output is correct
5 Correct 227 ms 45248 KB Output is correct
6 Correct 350 ms 45508 KB Output is correct
7 Correct 211 ms 46448 KB Output is correct
8 Correct 195 ms 45132 KB Output is correct
9 Correct 117 ms 45248 KB Output is correct
10 Correct 247 ms 46272 KB Output is correct
11 Correct 298 ms 46016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14936 KB Output is correct
2 Correct 412 ms 46076 KB Output is correct
3 Correct 350 ms 45408 KB Output is correct
4 Correct 408 ms 44496 KB Output is correct
5 Correct 344 ms 45000 KB Output is correct
6 Correct 352 ms 45612 KB Output is correct
7 Correct 383 ms 63016 KB Output is correct
8 Correct 320 ms 44760 KB Output is correct
9 Correct 613 ms 42184 KB Output is correct
10 Correct 335 ms 44892 KB Output is correct
11 Correct 279 ms 44708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 2 ms 14936 KB Output is correct
4 Correct 4 ms 15192 KB Output is correct
5 Correct 4 ms 15192 KB Output is correct
6 Correct 4 ms 15192 KB Output is correct
7 Correct 5 ms 15196 KB Output is correct
8 Correct 4 ms 15192 KB Output is correct
9 Correct 4 ms 15192 KB Output is correct
10 Correct 5 ms 15192 KB Output is correct
11 Correct 4 ms 15192 KB Output is correct
12 Correct 4 ms 15192 KB Output is correct
13 Correct 4 ms 15192 KB Output is correct
14 Correct 4 ms 15192 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 2 ms 14936 KB Output is correct
17 Correct 290 ms 46000 KB Output is correct
18 Correct 257 ms 45408 KB Output is correct
19 Correct 293 ms 44484 KB Output is correct
20 Correct 322 ms 44484 KB Output is correct
21 Correct 343 ms 45152 KB Output is correct
22 Correct 336 ms 44688 KB Output is correct
23 Correct 322 ms 45276 KB Output is correct
24 Correct 355 ms 57100 KB Output is correct
25 Correct 365 ms 62428 KB Output is correct
26 Correct 344 ms 45880 KB Output is correct
27 Correct 229 ms 44480 KB Output is correct
28 Correct 242 ms 45004 KB Output is correct
29 Correct 184 ms 45900 KB Output is correct
30 Correct 125 ms 45760 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 344 ms 45644 KB Output is correct
33 Correct 330 ms 45252 KB Output is correct
34 Correct 245 ms 44912 KB Output is correct
35 Correct 227 ms 45248 KB Output is correct
36 Correct 350 ms 45508 KB Output is correct
37 Correct 211 ms 46448 KB Output is correct
38 Correct 195 ms 45132 KB Output is correct
39 Correct 117 ms 45248 KB Output is correct
40 Correct 247 ms 46272 KB Output is correct
41 Correct 298 ms 46016 KB Output is correct
42 Correct 2 ms 14936 KB Output is correct
43 Correct 412 ms 46076 KB Output is correct
44 Correct 350 ms 45408 KB Output is correct
45 Correct 408 ms 44496 KB Output is correct
46 Correct 344 ms 45000 KB Output is correct
47 Correct 352 ms 45612 KB Output is correct
48 Correct 383 ms 63016 KB Output is correct
49 Correct 320 ms 44760 KB Output is correct
50 Correct 613 ms 42184 KB Output is correct
51 Correct 335 ms 44892 KB Output is correct
52 Correct 279 ms 44708 KB Output is correct
53 Correct 3 ms 14936 KB Output is correct
54 Correct 3 ms 14936 KB Output is correct
55 Correct 2 ms 14936 KB Output is correct
56 Correct 5 ms 15192 KB Output is correct
57 Correct 4 ms 15192 KB Output is correct
58 Correct 4 ms 15192 KB Output is correct
59 Correct 5 ms 15192 KB Output is correct
60 Correct 6 ms 15192 KB Output is correct
61 Correct 4 ms 15192 KB Output is correct
62 Correct 4 ms 15192 KB Output is correct
63 Correct 4 ms 15192 KB Output is correct
64 Correct 4 ms 15192 KB Output is correct
65 Correct 4 ms 15192 KB Output is correct
66 Correct 5 ms 15192 KB Output is correct
67 Correct 286 ms 46516 KB Output is correct
68 Correct 256 ms 44992 KB Output is correct
69 Correct 306 ms 45260 KB Output is correct
70 Correct 317 ms 46532 KB Output is correct
71 Correct 304 ms 46016 KB Output is correct
72 Correct 349 ms 46056 KB Output is correct
73 Correct 294 ms 44740 KB Output is correct
74 Correct 384 ms 56344 KB Output is correct
75 Correct 343 ms 62488 KB Output is correct
76 Correct 332 ms 45528 KB Output is correct
77 Correct 242 ms 44992 KB Output is correct
78 Correct 235 ms 46328 KB Output is correct
79 Correct 180 ms 46588 KB Output is correct
80 Correct 117 ms 46020 KB Output is correct
81 Correct 349 ms 46280 KB Output is correct
82 Correct 325 ms 45760 KB Output is correct
83 Correct 244 ms 45504 KB Output is correct
84 Correct 227 ms 45760 KB Output is correct
85 Correct 358 ms 45248 KB Output is correct
86 Correct 191 ms 46040 KB Output is correct
87 Correct 191 ms 46016 KB Output is correct
88 Correct 244 ms 46016 KB Output is correct
89 Correct 275 ms 46272 KB Output is correct
90 Correct 402 ms 45248 KB Output is correct
91 Correct 398 ms 44996 KB Output is correct
92 Correct 390 ms 45000 KB Output is correct
93 Correct 411 ms 46248 KB Output is correct
94 Correct 387 ms 45932 KB Output is correct
95 Correct 374 ms 62944 KB Output is correct
96 Correct 309 ms 44560 KB Output is correct
97 Correct 520 ms 42196 KB Output is correct
98 Correct 331 ms 46528 KB Output is correct
99 Correct 298 ms 46016 KB Output is correct
100 Correct 625 ms 40372 KB Output is correct
101 Correct 396 ms 45280 KB Output is correct
102 Correct 490 ms 46076 KB Output is correct
103 Correct 465 ms 44956 KB Output is correct
104 Correct 415 ms 46332 KB Output is correct