Submission #927719

# Submission time Handle Problem Language Result Execution time Memory
927719 2024-02-15T09:19:34 Z berr Stranded Far From Home (BOI22_island) C++17
100 / 100
201 ms 48244 KB
//ᓚᘏᗢ
 
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;

struct dsu{
    int n;
    vector<vector<int>> available;
    vector<int> sum, par, a;

    dsu(int _n, vector<int> x){
        n = _n;
        sum = x;
        par.resize(n);
        a=x;
        available.resize(n);

        iota(par.begin(), par.end(), 0);
        for(int i=0; i<n; i++){
            available[i].push_back(i);
        }
    }

    int find(int x){
        if(par[x]==x) return x;
        return par[x] = find(par[x]);
    }

    int merge(int x, int y){
        int tx=x;

        x = find(x); y=find(y);

        if(x==y) return 0;
        par[y] = x; 
        sum[x] += sum[y];
        if(sum[y] <a[tx]) return 1;

        if(available[y].size() > available[x].size()){
            swap(available[x], available[y]);
        }

        while(available[y].size()){
            available[x].push_back(available[y].back());
            available[y].pop_back();
        }
        return 1;
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m; cin >> n >> m;
    vector<int> a(n), id(n);

    for(auto &i: a) cin >> i;

    iota(id.begin(), id.end(), 0);

    sort(id.begin(), id.end(), [&](int i, int j){
        return a[i]<a[j];
    });

    vector<vector<int>> g(n);
    dsu d(n, a);

    for(int i=0; i<m; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for(auto i: id){
        for(auto v: g[i]){
            if(a[v] <= a[i]){

               d.merge(i, v);
            }
        }
    }

    vector<int> ar =d.available[d.find(id.back())];
    vector<int> ans(n);


    for(auto i: ar) ans[i]=1;

    for(auto i: ans) cout<<i;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 720 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 155 ms 36076 KB Output is correct
4 Correct 106 ms 41268 KB Output is correct
5 Correct 120 ms 43240 KB Output is correct
6 Correct 124 ms 44744 KB Output is correct
7 Correct 160 ms 45012 KB Output is correct
8 Correct 197 ms 44492 KB Output is correct
9 Correct 130 ms 48244 KB Output is correct
10 Correct 96 ms 37100 KB Output is correct
11 Correct 91 ms 41268 KB Output is correct
12 Correct 154 ms 39964 KB Output is correct
13 Correct 133 ms 44704 KB Output is correct
14 Correct 104 ms 43576 KB Output is correct
15 Correct 98 ms 39344 KB Output is correct
16 Correct 76 ms 38472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 154 ms 40676 KB Output is correct
3 Correct 160 ms 40116 KB Output is correct
4 Correct 126 ms 43316 KB Output is correct
5 Correct 107 ms 45184 KB Output is correct
6 Correct 152 ms 45024 KB Output is correct
7 Correct 116 ms 39488 KB Output is correct
8 Correct 115 ms 39476 KB Output is correct
9 Correct 76 ms 38468 KB Output is correct
10 Correct 141 ms 40828 KB Output is correct
11 Correct 125 ms 42292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 183 ms 37428 KB Output is correct
3 Correct 149 ms 38204 KB Output is correct
4 Correct 154 ms 40168 KB Output is correct
5 Correct 171 ms 42020 KB Output is correct
6 Correct 150 ms 41864 KB Output is correct
7 Correct 98 ms 42792 KB Output is correct
8 Correct 92 ms 43576 KB Output is correct
9 Correct 82 ms 22848 KB Output is correct
10 Correct 146 ms 45368 KB Output is correct
11 Correct 155 ms 42412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 720 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 155 ms 36076 KB Output is correct
18 Correct 106 ms 41268 KB Output is correct
19 Correct 120 ms 43240 KB Output is correct
20 Correct 124 ms 44744 KB Output is correct
21 Correct 160 ms 45012 KB Output is correct
22 Correct 197 ms 44492 KB Output is correct
23 Correct 130 ms 48244 KB Output is correct
24 Correct 96 ms 37100 KB Output is correct
25 Correct 91 ms 41268 KB Output is correct
26 Correct 154 ms 39964 KB Output is correct
27 Correct 133 ms 44704 KB Output is correct
28 Correct 104 ms 43576 KB Output is correct
29 Correct 98 ms 39344 KB Output is correct
30 Correct 76 ms 38472 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 154 ms 40676 KB Output is correct
33 Correct 160 ms 40116 KB Output is correct
34 Correct 126 ms 43316 KB Output is correct
35 Correct 107 ms 45184 KB Output is correct
36 Correct 152 ms 45024 KB Output is correct
37 Correct 116 ms 39488 KB Output is correct
38 Correct 115 ms 39476 KB Output is correct
39 Correct 76 ms 38468 KB Output is correct
40 Correct 141 ms 40828 KB Output is correct
41 Correct 125 ms 42292 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 183 ms 37428 KB Output is correct
44 Correct 149 ms 38204 KB Output is correct
45 Correct 154 ms 40168 KB Output is correct
46 Correct 171 ms 42020 KB Output is correct
47 Correct 150 ms 41864 KB Output is correct
48 Correct 98 ms 42792 KB Output is correct
49 Correct 92 ms 43576 KB Output is correct
50 Correct 82 ms 22848 KB Output is correct
51 Correct 146 ms 45368 KB Output is correct
52 Correct 155 ms 42412 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 2 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 892 KB Output is correct
63 Correct 1 ms 860 KB Output is correct
64 Correct 1 ms 860 KB Output is correct
65 Correct 1 ms 604 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 104 ms 40172 KB Output is correct
68 Correct 111 ms 44304 KB Output is correct
69 Correct 126 ms 43220 KB Output is correct
70 Correct 123 ms 44892 KB Output is correct
71 Correct 123 ms 45024 KB Output is correct
72 Correct 171 ms 44344 KB Output is correct
73 Correct 119 ms 48096 KB Output is correct
74 Correct 79 ms 36924 KB Output is correct
75 Correct 97 ms 41392 KB Output is correct
76 Correct 176 ms 40520 KB Output is correct
77 Correct 99 ms 44596 KB Output is correct
78 Correct 107 ms 43576 KB Output is correct
79 Correct 107 ms 39476 KB Output is correct
80 Correct 82 ms 38472 KB Output is correct
81 Correct 158 ms 45116 KB Output is correct
82 Correct 146 ms 44760 KB Output is correct
83 Correct 126 ms 47828 KB Output is correct
84 Correct 106 ms 45108 KB Output is correct
85 Correct 188 ms 45112 KB Output is correct
86 Correct 126 ms 39704 KB Output is correct
87 Correct 111 ms 39564 KB Output is correct
88 Correct 111 ms 40752 KB Output is correct
89 Correct 124 ms 42296 KB Output is correct
90 Correct 149 ms 41708 KB Output is correct
91 Correct 201 ms 42812 KB Output is correct
92 Correct 201 ms 44636 KB Output is correct
93 Correct 160 ms 46556 KB Output is correct
94 Correct 145 ms 41960 KB Output is correct
95 Correct 97 ms 42804 KB Output is correct
96 Correct 90 ms 43612 KB Output is correct
97 Correct 85 ms 22848 KB Output is correct
98 Correct 143 ms 45160 KB Output is correct
99 Correct 125 ms 42572 KB Output is correct
100 Correct 32 ms 7228 KB Output is correct
101 Correct 171 ms 43128 KB Output is correct
102 Correct 145 ms 35080 KB Output is correct
103 Correct 195 ms 35532 KB Output is correct
104 Correct 177 ms 40792 KB Output is correct