답안 #651058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
651058 2022-10-16T18:45:11 Z 600Mihnea Stranded Far From Home (BOI22_island) C++17
100 / 100
260 ms 31296 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<ll> s(n);
  vector<int> t(n, -1);
  vector<int> ord(n);
  vector<vector<int>> bosses(n);
  vector<vector<int>> g(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    ord[i] = i;
    bosses[i] = { i };
  }
  sort(ord.begin(), ord.end(), [&](int i, int j) {return s[i] < s[j]; });
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  function<int(int)>root = [&](int a) {
    if (t[a] == a) {
      return a;
    }
    else {
      return t[a] = root(t[a]);
    }
  };
  function<void(int, int)>join = [&](int a, int b) {
    a = root(a);
    b = root(b);
    if ((int)bosses[a].size() > (int)bosses[b].size()) {
      swap(a, b);
    }
    t[a] = b;
    s[b] += s[a];
    for (auto& boss : bosses[a]) {
      bosses[b].push_back(boss);
    }
  };
  for (auto& v : ord) {
    /// activate vertex v
    vector<int> comps;
    for (auto& ngh : g[v]) {
      if (t[ngh] != -1) {
        comps.push_back(root(ngh));
      }
    }
    sort(comps.begin(), comps.end());
    comps.resize(unique(comps.begin(), comps.end()) - comps.begin());
    t[v] = v;
    for (auto& c : comps) {
      if (s[c] < s[v]) {
        bosses[c].clear();
      }
    }
    for (auto& c : comps) {
      join(v, c);
    }
  }
  vector<int> isboss(n, 0);
  for (auto& boss : bosses[root(0)]) {
    isboss[boss] = 1;
  }
  for (auto& is : isboss) {
    cout << is;
  }
  cout << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 448 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 636 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 200 ms 27276 KB Output is correct
