Submission #588608

# Submission time Handle Problem Language Result Execution time Memory
588608 2022-07-03T16:44:48 Z MilosMilutinovic Tropical Garden (IOI11_garden) C++14
Compilation error
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, int r[][2], int q, int k[]) {
  vector<vector<pair<int, int>>> e(n);
  for (int i = m - 1; i >= 0; 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]);
    }
  }
  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]][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].first][0].first) {
      Add(i * 2 + 1, e[i][0].second * 2 + 1);
    } else {
      Add(i * 2 + 1, e[i][1].second * 2);
    }
  }
  const int L = 32;
  vector<vector<int>> jump(n, vector<int>(L));
  for (int i = 0; i < n; i++) {
    jump[i][0] = g[i * 2][0];    
  }
  for (int j = 1; j < L; j++) {
    for (int i = 0; i < 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;
      for (int l = L - 1; l >= 0; l--) {
        if (k[i] >> l & 1) {
          x = jump[x][l];
        }
      }
      if (x == p) {
        cnt += 1;
      }
    }            
    answer(cnt);
  }
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:32:27: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<std::pair<int, int> > >' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'})
   32 |     if (e[i][0].first == e[e[i][0]][0].first) {
      |                           ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from garden.cpp:8:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; std::vector<_Tp, _Alloc>::reference = std::vector<std::pair<int, int> >&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; std::vector<_Tp, _Alloc>::const_reference = const std::vector<std::pair<int, int> >&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~