Submission #951781

# Submission time Handle Problem Language Result Execution time Memory
951781 2024-03-22T15:32:33 Z Ludissey Stranded Far From Home (BOI22_island) C++14
100 / 100
217 ms 36224 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define sz(a) (int)a.size()
const int mod=1e9+7;
vector<int> parent;
vector<vector<int>> neigh;
vector<bool> poss;
vector<int> sz;
vector<int> sum;
vector<int> v;
vector<vector<int>> child;


int getParent(int a){
    if(parent[a]==a) return a;
    return parent[a]=getParent(parent[a]);
}

void unite(int a, int b){
    a=getParent(a); b=getParent(b);
    if(a==b) return;
    if(sum[a]<sum[b]) swap(a,b);
    sz[a]+=sz[b];
    sum[a]+=sum[b];
    parent[b]=a;
    child[a].push_back(b);
}
void deact(int a){
    poss[a]=false;
    for (auto u : child[a]) deact(u);
}


signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    sz.resize(N,1); poss.resize(N,true); parent.resize(N); neigh.resize(N); v.resize(N); sum.resize(N); child.resize(N);
    priority_queue<pair<int,int>> pq;
    for (int i = 0; i < N; i++) { 
        cin >> v[i]; parent[i]=i; sum[i]=v[i]; pq.push({-v[i], i}); 
    }
    for (int i = 0; i < M; i++) { 
        int u,vs;  cin >> u >> vs;
        neigh[u-1].push_back(vs-1); 
        neigh[vs-1].push_back(u-1);
    }
    while(!pq.empty()){
        int i=pq.top().second; pq.pop();
        for (auto u:neigh[i])
        {
            if(v[u]<=v[i]) {
                if(sum[getParent(u)]<v[i]) {
                    deact(getParent(u));
                }
                unite(i,u);
            }
        }
        

    }
    for (int i = 0; i < N; i++){
        cout << poss[i] << "";
    }
    cout << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 720 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 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 130 ms 29560 KB Output is correct
