Submission #321423

#TimeUsernameProblemLanguageResultExecution timeMemory
321423grtConnecting Supertrees (IOI20_supertrees)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using ll = long long; using pi = pair<int,int>; #define ST first #define ND second #define PB push_back const int nax = 1000 + 10; int n; vi Graph[nax]; bool visited[nax]; vector<vi>comp; vector<vi>access; vi cur; void build(vector<vi>v); void dfs(int x) { visited[x] = 1; cur.PB(x); for(int nbh : Graph[x]) { if(!visited[nbh]) dfs(nbh); } } int construct(vector<vi> p) { int cnt3 = 0; n = (int)p.size(); for(int i = 1; i <= n; ++i) { for(int j = 1; j <= n; ++j) { if(p[i - 1][j - 1] == 1) { Graph[i].PB(j); } if(p[i - 1][j - 1] == 3) cnt3++; } } if(cnt3 > 0) return 0; bool ok = 1; for(int i = 1; i <= n; ++i) { if(!visited[i]) { cur = {}; dfs(i); comp.PB(cur); for(int x : cur) { for(int y : cur) { if(p[x - 1][y - 1] != 1) ok = 0; } } } } if(!ok) return 0; for(auto c : comp) { cur = {}; int id = 0; for(auto c2 : comp) { if(c2 == c) { cur.PB(id); id++; continue; } int cnt0 = 0, cnt1 = 0, cnt2 = 0; for(int x : c) { for(int y : c2) { if(p[x - 1][y - 1] == 0) cnt0++; else if(p[x - 1][y - 1] == 1) cnt1++; else if(p[x - 1][y - 1] == 2) cnt2++; } } assert(cnt1 == 0); if(cnt0 > 0 && cnt2 > 0) ok = 0; if(cnt2 > 0) { cur.PB(id); } id++; } access.PB(cur); if((int)cur.size() == 2) ok = 0; } if(!ok) return 0; for(int i = 0; i <= n; ++i) visited[i] = 0; for(int i = 0; i < (int)comp.size(); ++i) { if(!visited[i]) { cur = access[i]; visited[i] = 1; for(int x : cur) { visited[x] = 1; if(cur != access[x]) ok = 0; } } } if(!ok) return 0; vector<vi>g(n); for(int i = 0; i < n; ++i) g[i].resize(n); for(int nr = 0; nr < (int)access.size(); ++nr) { for(int i = 0; i < (int)comp[nr].size() - 1; ++i) { g[comp[nr][i] - 1][comp[nr][i + 1] - 1] = g[comp[nr][i + 1] - 1][comp[nr][i] - 1] = 1; } //cout << nr << " "; for(int i = 0; i < (int)access[nr].size(); ++i) { if(access[nr][i] == nr) { int pr = i - 1; if(pr < 0) pr = (int)acces[nr].size() - 1; g[comp[access[pr]][0] - 1][comp[nr][0] - 1] = g[comp[nr][0] - 1][comp[access[pr]][0] - 1] = 1; } } } build(g); //for(int i = 0; i < n; ++i) { // for(int j = 0; j < n; ++j) { // cout << g[i][j] << " "; // } // cout << "\n"; //} return 1; } //int main() { //cout << construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}}); //cout << construct({{1,3},{3,1}}); //}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:107:38: error: 'acces' was not declared in this scope; did you mean 'access'?
  107 |                 if(pr < 0) pr = (int)acces[nr].size() - 1;
      |                                      ^~~~~
      |                                      access
supertrees.cpp:108:23: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<int> >' and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'})
  108 |                 g[comp[access[pr]][0] - 1][comp[nr][0] - 1] = g[comp[nr][0] - 1][comp[access[pr]][0] - 1] = 1;
      |                       ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from supertrees.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1040:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::reference = std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1040:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1058: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<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::const_reference = const std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1058:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
supertrees.cpp:108:86: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<int> >' and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'})
  108 |                 g[comp[access[pr]][0] - 1][comp[nr][0] - 1] = g[comp[nr][0] - 1][comp[access[pr]][0] - 1] = 1;
      |                                                                                      ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from supertrees.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1040:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::reference = std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1040:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1058: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<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::const_reference = const std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1058:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~