Submission #1093148

# Submission time Handle Problem Language Result Execution time Memory
1093148 2024-09-26T03:26:59 Z juicy Stranded Far From Home (BOI22_island) C++17
100 / 100
91 ms 14008 KB
#include <bits/stdc++.h>

using namespace std;

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

const int N = 2e5 + 5;

int n, m;
int a[N], pr[N];
long long s[N];
bool lose[N];

int find(int u) {
  if (u == pr[u]) {
    return u;
  }
  int p = find(pr[u]);
  lose[u] |= lose[pr[u]];
  return pr[u] = p;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pr[i] = i, s[i] = a[i];
  }
  vector<array<int, 3>> e;
  while (m--) {
    int x, y; cin >> x >> y;
    if (a[x] > a[y]) {
      swap(x, y);
    }
    e.push_back({a[y], x, y});
  }
  sort(e.begin(), e.end());
  for (auto [w, u, v] : e) {
    u = find(u), v = find(v);
    if (u ^ v) {
      lose[u] = s[u] < a[v];
      pr[u] = v;
      s[v] += s[u];
    }
  }
  for (int i = 1; i <= n; ++i) {
    find(i);
    cout << (lose[i] ? 0 : 1);
  }
  return 0;
}
# 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 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 74 ms 10704 KB Output is correct
4 Correct 66 ms 10928 KB Output is correct
5 Correct 67 ms 10252 KB Output is correct
6 Correct 71 ms 10680 KB Output is correct
7 Correct 72 ms 10688 KB Output is correct
8 Correct 89 ms 10680 KB Output is correct
9 Correct 68 ms 10620 KB Output is correct
10 Correct 65 ms 9924 KB Output is correct
11 Correct 67 ms 12732 KB Output is correct
12 Correct 82 ms 9404 KB Output is correct
13 Correct 65 ms 12476 KB Output is correct
14 Correct 64 ms 12216 KB Output is correct
15 Correct 66 ms 10760 KB Output is correct
16 Correct 47 ms 9920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 79 ms 10716 KB Output is correct
3 Correct 73 ms 10680 KB Output is correct
4 Correct 72 ms 14008 KB Output is correct
5 Correct 63 ms 11260 KB Output is correct
6 Correct 73 ms 10720 KB Output is correct
7 Correct 74 ms 10708 KB Output is correct
8 Correct 65 ms 10724 KB Output is correct
9 Correct 45 ms 9932 KB Output is correct
10 Correct 72 ms 13248 KB Output is correct
11 Correct 66 ms 10432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 84 ms 10724 KB Output is correct
3 Correct 83 ms 10636 KB Output is correct
4 Correct 83 ms 10684 KB Output is correct
5 Correct 88 ms 10684 KB Output is correct
6 Correct 91 ms 10460 KB Output is correct
7 Correct 72 ms 13268 KB Output is correct
8 Correct 61 ms 11192 KB Output is correct
9 Correct 63 ms 7112 KB Output is correct
10 Correct 73 ms 9108 KB Output is correct
11 Correct 65 ms 10384 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 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 74 ms 10704 KB Output is correct
18 Correct 66 ms 10928 KB Output is correct
19 Correct 67 ms 10252 KB Output is correct
20 Correct 71 ms 10680 KB Output is correct
21 Correct 72 ms 10688 KB Output is correct
22 Correct 89 ms 10680 KB Output is correct
23 Correct 68 ms 10620 KB Output is correct
24 Correct 65 ms 9924 KB Output is correct
25 Correct 67 ms 12732 KB Output is correct
26 Correct 82 ms 9404 KB Output is correct
27 Correct 65 ms 12476 KB Output is correct
28 Correct 64 ms 12216 KB Output is correct
29 Correct 66 ms 10760 KB Output is correct
30 Correct 47 ms 9920 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 79 ms 10716 KB Output is correct
33 Correct 73 ms 10680 KB Output is correct
34 Correct 72 ms 14008 KB Output is correct
35 Correct 63 ms 11260 KB Output is correct
36 Correct 73 ms 10720 KB Output is correct
37 Correct 74 ms 10708 KB Output is correct
38 Correct 65 ms 10724 KB Output is correct
39 Correct 45 ms 9932 KB Output is correct
40 Correct 72 ms 13248 KB Output is correct
41 Correct 66 ms 10432 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 84 ms 10724 KB Output is correct
44 Correct 83 ms 10636 KB Output is correct
45 Correct 83 ms 10684 KB Output is correct
46 Correct 88 ms 10684 KB Output is correct
47 Correct 91 ms 10460 KB Output is correct
48 Correct 72 ms 13268 KB Output is correct
49 Correct 61 ms 11192 KB Output is correct
50 Correct 63 ms 7112 KB Output is correct
51 Correct 73 ms 9108 KB Output is correct
52 Correct 65 ms 10384 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 460 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 472 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 604 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 70 ms 10692 KB Output is correct
68 Correct 75 ms 10944 KB Output is correct
69 Correct 66 ms 10300 KB Output is correct
70 Correct 68 ms 10688 KB Output is correct
71 Correct 69 ms 10700 KB Output is correct
72 Correct 83 ms 10688 KB Output is correct
73 Correct 66 ms 10692 KB Output is correct
74 Correct 65 ms 9936 KB Output is correct
75 Correct 69 ms 12736 KB Output is correct
76 Correct 72 ms 9324 KB Output is correct
77 Correct 64 ms 12328 KB Output is correct
78 Correct 66 ms 12216 KB Output is correct
79 Correct 68 ms 10736 KB Output is correct
80 Correct 47 ms 9960 KB Output is correct
81 Correct 74 ms 10712 KB Output is correct
82 Correct 72 ms 10696 KB Output is correct
83 Correct 71 ms 13936 KB Output is correct
84 Correct 64 ms 11448 KB Output is correct
85 Correct 70 ms 10704 KB Output is correct
86 Correct 64 ms 10708 KB Output is correct
87 Correct 64 ms 10832 KB Output is correct
88 Correct 70 ms 13244 KB Output is correct
89 Correct 69 ms 10392 KB Output is correct
90 Correct 89 ms 10684 KB Output is correct
91 Correct 82 ms 10700 KB Output is correct
92 Correct 82 ms 10736 KB Output is correct
93 Correct 89 ms 10688 KB Output is correct
94 Correct 79 ms 10388 KB Output is correct
95 Correct 70 ms 13244 KB Output is correct
96 Correct 59 ms 11196 KB Output is correct
97 Correct 65 ms 7108 KB Output is correct
98 Correct 73 ms 9152 KB Output is correct
99 Correct 66 ms 10308 KB Output is correct
100 Correct 46 ms 5120 KB Output is correct
101 Correct 79 ms 10684 KB Output is correct
102 Correct 76 ms 9528 KB Output is correct
103 Correct 83 ms 9916 KB Output is correct
104 Correct 87 ms 10696 KB Output is correct