4 Correct 118 ms 29104 KB Output is correct
5 Correct 147 ms 29204 KB Output is correct
6 Correct 156 ms 35008 KB Output is correct
7 Correct 150 ms 34496 KB Output is correct
8 Correct 155 ms 34864 KB Output is correct
9 Correct 125 ms 35304 KB Output is correct
10 Correct 103 ms 34496 KB Output is correct
11 Correct 98 ms 34488 KB Output is correct
12 Correct 151 ms 33064 KB Output is correct
13 Correct 105 ms 32140 KB Output is correct
14 Correct 112 ms 32064 KB Output is correct
15 Correct 103 ms 33728 KB Output is correct
16 Correct 86 ms 32764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 176 ms 28868 KB Output is correct
3 Correct 180 ms 33692 KB Output is correct
4 Correct 112 ms 33728 KB Output is correct
5 Correct 103 ms 32220 KB Output is correct
6 Correct 178 ms 33544 KB Output is correct
7 Correct 112 ms 34240 KB Output is correct
8 Correct 114 ms 34508 KB Output is correct
9 Correct 89 ms 33352 KB Output is correct
10 Correct 128 ms 33668 KB Output is correct
11 Correct 139 ms 31892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 193 ms 29660 KB Output is correct
3 Correct 188 ms 34020 KB Output is correct
4 Correct 196 ms 35028 KB Output is correct
5 Correct 163 ms 33768 KB Output is correct
6 Correct 147 ms 32704 KB Output is correct
7 Correct 111 ms 35216 KB Output is correct
8 Correct 89 ms 33732 KB Output is correct
9 Correct 85 ms 19208 KB Output is correct
10 Correct 160 ms 32416 KB Output is correct
11 Correct 141 ms 31684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 720 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 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 130 ms 29560 KB Output is correct
18 Correct 118 ms 29104 KB Output is correct
19 Correct 147 ms 29204 KB Output is correct
20 Correct 156 ms 35008 KB Output is correct
21 Correct 150 ms 34496 KB Output is correct
22 Correct 155 ms 34864 KB Output is correct
23 Correct 125 ms 35304 KB Output is correct
24 Correct 103 ms 34496 KB Output is correct
25 Correct 98 ms 34488 KB Output is correct
26 Correct 151 ms 33064 KB Output is correct
27 Correct 105 ms 32140 KB Output is correct
28 Correct 112 ms 32064 KB Output is correct
29 Correct 103 ms 33728 KB Output is correct
30 Correct 86 ms 32764 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 176 ms 28868 KB Output is correct
33 Correct 180 ms 33692 KB Output is correct
34 Correct 112 ms 33728 KB Output is correct
35 Correct 103 ms 32220 KB Output is correct
36 Correct 178 ms 33544 KB Output is correct
37 Correct 112 ms 34240 KB Output is correct
38 Correct 114 ms 34508 KB Output is correct
39 Correct 89 ms 33352 KB Output is correct
40 Correct 128 ms 33668 KB Output is correct
41 Correct 139 ms 31892 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 193 ms 29660 KB Output is correct
44 Correct 188 ms 34020 KB Output is correct
45 Correct 196 ms 35028 KB Output is correct
46 Correct 163 ms 33768 KB Output is correct
47 Correct 147 ms 32704 KB Output is correct
48 Correct 111 ms 35216 KB Output is correct
49 Correct 89 ms 33732 KB Output is correct
50 Correct 85 ms 19208 KB Output is correct
51 Correct 160 ms 32416 KB Output is correct
52 Correct 141 ms 31684 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 348 KB Output is correct
56 Correct 2 ms 604 KB Output is correct
57 Correct 2 ms 600 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 648 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 600 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 1 ms 604 KB Output is correct
66 Correct 2 ms 856 KB Output is correct
67 Correct 120 ms 33648 KB Output is correct
68 Correct 120 ms 32964 KB Output is correct
69 Correct 141 ms 32960 KB Output is correct
70 Correct 153 ms 35044 KB Output is correct
71 Correct 148 ms 34224 KB Output is correct
72 Correct 169 ms 34752 KB Output is correct
73 Correct 125 ms 36224 KB Output is correct
74 Correct 103 ms 34752 KB Output is correct
75 Correct 99 ms 34752 KB Output is correct
76 Correct 148 ms 33216 KB Output is correct
77 Correct 104 ms 32816 KB Output is correct
78 Correct 105 ms 32196 KB Output is correct
79 Correct 107 ms 33656 KB Output is correct
80 Correct 90 ms 32696 KB Output is correct
81 Correct 183 ms 33472 KB Output is correct
82 Correct 182 ms 33536 KB Output is correct
83 Correct 125 ms 33752 KB Output is correct
84 Correct 102 ms 32044 KB Output is correct
85 Correct 185 ms 33988 KB Output is correct
86 Correct 113 ms 34500 KB Output is correct
87 Correct 116 ms 33800 KB Output is correct
88 Correct 110 ms 33048 KB Output is correct
89 Correct 145 ms 32444 KB Output is correct
90 Correct 201 ms 34140 KB Output is correct
91 Correct 202 ms 33844 KB Output is correct
92 Correct 190 ms 34752 KB Output is correct
93 Correct 173 ms 34392 KB Output is correct
94 Correct 145 ms 32960 KB Output is correct
95 Correct 106 ms 35264 KB Output is correct
96 Correct 89 ms 33104 KB Output is correct
97 Correct 102 ms 19396 KB Output is correct
98 Correct 148 ms 32284 KB Output is correct
99 Correct 142 ms 31680 KB Output is correct
100 Correct 30 ms 7252 KB Output is correct
101 Correct 217 ms 34204 KB Output is correct
102 Correct 120 ms 29376 KB Output is correct
103 Correct 168 ms 29876 KB Output is correct
104 Correct 210 ms 33824 KB Output is correct