답안 #588614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588614 2022-07-03T17:01:48 Z MilosMilutinovic 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
컴파일 오류
0 ms 0 KB
/**
 *    author:  wxhtzdy
 *    created: 03.07.2022 18:28:39
**/
#include "garden.h"
#include "gardenlib.h"

#include <bits/stdc++.h>

using namespace std;

void count_routes(int n, int m, int p, vector<vector<int>> r, int q, vector<int> k) {
  vector<vector<pair<int, int>>> e(n);
  for (int i = 0; i < m; i++) {
    if ((int) e[r[i][0]].size() < 2) {
      e[r[i][0]].emplace_back(i, r[i][1]);
    }
    if ((int) e[r[i][1]].size() < 2) {
      e[r[i][1]].emplace_back(i, r[i][0]);
    }
  }
  for (int i = 0; i < n; i++) {
    if ((int) e[i].size() == 1) {
      e[i].push_back(e[i][0]);
    }
    assert((int) e[i].size() == 2);
  }
  vector<vector<int>> g(2 * n);
  function<void(int, int)> Add = [&](int v, int u) {
    g[v].push_back(u);
  };
  for (int i = 0; i < n; i++) {    
    if (e[i][0].first == e[e[i][0].second][0].first) {
      Add(i * 2, e[i][0].second * 2 + 1);
    } else {
      Add(i * 2, e[i][0].second * 2);
    }          
    if (e[i][1].first == e[e[i][1].second][0].first) {
      Add(i * 2 + 1, e[i][1].second * 2 + 1);
    } else {
      Add(i * 2 + 1, e[i][1].second * 2);
    }
  }
  const int L = 32;
  vector<vector<int>> jump(2 * n, vector<int>(L));
  for (int i = 0; i < 2 * n; i++) {
    jump[i][0] = g[i][0];    
  }
  for (int j = 1; j < L; j++) {
    for (int i = 0; i < 2 * n; i++) {
      jump[i][j] = jump[jump[i][j - 1]][j - 1];
    }
  }                     
  for (int i = 0; i < q; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      int x = j * 2;
      for (int l = L - 1; l >= 0; l--) {
        if (k[i] >> l & 1) {
          x = jump[x][l];
        }
      }
      if (x == p * 2 || x == 2 * p + 1) {
        cnt += 1;
      }
    }            
    answer(cnt);
  }
}

Compilation message

/usr/bin/ld: /tmp/cc7LTKhc.o: in function `main':
grader.cpp:(.text.startup+0x3f): undefined reference to `count_routes(int, int, int, int (*) [2], int, int*)'
collect2: error: ld returned 1 exit status