Submission #601528

# Submission time Handle Problem Language Result Execution time Memory
601528 2022-07-22T07:14:49 Z 이동현(#8475) Stranded Far From Home (BOI22_island) C++17
100 / 100
513 ms 93372 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int NS = (int)4e5 + 4;

int n, m;
int a[NS];
vector<int> way[NS], way2[NS];
int pr[NS], mesum[NS], chk[NS], ans[NS];
set<pair<int, int>> st[NS];
int nodeN;

int fd(int x){
    assert(x != 0);
    return (x == pr[x] ? x : pr[x] = fd(pr[x]));
}

void unite(int x, int y){
    x = fd(x), y = fd(y);
    if(x == y) return;
    if((int)st[x].size() > (int)st[y].size()){
        swap(x, y);
    }
    pr[x] = y;
    way2[y].push_back(x);
    mesum[y] += mesum[x];
    for(auto&i:st[x]){
        st[y].insert(i);
    }
}

void dfs(int x){
    for(auto&nxt:way2[x]){
        ans[nxt] += ans[x];
        dfs(nxt);
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    nodeN = n;
    vector<vector<int>> srt;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        srt.push_back({a[i], i});
    }
    for(int i = 0; i < m; ++i){
        int x, y; cin >> x >> y;
        way[x].push_back(y), way[y].push_back(x);
    }
    sort(srt.begin(), srt.end());
    for(int i = 0; i < n; ++i){
        int now = srt[i][1];
        mesum[now] = a[now];
        chk[now] = 1; pr[now] = now;
        for(auto&nxt:way[now]){
            if(chk[nxt]){
                int npr = fd(nxt);
                auto p = st[npr].lower_bound({a[now], now});
                if(p != st[npr].end() && p->second == now){
                    st[npr].erase(p);
                }
            }
            else{
                st[now].insert({a[nxt], nxt});
            }
        }
        for(auto&nxt:way[now]){
            if(!chk[nxt]){
                continue;
            }
            unite(now, nxt);
        }
        int u = fd(now);
        if((int)st[u].size() && mesum[u] < st[u].begin()->first){
            ++nodeN;
            pr[u] = pr[nodeN] = nodeN;
            way2[nodeN].push_back(u);
            ans[u] = 1;
            mesum[nodeN] = mesum[u];
            swap(st[u], st[nodeN]);
        }
    }
    dfs(fd(1));
    for(int i = 1; i <= n; ++i){
        cout << (!ans[i]);
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 18 ms 37876 KB Output is correct
3 Correct 18 ms 37860 KB Output is correct
4 Correct 22 ms 38288 KB Output is correct
5 Correct 19 ms 38284 KB Output is correct
6 Correct 19 ms 38228 KB Output is correct
7 Correct 20 ms 38372 KB Output is correct
8 Correct 19 ms 38356 KB Output is correct
9 Correct 20 ms 38356 KB Output is correct
10 Correct 20 ms 38368 KB Output is correct
11 Correct 21 ms 38356 KB Output is correct
12 Correct 23 ms 38244 KB Output is correct
13 Correct 19 ms 38268 KB Output is correct
14 Correct 20 ms 38284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 37884 KB Output is correct
2 Correct 21 ms 37820 KB Output is correct
3 Correct 189 ms 73976 KB Output is correct
4 Correct 221 ms 77536 KB Output is correct
5 Correct 289 ms 73504 KB Output is correct
6 Correct 338 ms 74724 KB Output is correct
7 Correct 335 ms 74800 KB Output is correct
8 Correct 393 ms 81592 KB Output is correct
9 Correct 237 ms 76940 KB Output is correct
10 Correct 443 ms 93328 KB Output is correct
11 Correct 345 ms 80880 KB Output is correct
12 Correct 333 ms 78496 KB Output is correct
13 Correct 198 ms 77212 KB Output is correct
14 Correct 201 ms 76948 KB Output is correct
15 Correct 218 ms 74612 KB Output is correct
16 Correct 140 ms 74280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 37844 KB Output is correct
2 Correct 487 ms 79340 KB Output is correct
3 Correct 431 ms 79708 KB Output is correct
4 Correct 236 ms 74608 KB Output is correct
5 Correct 214 ms 75384 KB Output is correct
6 Correct 409 ms 79648 KB Output is correct
7 Correct 222 ms 77236 KB Output is correct
8 Correct 235 ms 77176 KB Output is correct
9 Correct 131 ms 74236 KB Output is correct
10 Correct 239 ms 82640 KB Output is correct
11 Correct 296 ms 78932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 473 ms 79916 KB Output is correct
3 Correct 486 ms 79516 KB Output is correct
4 Correct 462 ms 79216 KB Output is correct
5 Correct 414 ms 75828 KB Output is correct
6 Correct 374 ms 77016 KB Output is correct
7 Correct 285 ms 75340 KB Output is correct
8 Correct 176 ms 86012 KB Output is correct
9 Correct 252 ms 68680 KB Output is correct
10 Correct 364 ms 75908 KB Output is correct
11 Correct 249 ms 78748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 18 ms 37876 KB Output is correct
3 Correct 18 ms 37860 KB Output is correct
4 Correct 22 ms 38288 KB Output is correct
5 Correct 19 ms 38284 KB Output is correct
6 Correct 19 ms 38228 KB Output is correct
7 Correct 20 ms 38372 KB Output is correct
8 Correct 19 ms 38356 KB Output is correct
9 Correct 20 ms 38356 KB Output is correct
10 Correct 20 ms 38368 KB Output is correct
11 Correct 21 ms 38356 KB Output is correct
12 Correct 23 ms 38244 KB Output is correct
13 Correct 19 ms 38268 KB Output is correct
14 Correct 20 ms 38284 KB Output is correct
15 Correct 17 ms 37884 KB Output is correct
16 Correct 21 ms 37820 KB Output is correct
17 Correct 189 ms 73976 KB Output is correct
18 Correct 221 ms 77536 KB Output is correct
19 Correct 289 ms 73504 KB Output is correct
20 Correct 338 ms 74724 KB Output is correct
21 Correct 335 ms 74800 KB Output is correct
22 Correct 393 ms 81592 KB Output is correct
23 Correct 237 ms 76940 KB Output is correct
24 Correct 443 ms 93328 KB Output is correct
25 Correct 345 ms 80880 KB Output is correct
26 Correct 333 ms 78496 KB Output is correct
27 Correct 198 ms 77212 KB Output is correct
28 Correct 201 ms 76948 KB Output is correct
29 Correct 218 ms 74612 KB Output is correct
30 Correct 140 ms 74280 KB Output is correct
31 Correct 20 ms 37844 KB Output is correct
32 Correct 487 ms 79340 KB Output is correct
33 Correct 431 ms 79708 KB Output is correct
34 Correct 236 ms 74608 KB Output is correct
35 Correct 214 ms 75384 KB Output is correct
36 Correct 409 ms 79648 KB Output is correct
37 Correct 222 ms 77236 KB Output is correct
38 Correct 235 ms 77176 KB Output is correct
39 Correct 131 ms 74236 KB Output is correct
40 Correct 239 ms 82640 KB Output is correct
41 Correct 296 ms 78932 KB Output is correct
42 Correct 18 ms 37844 KB Output is correct
43 Correct 473 ms 79916 KB Output is correct
44 Correct 486 ms 79516 KB Output is correct
45 Correct 462 ms 79216 KB Output is correct
46 Correct 414 ms 75828 KB Output is correct
47 Correct 374 ms 77016 KB Output is correct
48 Correct 285 ms 75340 KB Output is correct
49 Correct 176 ms 86012 KB Output is correct
50 Correct 252 ms 68680 KB Output is correct
51 Correct 364 ms 75908 KB Output is correct
52 Correct 249 ms 78748 KB Output is correct
53 Correct 19 ms 37844 KB Output is correct
54 Correct 25 ms 37844 KB Output is correct
55 Correct 18 ms 37844 KB Output is correct
56 Correct 21 ms 38384 KB Output is correct
57 Correct 25 ms 38372 KB Output is correct
58 Correct 20 ms 38228 KB Output is correct
59 Correct 21 ms 38296 KB Output is correct
60 Correct 19 ms 38204 KB Output is correct
61 Correct 19 ms 38356 KB Output is correct
62 Correct 24 ms 38368 KB Output is correct
63 Correct 20 ms 38324 KB Output is correct
64 Correct 24 ms 38356 KB Output is correct
65 Correct 21 ms 38228 KB Output is correct
66 Correct 20 ms 38332 KB Output is correct
67 Correct 216 ms 73920 KB Output is correct
68 Correct 213 ms 77488 KB Output is correct
69 Correct 297 ms 73560 KB Output is correct
70 Correct 328 ms 74640 KB Output is correct
71 Correct 355 ms 74816 KB Output is correct
72 Correct 344 ms 81592 KB Output is correct
73 Correct 273 ms 76972 KB Output is correct
74 Correct 427 ms 93372 KB Output is correct
75 Correct 335 ms 80784 KB Output is correct
76 Correct 352 ms 78568 KB Output is correct
77 Correct 211 ms 77184 KB Output is correct
78 Correct 187 ms 76960 KB Output is correct
79 Correct 173 ms 74608 KB Output is correct
80 Correct 141 ms 74368 KB Output is correct
81 Correct 448 ms 79456 KB Output is correct
82 Correct 439 ms 79700 KB Output is correct
83 Correct 233 ms 74592 KB Output is correct
84 Correct 229 ms 75420 KB Output is correct
85 Correct 436 ms 79700 KB Output is correct
86 Correct 258 ms 77280 KB Output is correct
87 Correct 248 ms 77268 KB Output is correct
88 Correct 254 ms 82624 KB Output is correct
89 Correct 320 ms 78872 KB Output is correct
90 Correct 486 ms 79876 KB Output is correct
91 Correct 486 ms 79668 KB Output is correct
92 Correct 437 ms 79188 KB Output is correct
93 Correct 385 ms 75840 KB Output is correct
94 Correct 378 ms 76960 KB Output is correct
95 Correct 262 ms 75276 KB Output is correct
96 Correct 198 ms 86028 KB Output is correct
97 Correct 286 ms 68652 KB Output is correct
98 Correct 338 ms 75908 KB Output is correct
99 Correct 268 ms 78812 KB Output is correct
100 Correct 126 ms 55184 KB Output is correct
101 Correct 501 ms 80156 KB Output is correct
102 Correct 355 ms 77608 KB Output is correct
103 Correct 495 ms 81304 KB Output is correct
104 Correct 513 ms 81024 KB Output is correct