답안 #647428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647428 2022-10-02T14:20:32 Z Pety Stranded Far From Home (BOI22_island) C++14
100 / 100
351 ms 47300 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int INF = 1e9;
const int MOD = 1e9 + 7;

int n, m, val[200002], ind[200002], p[200002], ok[200002];
ll sz[200002];
vector<int>G2[200002];
vector<int>G[200002];


int find (int x) {
  if (p[x] == x)
    return x;
  return p[x] = find(p[x]); 
}

void Union (int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    G[a].push_back(b);
    G[b].push_back(a);
    p[b] = a;
  }
}

bool cmp (int a, int b) {
  if (val[a] == val[b])
     return a < b;
  return val[a] < val[b];
}

void dfs (int nod, int par) {
  assert(par == 0 || val[nod] <= val[par]);

  sz[nod] = val[nod];
  for (auto it : G[nod]) {
    if (it == par)
      continue;
    dfs(it, nod);
    sz[nod] += sz[it];
  }
  ok[nod] = (sz[nod] >= val[par]);
}

void dfs2 (int nod, int par, bool idk) {
  for (auto it : G[nod]) {
    if (it == par)
      continue;
    dfs2(it, nod, (idk & ok[it]));
  }
  ok[nod] = idk;
}

int main () 
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) 
    cin >> val[i];
  for (int i = 1; i <= m; i++) {  
    int x, y;
    cin >> x >> y;
    G2[x].push_back(y);
    G2[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    ind[i] = p[i] = i;
  sort(ind + 1, ind + n + 1, cmp);  
  for (int i = 1; i <= n; i++)
    for (auto it : G2[ind[i]])
      if (make_pair(val[it], it) <= make_pair(val[ind[i]], ind[i]))
        Union(ind[i], it);
  dfs(find(1), 0);
  dfs2(find(1), 0, 1);
  for (int i = 1; i <= n; i++)
    cout << ok[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 5 ms 9740 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 7 ms 9940 KB Output is correct
6 Correct 8 ms 9868 KB Output is correct
7 Correct 7 ms 9864 KB Output is correct
8 Correct 7 ms 9864 KB Output is correct
9 Correct 7 ms 10016 KB Output is correct
10 Correct 7 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 8 ms 9864 KB Output is correct
13 Correct 8 ms 10068 KB Output is correct
14 Correct 9 ms 9940 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 177 ms 33356 KB Output is correct
4 Correct 192 ms 44232 KB Output is correct
5 Correct 268 ms 30968 KB Output is correct
6 Correct 264 ms 31564 KB Output is correct
7 Correct 311 ms 31716 KB Output is correct
8 Correct 190 ms 47152 KB Output is correct
9 Correct 200 ms 31460 KB Output is correct
10 Correct 157 ms 32212 KB Output is correct
11 Correct 182 ms 46872 KB Output is correct
12 Correct 285 ms 31700 KB Output is correct
13 Correct 160 ms 45596 KB Output is correct
14 Correct 177 ms 44212 KB Output is correct
15 Correct 220 ms 47116 KB Output is correct
16 Correct 123 ms 46112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 277 ms 26988 KB Output is correct
3 Correct 249 ms 31496 KB Output is correct
4 Correct 212 ms 47184 KB Output is correct
5 Correct 192 ms 40652 KB Output is correct
6 Correct 234 ms 31488 KB Output is correct
7 Correct 236 ms 47276 KB Output is correct
8 Correct 227 ms 47300 KB Output is correct
9 Correct 121 ms 46172 KB Output is correct
10 Correct 201 ms 38624 KB Output is correct
11 Correct 184 ms 32788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 329 ms 28148 KB Output is correct
3 Correct 324 ms 31864 KB Output is correct
4 Correct 330 ms 31712 KB Output is correct
5 Correct 329 ms 31824 KB Output is correct
6 Correct 295 ms 32800 KB Output is correct
7 Correct 172 ms 41344 KB Output is correct
8 Correct 131 ms 46028 KB Output is correct
9 Correct 184 ms 22504 KB Output is correct
10 Correct 291 ms 30204 KB Output is correct
11 Correct 204 ms 32904 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 5 ms 9740 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 7 ms 9940 KB Output is correct
6 Correct 8 ms 9868 KB Output is correct
7 Correct 7 ms 9864 KB Output is correct
8 Correct 7 ms 9864 KB Output is correct
9 Correct 7 ms 10016 KB Output is correct
10 Correct 7 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 8 ms 9864 KB Output is correct
13 Correct 8 ms 10068 KB Output is correct
14 Correct 9 ms 9940 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 177 ms 33356 KB Output is correct
18 Correct 192 ms 44232 KB Output is correct
19 Correct 268 ms 30968 KB Output is correct
20 Correct 264 ms 31564 KB Output is correct
21 Correct 311 ms 31716 KB Output is correct
22 Correct 190 ms 47152 KB Output is correct
23 Correct 200 ms 31460 KB Output is correct
24 Correct 157 ms 32212 KB Output is correct
25 Correct 182 ms 46872 KB Output is correct
26 Correct 285 ms 31700 KB Output is correct
27 Correct 160 ms 45596 KB Output is correct
28 Correct 177 ms 44212 KB Output is correct
29 Correct 220 ms 47116 KB Output is correct
30 Correct 123 ms 46112 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 277 ms 26988 KB Output is correct
33 Correct 249 ms 31496 KB Output is correct
34 Correct 212 ms 47184 KB Output is correct
35 Correct 192 ms 40652 KB Output is correct
36 Correct 234 ms 31488 KB Output is correct
37 Correct 236 ms 47276 KB Output is correct
38 Correct 227 ms 47300 KB Output is correct
39 Correct 121 ms 46172 KB Output is correct
40 Correct 201 ms 38624 KB Output is correct
41 Correct 184 ms 32788 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 329 ms 28148 KB Output is correct
44 Correct 324 ms 31864 KB Output is correct
45 Correct 330 ms 31712 KB Output is correct
46 Correct 329 ms 31824 KB Output is correct
47 Correct 295 ms 32800 KB Output is correct
48 Correct 172 ms 41344 KB Output is correct
49 Correct 131 ms 46028 KB Output is correct
50 Correct 184 ms 22504 KB Output is correct
51 Correct 291 ms 30204 KB Output is correct
52 Correct 204 ms 32904 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 6 ms 9684 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 7 ms 9864 KB Output is correct
57 Correct 7 ms 9936 KB Output is correct
58 Correct 7 ms 9916 KB Output is correct
59 Correct 7 ms 9868 KB Output is correct
60 Correct 7 ms 9812 KB Output is correct
61 Correct 7 ms 10068 KB Output is correct
62 Correct 7 ms 9940 KB Output is correct
63 Correct 7 ms 9860 KB Output is correct
64 Correct 7 ms 9940 KB Output is correct
65 Correct 9 ms 9984 KB Output is correct
66 Correct 7 ms 9940 KB Output is correct
67 Correct 193 ms 37772 KB Output is correct
68 Correct 167 ms 44360 KB Output is correct
69 Correct 290 ms 30964 KB Output is correct
70 Correct 300 ms 31556 KB Output is correct
71 Correct 339 ms 31580 KB Output is correct
72 Correct 220 ms 47196 KB Output is correct
73 Correct 173 ms 31540 KB Output is correct
74 Correct 156 ms 32188 KB Output is correct
75 Correct 196 ms 46940 KB Output is correct
76 Correct 270 ms 31804 KB Output is correct
77 Correct 168 ms 45608 KB Output is correct
78 Correct 175 ms 44216 KB Output is correct
79 Correct 189 ms 47096 KB Output is correct
80 Correct 119 ms 46100 KB Output is correct
81 Correct 276 ms 31316 KB Output is correct
82 Correct 258 ms 31528 KB Output is correct
83 Correct 230 ms 47136 KB Output is correct
84 Correct 170 ms 40628 KB Output is correct
85 Correct 272 ms 31516 KB Output is correct
86 Correct 198 ms 47236 KB Output is correct
87 Correct 201 ms 47236 KB Output is correct
88 Correct 185 ms 38720 KB Output is correct
89 Correct 183 ms 32800 KB Output is correct
90 Correct 346 ms 32540 KB Output is correct
91 Correct 326 ms 31900 KB Output is correct
92 Correct 348 ms 31680 KB Output is correct
93 Correct 335 ms 31768 KB Output is correct
94 Correct 288 ms 32804 KB Output is correct
95 Correct 148 ms 41248 KB Output is correct
96 Correct 130 ms 45936 KB Output is correct
97 Correct 156 ms 22508 KB Output is correct
98 Correct 269 ms 30224 KB Output is correct
99 Correct 194 ms 32904 KB Output is correct
100 Correct 52 ms 14292 KB Output is correct
101 Correct 324 ms 31796 KB Output is correct
102 Correct 270 ms 31932 KB Output is correct
103 Correct 275 ms 32496 KB Output is correct
104 Correct 351 ms 32980 KB Output is correct