Submission #1093021

# Submission time Handle Problem Language Result Execution time Memory
1093021 2024-09-25T17:46:56 Z LittleFlowers__ Stranded Far From Home (BOI22_island) C++17
100 / 100
305 ms 89176 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#elif LOCAL
#define debug(...) 42
#endif

#define in ({long long x = 0; int c = getchar(), n = 0; for(; !isdigit(c); c = getchar()) n = (c == '-'); for(; isdigit(c); c = getchar()) x = x * 10 + c - '0'; n ? -x : x;})

const int N = 200010;

int n, m;
long long totalWeight[N], weight[N], maxWeight[N];
struct Edge {
  int u, v;
} edges[N];

int id[N];
set<int> able[N];
int root(int x) {
  return !id[x] ? x : id[x] = root(id[x]);
}

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);

  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> weight[i];
    maxWeight[i] = totalWeight[i] = weight[i];
    able[i].insert(i);
  }
  for (int i = 1; i <= m; ++i) {
    int u, v; cin >> u >> v;

    if (weight[u] > weight[v]) swap(u, v);
    edges[i] = { u, v };
  }

  sort(edges + 1, edges + m + 1, [](Edge x, Edge y) {
    return weight[x.v] < weight[y.v];
  });

  for (int i = 1; i <= m; ++i) {
    auto [u, v] = edges[i];
    auto [x, y] = make_pair(root(u), root(v));
    if (x == y) continue;

    if (able[x].size() < able[y].size()) {
      swap(x, y);
      swap(u, v);
    }

    bool leftAble = false;
    bool rightAble = false;

    if (totalWeight[x] >= totalWeight[y]) leftAble = true;
    if (totalWeight[y] >= totalWeight[x]) rightAble = true;
    if (totalWeight[x] >= weight[v] && able[y].count(v)) leftAble = true;
    if (totalWeight[y] >= weight[u] && able[x].count(u)) rightAble = true;
    if (maxWeight[x] >= maxWeight[y]) leftAble = true;
    if (maxWeight[y] >= maxWeight[x]) rightAble = true;

    if (leftAble && rightAble) {
      able[x].insert(able[y].begin(), able[y].end());
    } else if (leftAble) {

    } else {
      swap(able[x], able[y]);
    }

    id[y] = x;
    totalWeight[x] += totalWeight[y];
    maxWeight[x] = max(maxWeight[x], maxWeight[y]);
  }

  int root = 1;
  while (id[root]) root += 1;

  for (int i = 1; i <= n; ++i) {
    cout << able[root].count(i);
  }
  cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 5 ms 10076 KB Output is correct
