답안 #647420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647420 2022-10-02T13:55:03 Z Pety Stranded Far From Home (BOI22_island) C++14
0 / 100
228 ms 30728 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], 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);
    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) {
  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 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 7 ms 9800 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Incorrect 155 ms 30728 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 198 ms 24156 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 228 ms 25036 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 7 ms 9800 KB Output isn't correct
5 Halted 0 ms 0 KB -