답안 #647427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647427 2022-10-02T14:20:15 Z Pety Stranded Far From Home (BOI22_island) C++14
컴파일 오류
0 ms 0 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;
}

Compilation message

island.cpp:11:1: error: expected initializer before 'vector'
   11 | vector<int>G2[200002];
      | ^~~~~~
island.cpp: In function 'void dfs(int, int)':
island.cpp:40:3: error: 'sz' was not declared in this scope
   40 |   sz[nod] = val[nod];
      |   ^~
island.cpp: In function 'int main()':
island.cpp:69:5: error: 'G2' was not declared in this scope; did you mean 'G'?
   69 |     G2[x].push_back(y);
      |     ^~
      |     G
island.cpp:76:20: error: 'G2' was not declared in this scope; did you mean 'G'?
   76 |     for (auto it : G2[ind[i]])
      |                    ^~
      |                    G