4 Correct 225 ms 30420 KB Output is correct
5 Correct 260 ms 28460 KB Output is correct
6 Correct 235 ms 29296 KB Output is correct
7 Correct 255 ms 29388 KB Output is correct
8 Correct 232 ms 28488 KB Output is correct
9 Correct 207 ms 31296 KB Output is correct
10 Correct 145 ms 27772 KB Output is correct
11 Correct 150 ms 28600 KB Output is correct
12 Correct 247 ms 28052 KB Output is correct
13 Correct 220 ms 31040 KB Output is correct
14 Correct 195 ms 30524 KB Output is correct
15 Correct 179 ms 27376 KB Output is correct
16 Correct 98 ms 27000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 243 ms 29984 KB Output is correct
3 Correct 230 ms 30028 KB Output is correct
4 Correct 169 ms 30952 KB Output is correct
5 Correct 162 ms 30724 KB Output is correct
6 Correct 219 ms 30152 KB Output is correct
7 Correct 187 ms 27348 KB Output is correct
8 Correct 179 ms 27284 KB Output is correct
9 Correct 97 ms 27048 KB Output is correct
10 Correct 180 ms 28356 KB Output is correct
11 Correct 206 ms 29800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 257 ms 27788 KB Output is correct
3 Correct 215 ms 28396 KB Output is correct
4 Correct 223 ms 29220 KB Output is correct
5 Correct 226 ms 30172 KB Output is correct
6 Correct 184 ms 27380 KB Output is correct
7 Correct 131 ms 28420 KB Output is correct
8 Correct 117 ms 29156 KB Output is correct
9 Correct 105 ms 15188 KB Output is correct
10 Correct 197 ms 30976 KB Output is correct
11 Correct 200 ms 29948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 448 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 636 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 200 ms 27276 KB Output is correct
18 Correct 225 ms 30420 KB Output is correct
19 Correct 260 ms 28460 KB Output is correct
20 Correct 235 ms 29296 KB Output is correct
21 Correct 255 ms 29388 KB Output is correct
22 Correct 232 ms 28488 KB Output is correct
23 Correct 207 ms 31296 KB Output is correct
24 Correct 145 ms 27772 KB Output is correct
25 Correct 150 ms 28600 KB Output is correct
26 Correct 247 ms 28052 KB Output is correct
27 Correct 220 ms 31040 KB Output is correct
28 Correct 195 ms 30524 KB Output is correct
29 Correct 179 ms 27376 KB Output is correct
30 Correct 98 ms 27000 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 243 ms 29984 KB Output is correct
33 Correct 230 ms 30028 KB Output is correct
34 Correct 169 ms 30952 KB Output is correct
35 Correct 162 ms 30724 KB Output is correct
36 Correct 219 ms 30152 KB Output is correct
37 Correct 187 ms 27348 KB Output is correct
38 Correct 179 ms 27284 KB Output is correct
39 Correct 97 ms 27048 KB Output is correct
40 Correct 180 ms 28356 KB Output is correct
41 Correct 206 ms 29800 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 257 ms 27788 KB Output is correct
44 Correct 215 ms 28396 KB Output is correct
45 Correct 223 ms 29220 KB Output is correct
46 Correct 226 ms 30172 KB Output is correct
47 Correct 184 ms 27380 KB Output is correct
48 Correct 131 ms 28420 KB Output is correct
49 Correct 117 ms 29156 KB Output is correct
50 Correct 105 ms 15188 KB Output is correct
51 Correct 197 ms 30976 KB Output is correct
52 Correct 200 ms 29948 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 320 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 2 ms 460 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 2 ms 468 KB Output is correct
61 Correct 2 ms 596 KB Output is correct
62 Correct 2 ms 596 KB Output is correct
63 Correct 2 ms 596 KB Output is correct
64 Correct 2 ms 596 KB Output is correct
65 Correct 2 ms 612 KB Output is correct
66 Correct 2 ms 596 KB Output is correct
67 Correct 163 ms 27328 KB Output is correct
68 Correct 170 ms 30424 KB Output is correct
69 Correct 189 ms 28412 KB Output is correct
70 Correct 197 ms 29216 KB Output is correct
71 Correct 183 ms 29388 KB Output is correct
72 Correct 182 ms 28564 KB Output is correct
73 Correct 173 ms 31264 KB Output is correct
74 Correct 126 ms 27820 KB Output is correct
75 Correct 130 ms 28596 KB Output is correct
76 Correct 198 ms 28040 KB Output is correct
77 Correct 174 ms 30996 KB Output is correct
78 Correct 166 ms 30476 KB Output is correct
79 Correct 172 ms 27300 KB Output is correct
80 Correct 100 ms 27072 KB Output is correct
81 Correct 217 ms 30004 KB Output is correct
82 Correct 243 ms 30016 KB Output is correct
83 Correct 190 ms 31028 KB Output is correct
84 Correct 191 ms 30632 KB Output is correct
85 Correct 233 ms 30100 KB Output is correct
86 Correct 161 ms 27272 KB Output is correct
87 Correct 181 ms 27276 KB Output is correct
88 Correct 160 ms 28432 KB Output is correct
89 Correct 193 ms 29884 KB Output is correct
90 Correct 227 ms 27792 KB Output is correct
91 Correct 221 ms 28448 KB Output is correct
92 Correct 236 ms 29292 KB Output is correct
93 Correct 236 ms 30152 KB Output is correct
94 Correct 173 ms 27296 KB Output is correct
95 Correct 135 ms 28384 KB Output is correct
96 Correct 115 ms 29068 KB Output is correct
97 Correct 120 ms 15208 KB Output is correct
98 Correct 231 ms 31012 KB Output is correct
99 Correct 189 ms 29976 KB Output is correct
100 Correct 42 ms 3148 KB Output is correct
101 Correct 250 ms 28608 KB Output is correct
102 Correct 155 ms 22060 KB Output is correct
103 Correct 199 ms 22876 KB Output is correct
104 Correct 250 ms 27104 KB Output is correct