Submission #894243

# Submission time Handle Problem Language Result Execution time Memory
894243 2023-12-28T03:06:00 Z box Stranded Far From Home (BOI22_island) C++17
100 / 100
148 ms 25580 KB
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
 
const int N = 2e5;
 
int e[N];
 
int find(int i) { return e[i] < 0 ? i : e[i] = find(e[i]); }
 
void link(int i, int j) {
  i = find(i), j = find(j);
  if (e[i] > e[j]) swap(i, j);
  e[i] += e[j], e[j] = i;
}
 
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  static int s[N];
  for (int i = 0; i < n; i++) cin >> s[i];
  vector<array<int, 3>> ed(m);
  for (auto &[v, i, j] : ed) {
    cin >> i >> j, i--, j--;
    v = max(s[i], s[j]);
  }
  sort(ed.begin(), ed.end());
  static vector<int> win[N];
  static long long sm[N];
  for (int i = 0; i < n; i++) e[i] = -1, sm[i] = s[i], win[i].push_back(i);
  for (auto [w, i, j] : ed) {
    int u = find(i), v = find(j);
    if (u == v) continue;
    link(i, j);
    int t = find(i);
    if (sm[u] < s[j])
      swap(win[t], win[v]);
    else if (sm[v] < s[i])
      swap(win[t], win[u]);
    else {
      if (win[v].size() > win[u].size()) swap(win[u], win[v]);
      for (int i : win[v]) win[u].push_back(i);
      swap(win[t], win[u]);
    }
    sm[t] = sm[u] + sm[v];
  }
  static bool w[N];
  for (int i : win[find(0)]) w[i] = 1;
  for (int i = 0; i < n; i++) cout << w[i];
  cout << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7000 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7000 KB Output is correct
