Submission #574165

# Submission time Handle Problem Language Result Execution time Memory
574165 2022-06-08T05:24:11 Z MilosMilutinovic Stranded Far From Home (BOI22_island) C++14
100 / 100
252 ms 36804 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, s[N], fa[N], mx[N], ans[N];
long long sum[N];
vector<int> g[N], ch[N];
int getfa(int x) {
    return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}
void unite(int x, int y) {
    x = getfa(x);
    y = getfa(y);
    if (x == y)
        return;
    if (sum[x] < mx[y])
        ch[x].clear();
    if (mx[x] > sum[y])
        ch[y].clear();
    if (ch[x].size() < ch[y].size())
        swap(x, y);
    for (int i : ch[y])
        ch[x].push_back(i);
    fa[y] = x;
    mx[x] = max(mx[x], mx[y]);
    sum[x] += sum[y];
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> s[i];
    vector<pair<int, int>> edg;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
        edg.push_back({u, v});
    }
    sort(edg.begin(), edg.end(), [&](pair<int, int> x, pair<int, int> y) {
        return max(s[x.first], s[x.second]) < max(s[y.first], s[y.second]);
    });
    for (int i = 1; i <= n; i++) {
        fa[i] = i;
        ch[i] = {i};
        mx[i] = s[i];
        sum[i] = s[i];
    }
    for (auto& e : edg) {
        int u = e.first;
        int v = e.second;
        unite(u, v);
    }
    for (int i : ch[getfa(1)])
        ans[i] = 1;
    for (int i = 1; i <= n; i++)
        cout << ans[i];
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 7 ms 9668 KB Output is correct
4 Correct 8 ms 9836 KB Output is correct
5 Correct 7 ms 9940 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 8 ms 9908 KB Output is correct
8 Correct 7 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 8 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 9 ms 9940 KB Output is correct
14 Correct 8 ms 9944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 201 ms 30240 KB Output is correct
4 Correct 205 ms 35588 KB Output is correct
5 Correct 213 ms 31208 KB Output is correct
6 Correct 210 ms 32040 KB Output is correct
7 Correct 219 ms 31992 KB Output is correct
8 Correct 252 ms 34280 KB Output is correct
9 Correct 194 ms 32740 KB Output is correct
10 Correct 116 ms 28604 KB Output is correct
11 Correct 179 ms 31280 KB Output is correct
12 Correct 205 ms 30100 KB Output is correct
13 Correct 195 ms 36168 KB Output is correct
14 Correct 200 ms 35268 KB Output is correct
15 Correct 157 ms 30388 KB Output is correct
16 Correct 106 ms 30328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 223 ms 32632 KB Output is correct
3 Correct 192 ms 32772 KB Output is correct
4 Correct 222 ms 36756 KB Output is correct
5 Correct 219 ms 36144 KB Output is correct
6 Correct 194 ms 32604 KB Output is correct
7 Correct 200 ms 30480 KB Output is correct
8 Correct 199 ms 30488 KB Output is correct
9 Correct 101 ms 30244 KB Output is correct
10 Correct 177 ms 32652 KB Output is correct
11 Correct 183 ms 32924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 192 ms 30472 KB Output is correct
3 Correct 220 ms 31080 KB Output is correct
4 Correct 211 ms 32064 KB Output is correct
5 Correct 252 ms 33460 KB Output is correct
6 Correct 204 ms 31032 KB Output is correct
7 Correct 145 ms 31272 KB Output is correct
8 Correct 134 ms 31312 KB Output is correct
9 Correct 112 ms 21512 KB Output is correct
10 Correct 214 ms 33320 KB Output is correct
11 Correct 231 ms 33056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 7 ms 9668 KB Output is correct
4 Correct 8 ms 9836 KB Output is correct
5 Correct 7 ms 9940 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 8 ms 9908 KB Output is correct
8 Correct 7 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 8 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 9 ms 9940 KB Output is correct
14 Correct 8 ms 9944 KB Output is correct
15 Correct 7 ms 9684 KB Output is correct
16 Correct 7 ms 9684 KB Output is correct
17 Correct 201 ms 30240 KB Output is correct
18 Correct 205 ms 35588 KB Output is correct
19 Correct 213 ms 31208 KB Output is correct
20 Correct 210 ms 32040 KB Output is correct
21 Correct 219 ms 31992 KB Output is correct
22 Correct 252 ms 34280 KB Output is correct
23 Correct 194 ms 32740 KB Output is correct
24 Correct 116 ms 28604 KB Output is correct
25 Correct 179 ms 31280 KB Output is correct
26 Correct 205 ms 30100 KB Output is correct
27 Correct 195 ms 36168 KB Output is correct
28 Correct 200 ms 35268 KB Output is correct
29 Correct 157 ms 30388 KB Output is correct
30 Correct 106 ms 30328 KB Output is correct
31 Correct 7 ms 9684 KB Output is correct
32 Correct 223 ms 32632 KB Output is correct
33 Correct 192 ms 32772 KB Output is correct
34 Correct 222 ms 36756 KB Output is correct
35 Correct 219 ms 36144 KB Output is correct
36 Correct 194 ms 32604 KB Output is correct
37 Correct 200 ms 30480 KB Output is correct
38 Correct 199 ms 30488 KB Output is correct
39 Correct 101 ms 30244 KB Output is correct
40 Correct 177 ms 32652 KB Output is correct
41 Correct 183 ms 32924 KB Output is correct
42 Correct 6 ms 9684 KB Output is correct
43 Correct 192 ms 30472 KB Output is correct
44 Correct 220 ms 31080 KB Output is correct
45 Correct 211 ms 32064 KB Output is correct
46 Correct 252 ms 33460 KB Output is correct
47 Correct 204 ms 31032 KB Output is correct
48 Correct 145 ms 31272 KB Output is correct
49 Correct 134 ms 31312 KB Output is correct
50 Correct 112 ms 21512 KB Output is correct
51 Correct 214 ms 33320 KB Output is correct
52 Correct 231 ms 33056 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 6 ms 9684 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 8 ms 9812 KB Output is correct
57 Correct 7 ms 9944 KB Output is correct
58 Correct 7 ms 9840 KB Output is correct
59 Correct 8 ms 9812 KB Output is correct
60 Correct 8 ms 9940 KB Output is correct
61 Correct 6 ms 9940 KB Output is correct
62 Correct 6 ms 9940 KB Output is correct
63 Correct 6 ms 9924 KB Output is correct
64 Correct 8 ms 9956 KB Output is correct
65 Correct 7 ms 9928 KB Output is correct
66 Correct 7 ms 9928 KB Output is correct
67 Correct 180 ms 30164 KB Output is correct
68 Correct 165 ms 35488 KB Output is correct
69 Correct 191 ms 31248 KB Output is correct
70 Correct 201 ms 32020 KB Output is correct
71 Correct 193 ms 31952 KB Output is correct
72 Correct 209 ms 34232 KB Output is correct
73 Correct 165 ms 32896 KB Output is correct
74 Correct 119 ms 28700 KB Output is correct
75 Correct 144 ms 31280 KB Output is correct
76 Correct 196 ms 30056 KB Output is correct
77 Correct 197 ms 36152 KB Output is correct
78 Correct 175 ms 35324 KB Output is correct
79 Correct 171 ms 30648 KB Output is correct
80 Correct 106 ms 30220 KB Output is correct
81 Correct 177 ms 32648 KB Output is correct
82 Correct 197 ms 32752 KB Output is correct
83 Correct 209 ms 36804 KB Output is correct
84 Correct 206 ms 36196 KB Output is correct
85 Correct 176 ms 32632 KB Output is correct
86 Correct 151 ms 30392 KB Output is correct
87 Correct 152 ms 30476 KB Output is correct
88 Correct 179 ms 32668 KB Output is correct
89 Correct 195 ms 32932 KB Output is correct
90 Correct 186 ms 30384 KB Output is correct
91 Correct 227 ms 31004 KB Output is correct
92 Correct 210 ms 32056 KB Output is correct
93 Correct 200 ms 33464 KB Output is correct
94 Correct 187 ms 30876 KB Output is correct
95 Correct 182 ms 31228 KB Output is correct
96 Correct 115 ms 31232 KB Output is correct
97 Correct 114 ms 21612 KB Output is correct
98 Correct 191 ms 33388 KB Output is correct
99 Correct 215 ms 33036 KB Output is correct
100 Correct 69 ms 13676 KB Output is correct
101 Correct 191 ms 31192 KB Output is correct
102 Correct 186 ms 27324 KB Output is correct
103 Correct 189 ms 27008 KB Output is correct
104 Correct 232 ms 29876 KB Output is correct