Submission #593269

# Submission time Handle Problem Language Result Execution time Memory
593269 2022-07-10T17:57:47 Z 1zaid1 Stranded Far From Home (BOI22_island) C++17
100 / 100
196 ms 50592 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int M = 4e5+1;
#define int long long
vector<int> node[M];
int p[M], sum[M], k[M];
vector<int> bt[M];

int find(int s) {
    return (s == p[s]?s:p[s]=find(p[s]));
}

void uni(int x, int y) {
    if (bt[x].size() < bt[y].size()) swap(x, y);
    for (int i:bt[y]) bt[x].push_back(i);
    bt[y].clear();
    p[y] = x;
    sum[x] += sum[y];
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
 
    int n, m;
    cin >> n >> m;
 
    for (int i = 1; i <= n; i++) cin >> k[i];
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
 
        if (k[a] >= k[b]) node[a].push_back(b);
        else node[b].push_back(a);
    }
 
    vector<int> v;
    for (int i = 1; i <= n; i++) {
        p[i] = i;
        bt[i] = {i};
        sum[i] = k[i];
        // cout << i << ": ";
        // for (int j:node[i]) cout << j << ' '; cout << endl;
    }

    for (int i = 1; i <= n; i++) v.push_back(i);
    sort(v.begin(), v.end(), [](int a, int b) {return k[a] < k[b];});
    for (int s:v) {
        for (int i:node[s]) {
            if (find(i) == find(s)) continue;
            if (sum[find(i)] < k[s]) bt[find(i)].clear();
            uni(find(s), find(i));
        }
    }

    bitset<200005> x;
    for (int i:bt[find(1)]) x[i] = 1;
    for (int i = 1; i <= n; i++) cout << x[i]; cout << endl;
 
    return 0;
}
/*
4 3
4 2 2 1
1 2
3 2
4 1

4 4
2 2 4 3
1 2
1 3
2 3
3 4
*/

Compilation message

island.cpp: In function 'int main()':
island.cpp:58:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   58 |     for (int i = 1; i <= n; i++) cout << x[i]; cout << endl;
      |     ^~~
island.cpp:58:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   58 |     for (int i = 1; i <= n; i++) cout << x[i]; cout << endl;
      |                                                ^~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 10 ms 19156 KB Output is correct