4 Correct 3 ms 7136 KB Output is correct
5 Correct 4 ms 7260 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7256 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 4 ms 7260 KB Output is correct
10 Correct 4 ms 7260 KB Output is correct
11 Correct 3 ms 7168 KB Output is correct
12 Correct 3 ms 7132 KB Output is correct
13 Correct 4 ms 7260 KB Output is correct
14 Correct 4 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7124 KB Output is correct
2 Correct 3 ms 7116 KB Output is correct
3 Correct 85 ms 22696 KB Output is correct
4 Correct 114 ms 21132 KB Output is correct
5 Correct 88 ms 23712 KB Output is correct
6 Correct 115 ms 24440 KB Output is correct
7 Correct 98 ms 24364 KB Output is correct
8 Correct 94 ms 22624 KB Output is correct
9 Correct 88 ms 25580 KB Output is correct
10 Correct 78 ms 20732 KB Output is correct
11 Correct 78 ms 21468 KB Output is correct
12 Correct 100 ms 21244 KB Output is correct
13 Correct 77 ms 21108 KB Output is correct
14 Correct 76 ms 21192 KB Output is correct
15 Correct 90 ms 22504 KB Output is correct
16 Correct 82 ms 21732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Correct 118 ms 25140 KB Output is correct
3 Correct 102 ms 25160 KB Output is correct
4 Correct 88 ms 22508 KB Output is correct
5 Correct 122 ms 21100 KB Output is correct
6 Correct 107 ms 25376 KB Output is correct
7 Correct 81 ms 22476 KB Output is correct
8 Correct 84 ms 22512 KB Output is correct
9 Correct 64 ms 21712 KB Output is correct
10 Correct 85 ms 21436 KB Output is correct
11 Correct 92 ms 21364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Correct 119 ms 22984 KB Output is correct
3 Correct 118 ms 23472 KB Output is correct
4 Correct 107 ms 24316 KB Output is correct
5 Correct 109 ms 25368 KB Output is correct
6 Correct 123 ms 23388 KB Output is correct
7 Correct 86 ms 22384 KB Output is correct
8 Correct 73 ms 21448 KB Output is correct
9 Correct 74 ms 16544 KB Output is correct
10 Correct 127 ms 24744 KB Output is correct
11 Correct 102 ms 21276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7000 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7000 KB Output is correct
4 Correct 3 ms 7136 KB Output is correct
5 Correct 4 ms 7260 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7256 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 4 ms 7260 KB Output is correct
10 Correct 4 ms 7260 KB Output is correct
11 Correct 3 ms 7168 KB Output is correct
12 Correct 3 ms 7132 KB Output is correct
13 Correct 4 ms 7260 KB Output is correct
14 Correct 4 ms 7248 KB Output is correct
15 Correct 2 ms 7124 KB Output is correct
16 Correct 3 ms 7116 KB Output is correct
17 Correct 85 ms 22696 KB Output is correct
18 Correct 114 ms 21132 KB Output is correct
19 Correct 88 ms 23712 KB Output is correct
20 Correct 115 ms 24440 KB Output is correct
21 Correct 98 ms 24364 KB Output is correct
22 Correct 94 ms 22624 KB Output is correct
23 Correct 88 ms 25580 KB Output is correct
24 Correct 78 ms 20732 KB Output is correct
25 Correct 78 ms 21468 KB Output is correct
26 Correct 100 ms 21244 KB Output is correct
27 Correct 77 ms 21108 KB Output is correct
28 Correct 76 ms 21192 KB Output is correct
29 Correct 90 ms 22504 KB Output is correct
30 Correct 82 ms 21732 KB Output is correct
31 Correct 2 ms 7004 KB Output is correct
32 Correct 118 ms 25140 KB Output is correct
33 Correct 102 ms 25160 KB Output is correct
34 Correct 88 ms 22508 KB Output is correct
35 Correct 122 ms 21100 KB Output is correct
36 Correct 107 ms 25376 KB Output is correct
37 Correct 81 ms 22476 KB Output is correct
38 Correct 84 ms 22512 KB Output is correct
39 Correct 64 ms 21712 KB Output is correct
40 Correct 85 ms 21436 KB Output is correct
41 Correct 92 ms 21364 KB Output is correct
42 Correct 2 ms 7004 KB Output is correct
43 Correct 119 ms 22984 KB Output is correct
44 Correct 118 ms 23472 KB Output is correct
45 Correct 107 ms 24316 KB Output is correct
46 Correct 109 ms 25368 KB Output is correct
47 Correct 123 ms 23388 KB Output is correct
48 Correct 86 ms 22384 KB Output is correct
49 Correct 73 ms 21448 KB Output is correct
50 Correct 74 ms 16544 KB Output is correct
51 Correct 127 ms 24744 KB Output is correct
52 Correct 102 ms 21276 KB Output is correct
53 Correct 3 ms 7004 KB Output is correct
54 Correct 3 ms 7004 KB Output is correct
55 Correct 4 ms 7004 KB Output is correct
56 Correct 4 ms 7260 KB Output is correct
57 Correct 5 ms 7260 KB Output is correct
58 Correct 3 ms 7260 KB Output is correct
59 Correct 3 ms 7188 KB Output is correct
60 Correct 3 ms 7256 KB Output is correct
61 Correct 3 ms 7260 KB Output is correct
62 Correct 3 ms 7260 KB Output is correct
63 Correct 3 ms 7188 KB Output is correct
64 Correct 3 ms 7260 KB Output is correct
65 Correct 3 ms 7180 KB Output is correct
66 Correct 3 ms 7260 KB Output is correct
67 Correct 106 ms 22696 KB Output is correct
68 Correct 92 ms 21224 KB Output is correct
69 Correct 106 ms 23744 KB Output is correct
70 Correct 104 ms 24444 KB Output is correct
71 Correct 121 ms 24392 KB Output is correct
72 Correct 97 ms 22456 KB Output is correct
73 Correct 104 ms 25560 KB Output is correct
74 Correct 84 ms 20664 KB Output is correct
75 Correct 103 ms 21464 KB Output is correct
76 Correct 109 ms 21456 KB Output is correct
77 Correct 82 ms 21140 KB Output is correct
78 Correct 82 ms 21136 KB Output is correct
79 Correct 86 ms 22508 KB Output is correct
80 Correct 75 ms 21816 KB Output is correct
81 Correct 126 ms 25320 KB Output is correct
82 Correct 120 ms 25336 KB Output is correct
83 Correct 91 ms 22536 KB Output is correct
84 Correct 82 ms 21208 KB Output is correct
85 Correct 110 ms 25436 KB Output is correct
86 Correct 104 ms 22520 KB Output is correct
87 Correct 96 ms 22516 KB Output is correct
88 Correct 83 ms 21364 KB Output is correct
89 Correct 104 ms 21360 KB Output is correct
90 Correct 148 ms 23144 KB Output is correct
91 Correct 116 ms 23420 KB Output is correct
92 Correct 120 ms 24296 KB Output is correct
93 Correct 132 ms 25488 KB Output is correct
94 Correct 106 ms 23476 KB Output is correct
95 Correct 101 ms 22584 KB Output is correct
96 Correct 82 ms 21456 KB Output is correct
97 Correct 76 ms 16548 KB Output is correct
98 Correct 102 ms 24664 KB Output is correct
99 Correct 88 ms 21280 KB Output is correct
100 Correct 53 ms 11600 KB Output is correct
101 Correct 114 ms 23952 KB Output is correct
102 Correct 116 ms 20828 KB Output is correct
103 Correct 102 ms 20564 KB Output is correct
104 Correct 108 ms 22520 KB Output is correct