5 Correct 5 ms 10076 KB Output is correct
6 Correct 5 ms 10076 KB Output is correct
7 Correct 5 ms 9952 KB Output is correct
8 Correct 4 ms 10008 KB Output is correct
9 Correct 5 ms 10076 KB Output is correct
10 Correct 5 ms 10076 KB Output is correct
11 Correct 5 ms 10072 KB Output is correct
12 Correct 5 ms 10196 KB Output is correct
13 Correct 5 ms 10328 KB Output is correct
14 Correct 5 ms 10076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 108 ms 39380 KB Output is correct
4 Correct 236 ms 84432 KB Output is correct
5 Correct 167 ms 50256 KB Output is correct
6 Correct 166 ms 52308 KB Output is correct
7 Correct 173 ms 51796 KB Output is correct
8 Correct 305 ms 72488 KB Output is correct
9 Correct 153 ms 61176 KB Output is correct
10 Correct 71 ms 29884 KB Output is correct
11 Correct 176 ms 39252 KB Output is correct
12 Correct 151 ms 46164 KB Output is correct
13 Correct 248 ms 87120 KB Output is correct
14 Correct 240 ms 85844 KB Output is correct
15 Correct 129 ms 40180 KB Output is correct
16 Correct 119 ms 39248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 163 ms 59220 KB Output is correct
3 Correct 168 ms 59172 KB Output is correct
4 Correct 244 ms 89172 KB Output is correct
5 Correct 214 ms 85584 KB Output is correct
6 Correct 159 ms 58704 KB Output is correct
7 Correct 129 ms 40276 KB Output is correct
8 Correct 131 ms 40100 KB Output is correct
9 Correct 122 ms 39248 KB Output is correct
10 Correct 143 ms 57432 KB Output is correct
11 Correct 174 ms 66136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 194 ms 45396 KB Output is correct
3 Correct 181 ms 49640 KB Output is correct
4 Correct 200 ms 56028 KB Output is correct
5 Correct 271 ms 67104 KB Output is correct
6 Correct 207 ms 53844 KB Output is correct
7 Correct 164 ms 40020 KB Output is correct
8 Correct 124 ms 54492 KB Output is correct
9 Correct 84 ms 27472 KB Output is correct
10 Correct 245 ms 71252 KB Output is correct
11 Correct 171 ms 65748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 5 ms 10076 KB Output is correct
5 Correct 5 ms 10076 KB Output is correct
6 Correct 5 ms 10076 KB Output is correct
7 Correct 5 ms 9952 KB Output is correct
8 Correct 4 ms 10008 KB Output is correct
9 Correct 5 ms 10076 KB Output is correct
10 Correct 5 ms 10076 KB Output is correct
11 Correct 5 ms 10072 KB Output is correct
12 Correct 5 ms 10196 KB Output is correct
13 Correct 5 ms 10328 KB Output is correct
14 Correct 5 ms 10076 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 108 ms 39380 KB Output is correct
18 Correct 236 ms 84432 KB Output is correct
19 Correct 167 ms 50256 KB Output is correct
20 Correct 166 ms 52308 KB Output is correct
21 Correct 173 ms 51796 KB Output is correct
22 Correct 305 ms 72488 KB Output is correct
23 Correct 153 ms 61176 KB Output is correct
24 Correct 71 ms 29884 KB Output is correct
25 Correct 176 ms 39252 KB Output is correct
26 Correct 151 ms 46164 KB Output is correct
27 Correct 248 ms 87120 KB Output is correct
28 Correct 240 ms 85844 KB Output is correct
29 Correct 129 ms 40180 KB Output is correct
30 Correct 119 ms 39248 KB Output is correct
31 Correct 4 ms 9816 KB Output is correct
32 Correct 163 ms 59220 KB Output is correct
33 Correct 168 ms 59172 KB Output is correct
34 Correct 244 ms 89172 KB Output is correct
35 Correct 214 ms 85584 KB Output is correct
36 Correct 159 ms 58704 KB Output is correct
37 Correct 129 ms 40276 KB Output is correct
38 Correct 131 ms 40100 KB Output is correct
39 Correct 122 ms 39248 KB Output is correct
40 Correct 143 ms 57432 KB Output is correct
41 Correct 174 ms 66136 KB Output is correct
42 Correct 4 ms 9816 KB Output is correct
43 Correct 194 ms 45396 KB Output is correct
44 Correct 181 ms 49640 KB Output is correct
45 Correct 200 ms 56028 KB Output is correct
46 Correct 271 ms 67104 KB Output is correct
47 Correct 207 ms 53844 KB Output is correct
48 Correct 164 ms 40020 KB Output is correct
49 Correct 124 ms 54492 KB Output is correct
50 Correct 84 ms 27472 KB Output is correct
51 Correct 245 ms 71252 KB Output is correct
52 Correct 171 ms 65748 KB Output is correct
53 Correct 4 ms 9816 KB Output is correct
54 Correct 4 ms 9820 KB Output is correct
55 Correct 4 ms 9820 KB Output is correct
56 Correct 4 ms 10076 KB Output is correct
57 Correct 6 ms 10128 KB Output is correct
58 Correct 5 ms 10076 KB Output is correct
59 Correct 4 ms 10076 KB Output is correct
60 Correct 4 ms 9852 KB Output is correct
61 Correct 4 ms 10076 KB Output is correct
62 Correct 5 ms 10232 KB Output is correct
63 Correct 5 ms 10076 KB Output is correct
64 Correct 4 ms 10076 KB Output is correct
65 Correct 5 ms 10332 KB Output is correct
66 Correct 4 ms 10128 KB Output is correct
67 Correct 108 ms 39584 KB Output is correct
68 Correct 231 ms 84444 KB Output is correct
69 Correct 156 ms 50004 KB Output is correct
70 Correct 189 ms 52312 KB Output is correct
71 Correct 173 ms 52020 KB Output is correct
72 Correct 263 ms 72208 KB Output is correct
73 Correct 147 ms 61268 KB Output is correct
74 Correct 69 ms 29844 KB Output is correct
75 Correct 187 ms 39252 KB Output is correct
76 Correct 149 ms 46192 KB Output is correct
77 Correct 228 ms 86812 KB Output is correct
78 Correct 221 ms 85844 KB Output is correct
79 Correct 126 ms 40272 KB Output is correct
80 Correct 122 ms 39252 KB Output is correct
81 Correct 160 ms 59268 KB Output is correct
82 Correct 160 ms 59216 KB Output is correct
83 Correct 248 ms 89176 KB Output is correct
84 Correct 218 ms 85584 KB Output is correct
85 Correct 156 ms 58708 KB Output is correct
86 Correct 134 ms 40276 KB Output is correct
87 Correct 128 ms 40276 KB Output is correct
88 Correct 140 ms 57368 KB Output is correct
89 Correct 179 ms 66132 KB Output is correct
90 Correct 193 ms 45392 KB Output is correct
91 Correct 190 ms 49640 KB Output is correct
92 Correct 210 ms 56148 KB Output is correct
93 Correct 281 ms 66900 KB Output is correct
94 Correct 237 ms 53904 KB Output is correct
95 Correct 163 ms 40016 KB Output is correct
96 Correct 132 ms 54612 KB Output is correct
97 Correct 84 ms 27520 KB Output is correct
98 Correct 240 ms 71396 KB Output is correct
99 Correct 156 ms 65724 KB Output is correct
100 Correct 36 ms 13660 KB Output is correct
101 Correct 202 ms 49376 KB Output is correct
102 Correct 174 ms 43600 KB Output is correct
103 Correct 146 ms 35300 KB Output is correct
104 Correct 165 ms 41724 KB Output is correct