4 Correct 11 ms 19272 KB Output is correct
5 Correct 11 ms 19284 KB Output is correct
6 Correct 10 ms 19284 KB Output is correct
7 Correct 11 ms 19316 KB Output is correct
8 Correct 10 ms 19272 KB Output is correct
9 Correct 10 ms 19352 KB Output is correct
10 Correct 13 ms 19412 KB Output is correct
11 Correct 10 ms 19328 KB Output is correct
12 Correct 10 ms 19332 KB Output is correct
13 Correct 10 ms 19284 KB Output is correct
14 Correct 11 ms 19340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19080 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 126 ms 39380 KB Output is correct
4 Correct 136 ms 46168 KB Output is correct
5 Correct 144 ms 43276 KB Output is correct
6 Correct 142 ms 44652 KB Output is correct
7 Correct 143 ms 45496 KB Output is correct
8 Correct 187 ms 44864 KB Output is correct
9 Correct 124 ms 46220 KB Output is correct
10 Correct 90 ms 37784 KB Output is correct
11 Correct 109 ms 41412 KB Output is correct
12 Correct 175 ms 42048 KB Output is correct
13 Correct 125 ms 47564 KB Output is correct
14 Correct 134 ms 47036 KB Output is correct
15 Correct 129 ms 44568 KB Output is correct
16 Correct 98 ms 43400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 183 ms 44100 KB Output is correct
3 Correct 192 ms 47172 KB Output is correct
4 Correct 142 ms 48432 KB Output is correct
5 Correct 141 ms 48384 KB Output is correct
6 Correct 183 ms 46064 KB Output is correct
7 Correct 151 ms 43300 KB Output is correct
8 Correct 140 ms 43132 KB Output is correct
9 Correct 86 ms 42268 KB Output is correct
10 Correct 125 ms 40920 KB Output is correct
11 Correct 147 ms 46080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 180 ms 39752 KB Output is correct
3 Correct 186 ms 43800 KB Output is correct
4 Correct 188 ms 43704 KB Output is correct
5 Correct 192 ms 50428 KB Output is correct
6 Correct 164 ms 44980 KB Output is correct
7 Correct 133 ms 40420 KB Output is correct
8 Correct 102 ms 46532 KB Output is correct
9 Correct 95 ms 31884 KB Output is correct
10 Correct 168 ms 48956 KB Output is correct
11 Correct 159 ms 45104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 10 ms 19156 KB Output is correct
4 Correct 11 ms 19272 KB Output is correct
5 Correct 11 ms 19284 KB Output is correct
6 Correct 10 ms 19284 KB Output is correct
7 Correct 11 ms 19316 KB Output is correct
8 Correct 10 ms 19272 KB Output is correct
9 Correct 10 ms 19352 KB Output is correct
10 Correct 13 ms 19412 KB Output is correct
11 Correct 10 ms 19328 KB Output is correct
12 Correct 10 ms 19332 KB Output is correct
13 Correct 10 ms 19284 KB Output is correct
14 Correct 11 ms 19340 KB Output is correct
15 Correct 9 ms 19080 KB Output is correct
16 Correct 10 ms 19028 KB Output is correct
17 Correct 126 ms 39380 KB Output is correct
18 Correct 136 ms 46168 KB Output is correct
19 Correct 144 ms 43276 KB Output is correct
20 Correct 142 ms 44652 KB Output is correct
21 Correct 143 ms 45496 KB Output is correct
22 Correct 187 ms 44864 KB Output is correct
23 Correct 124 ms 46220 KB Output is correct
24 Correct 90 ms 37784 KB Output is correct
25 Correct 109 ms 41412 KB Output is correct
26 Correct 175 ms 42048 KB Output is correct
27 Correct 125 ms 47564 KB Output is correct
28 Correct 134 ms 47036 KB Output is correct
29 Correct 129 ms 44568 KB Output is correct
30 Correct 98 ms 43400 KB Output is correct
31 Correct 10 ms 19028 KB Output is correct
32 Correct 183 ms 44100 KB Output is correct
33 Correct 192 ms 47172 KB Output is correct
34 Correct 142 ms 48432 KB Output is correct
35 Correct 141 ms 48384 KB Output is correct
36 Correct 183 ms 46064 KB Output is correct
37 Correct 151 ms 43300 KB Output is correct
38 Correct 140 ms 43132 KB Output is correct
39 Correct 86 ms 42268 KB Output is correct
40 Correct 125 ms 40920 KB Output is correct
41 Correct 147 ms 46080 KB Output is correct
42 Correct 10 ms 19028 KB Output is correct
43 Correct 180 ms 39752 KB Output is correct
44 Correct 186 ms 43800 KB Output is correct
45 Correct 188 ms 43704 KB Output is correct
46 Correct 192 ms 50428 KB Output is correct
47 Correct 164 ms 44980 KB Output is correct
48 Correct 133 ms 40420 KB Output is correct
49 Correct 102 ms 46532 KB Output is correct
50 Correct 95 ms 31884 KB Output is correct
51 Correct 168 ms 48956 KB Output is correct
52 Correct 159 ms 45104 KB Output is correct
53 Correct 10 ms 19028 KB Output is correct
54 Correct 10 ms 19028 KB Output is correct
55 Correct 10 ms 19028 KB Output is correct
56 Correct 11 ms 19284 KB Output is correct
57 Correct 11 ms 19284 KB Output is correct
58 Correct 10 ms 19284 KB Output is correct
59 Correct 10 ms 19284 KB Output is correct
60 Correct 11 ms 19236 KB Output is correct
61 Correct 12 ms 19328 KB Output is correct
62 Correct 11 ms 19412 KB Output is correct
63 Correct 11 ms 19268 KB Output is correct
64 Correct 11 ms 19304 KB Output is correct
65 Correct 10 ms 19284 KB Output is correct
66 Correct 11 ms 19284 KB Output is correct
67 Correct 132 ms 42252 KB Output is correct
68 Correct 128 ms 46596 KB Output is correct
69 Correct 138 ms 42808 KB Output is correct
70 Correct 144 ms 44760 KB Output is correct
71 Correct 153 ms 44192 KB Output is correct
72 Correct 177 ms 44384 KB Output is correct
73 Correct 129 ms 46288 KB Output is correct
74 Correct 91 ms 35988 KB Output is correct
75 Correct 109 ms 40060 KB Output is correct
76 Correct 161 ms 41412 KB Output is correct
77 Correct 127 ms 47392 KB Output is correct
78 Correct 139 ms 45928 KB Output is correct
79 Correct 123 ms 43416 KB Output is correct
80 Correct 88 ms 44224 KB Output is correct
81 Correct 188 ms 46444 KB Output is correct
82 Correct 190 ms 47252 KB Output is correct
83 Correct 134 ms 46536 KB Output is correct
84 Correct 128 ms 48880 KB Output is correct
85 Correct 187 ms 48536 KB Output is correct
86 Correct 144 ms 45320 KB Output is correct
87 Correct 148 ms 45256 KB Output is correct
88 Correct 123 ms 40316 KB Output is correct
89 Correct 145 ms 43712 KB Output is correct
90 Correct 171 ms 42260 KB Output is correct
91 Correct 184 ms 45260 KB Output is correct
92 Correct 185 ms 46696 KB Output is correct
93 Correct 174 ms 49500 KB Output is correct
94 Correct 178 ms 45176 KB Output is correct
95 Correct 122 ms 42140 KB Output is correct
96 Correct 99 ms 46136 KB Output is correct
97 Correct 95 ms 32340 KB Output is correct
98 Correct 171 ms 50592 KB Output is correct
99 Correct 160 ms 46400 KB Output is correct
100 Correct 45 ms 23756 KB Output is correct
101 Correct 196 ms 45368 KB Output is correct
102 Correct 147 ms 40088 KB Output is correct
103 Correct 173 ms 35900 KB Output is correct
104 Correct 188 ms 39356 KB Output is correct