답안 #650692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650692 2022-10-14T17:28:29 Z tvladm2009 Stranded Far From Home (BOI22_island) C++14
100 / 100
238 ms 35780 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 2 * 1e5 + 7;
int w[N];
vector<int> g[N], neighbours[N];
int parent[N], order[N];
bool visited[N], ans[N];
ll sum[N];

int getRoot(int u) {
  if (parent[u] == 0) {
    return u;
  }
  return parent[u] = getRoot(parent[u]);
}

void dfs(int u, int p = -1) {
  ans[u] = true;
  for (auto &v : neighbours[u]) {
    if (v != p) {
      dfs(v, u);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    order[i] = i;
  }
  sort(order + 1, order + n + 1, [&](int x, int y) -> bool {
    return w[x] < w[y];
  });
  for (int i = 1; i <= n; i++) {
    sum[i] = w[i];
  }

  for (int i = 1; i <= n; i++) {
    int u = order[i];
    visited[u] = true;
    for (auto v : g[u]) {
      if (visited[v] == true) {
        v = getRoot(v);
        if (v != u) {
          if (sum[v] >= w[u]) {
            neighbours[u].push_back(v);
          }
          parent[v] = u;
          sum[u] += sum[v];
        }
      }
    }
  }
  dfs(order[n]);
  for (int i = 1; i <= n; i++) {
    cout << ans[i];
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 7 ms 9868 KB Output is correct
6 Correct 7 ms 9888 KB Output is correct
7 Correct 9 ms 9812 KB Output is correct
8 Correct 7 ms 9812 KB Output is correct
9 Correct 8 ms 9888 KB Output is correct
10 Correct 7 ms 9924 KB Output is correct
11 Correct 7 ms 9880 KB Output is correct
12 Correct 7 ms 9868 KB Output is correct
13 Correct 7 ms 9916 KB Output is correct
14 Correct 7 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9660 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 170 ms 30188 KB Output is correct
4 Correct 169 ms 28844 KB Output is correct
5 Correct 156 ms 26992 KB Output is correct
6 Correct 192 ms 27516 KB Output is correct
7 Correct 210 ms 27512 KB Output is correct
8 Correct 174 ms 29392 KB Output is correct
9 Correct 171 ms 26072 KB Output is correct
10 Correct 103 ms 24756 KB Output is correct
11 Correct 120 ms 25900 KB Output is correct
12 Correct 179 ms 27008 KB Output is correct
13 Correct 137 ms 29028 KB Output is correct
14 Correct 138 ms 29160 KB Output is correct
15 Correct 164 ms 35660 KB Output is correct
16 Correct 97 ms 34664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 185 ms 27136 KB Output is correct
3 Correct 215 ms 27252 KB Output is correct
4 Correct 159 ms 30796 KB Output is correct
5 Correct 151 ms 29012 KB Output is correct
6 Correct 197 ms 27384 KB Output is correct
7 Correct 175 ms 35684 KB Output is correct
8 Correct 169 ms 35640 KB Output is correct
9 Correct 103 ms 34744 KB Output is correct
10 Correct 154 ms 27048 KB Output is correct
11 Correct 156 ms 26416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9724 KB Output is correct
2 Correct 222 ms 27904 KB Output is correct
3 Correct 213 ms 27692 KB Output is correct
4 Correct 195 ms 28016 KB Output is correct
5 Correct 232 ms 28840 KB Output is correct
6 Correct 170 ms 28676 KB Output is correct
7 Correct 124 ms 27868 KB Output is correct
8 Correct 134 ms 31900 KB Output is correct
9 Correct 127 ms 21024 KB Output is correct
10 Correct 166 ms 27112 KB Output is correct
11 Correct 161 ms 26548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 7 ms 9868 KB Output is correct
6 Correct 7 ms 9888 KB Output is correct
7 Correct 9 ms 9812 KB Output is correct
8 Correct 7 ms 9812 KB Output is correct
9 Correct 8 ms 9888 KB Output is correct
10 Correct 7 ms 9924 KB Output is correct
11 Correct 7 ms 9880 KB Output is correct
12 Correct 7 ms 9868 KB Output is correct
13 Correct 7 ms 9916 KB Output is correct
14 Correct 7 ms 9812 KB Output is correct
15 Correct 6 ms 9660 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 170 ms 30188 KB Output is correct
18 Correct 169 ms 28844 KB Output is correct
19 Correct 156 ms 26992 KB Output is correct
20 Correct 192 ms 27516 KB Output is correct
21 Correct 210 ms 27512 KB Output is correct
22 Correct 174 ms 29392 KB Output is correct
23 Correct 171 ms 26072 KB Output is correct
24 Correct 103 ms 24756 KB Output is correct
25 Correct 120 ms 25900 KB Output is correct
26 Correct 179 ms 27008 KB Output is correct
27 Correct 137 ms 29028 KB Output is correct
28 Correct 138 ms 29160 KB Output is correct
29 Correct 164 ms 35660 KB Output is correct
30 Correct 97 ms 34664 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 185 ms 27136 KB Output is correct
33 Correct 215 ms 27252 KB Output is correct
34 Correct 159 ms 30796 KB Output is correct
35 Correct 151 ms 29012 KB Output is correct
36 Correct 197 ms 27384 KB Output is correct
37 Correct 175 ms 35684 KB Output is correct
38 Correct 169 ms 35640 KB Output is correct
39 Correct 103 ms 34744 KB Output is correct
40 Correct 154 ms 27048 KB Output is correct
41 Correct 156 ms 26416 KB Output is correct
42 Correct 5 ms 9724 KB Output is correct
43 Correct 222 ms 27904 KB Output is correct
44 Correct 213 ms 27692 KB Output is correct
45 Correct 195 ms 28016 KB Output is correct
46 Correct 232 ms 28840 KB Output is correct
47 Correct 170 ms 28676 KB Output is correct
48 Correct 124 ms 27868 KB Output is correct
49 Correct 134 ms 31900 KB Output is correct
50 Correct 127 ms 21024 KB Output is correct
51 Correct 166 ms 27112 KB Output is correct
52 Correct 161 ms 26548 KB Output is correct
53 Correct 6 ms 9728 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 7 ms 9812 KB Output is correct
57 Correct 7 ms 9864 KB Output is correct
58 Correct 6 ms 9812 KB Output is correct
59 Correct 7 ms 9812 KB Output is correct
60 Correct 7 ms 9940 KB Output is correct
61 Correct 6 ms 9864 KB Output is correct
62 Correct 7 ms 9812 KB Output is correct
63 Correct 7 ms 9812 KB Output is correct
64 Correct 8 ms 9812 KB Output is correct
65 Correct 6 ms 9864 KB Output is correct
66 Correct 7 ms 9868 KB Output is correct
67 Correct 153 ms 30228 KB Output is correct
68 Correct 139 ms 28804 KB Output is correct
69 Correct 157 ms 27016 KB Output is correct
70 Correct 205 ms 27460 KB Output is correct
71 Correct 171 ms 27596 KB Output is correct
72 Correct 174 ms 29324 KB Output is correct
73 Correct 181 ms 26056 KB Output is correct
74 Correct 106 ms 24520 KB Output is correct
75 Correct 104 ms 25824 KB Output is correct
76 Correct 149 ms 26968 KB Output is correct
77 Correct 149 ms 29116 KB Output is correct
78 Correct 163 ms 29204 KB Output is correct
79 Correct 141 ms 35664 KB Output is correct
80 Correct 97 ms 34700 KB Output is correct
81 Correct 206 ms 27268 KB Output is correct
82 Correct 185 ms 27320 KB Output is correct
83 Correct 149 ms 30804 KB Output is correct
84 Correct 151 ms 29000 KB Output is correct
85 Correct 200 ms 27284 KB Output is correct
86 Correct 177 ms 35768 KB Output is correct
87 Correct 182 ms 35780 KB Output is correct
88 Correct 157 ms 27112 KB Output is correct
89 Correct 161 ms 26508 KB Output is correct
90 Correct 223 ms 27860 KB Output is correct
91 Correct 208 ms 27640 KB Output is correct
92 Correct 189 ms 28028 KB Output is correct
93 Correct 222 ms 28892 KB Output is correct
94 Correct 192 ms 28832 KB Output is correct
95 Correct 111 ms 27888 KB Output is correct
96 Correct 112 ms 31904 KB Output is correct
97 Correct 122 ms 21028 KB Output is correct
98 Correct 162 ms 27232 KB Output is correct
99 Correct 141 ms 26572 KB Output is correct
100 Correct 48 ms 14084 KB Output is correct
101 Correct 238 ms 27524 KB Output is correct
102 Correct 171 ms 26892 KB Output is correct
103 Correct 188 ms 26656 KB Output is correct
104 Correct 214 ms 27784 KB Output is correct