Submission #1018292

#TimeUsernameProblemLanguageResultExecution timeMemory
1018292gutzzyTraffic (IOI10_traffic)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "traffic.h" using namespace std; vector<int> dp; vector<vector<int>> lst; pair<int,int> ans; int calc(int nodo, int padre, vector<int> &p){ if(dp[nodo]!=-1) return dp[nodo]; int res = p[nodo]; for(auto vecino:lst[nodo]){ if(vecino!=padre) res += calc(vecino,nodo,p); } dp[nodo] = res; return dp[nodo]; } void dfs(int nodo, int padre, vector<int> &p){ dp[padre] = -1; int res = 0; for(auto vecino:lst[nodo]){ res = max(res, calc(vecino,nodo,p)); } //cout << "arena: " << nodo << " res: " << res << endl; if(res<ans.second){ //cout << "update! new arena: " << nodo << " " << res << endl; ans.second = res; ans.first = nodo; } for(auto vecino:lst[nodo]){ if(vecino!=padre) dfs(vecino,nodo,p); } return; } int LocateCentre(int n, vector<int> *p, vector<int> *s, vector<int> *d){ dp = vector<int>(n,-1); ans.first = 0; ans.second = 2e9; lst = vector<vector<int>>(n,vector<int>()); for(int i=0;i<n-1;i++){ lst[s[i]].push_back(d[i]); lst[d[i]].push_back(s[i]); } dfs(0,0,p); return ans.first; } /* int main(){ cout << LocateCentre(5,{10,10,10,20,20},{0,1,2,3},{2,2,3,4}) << endl; return 0; } */

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, std::vector<int>*, std::vector<int>*, std::vector<int>*)':
traffic.cpp:44:12: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<int> >' and 'std::vector<int>')
   44 |         lst[s[i]].push_back(d[i]);
      |            ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from traffic.cpp:1:
/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<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::reference = std::vector<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 'std::vector<int>' to 'std::vector<std::vector<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<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]'
 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 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
traffic.cpp:45:12: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<int> >' and 'std::vector<int>')
   45 |         lst[d[i]].push_back(s[i]);
      |            ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from traffic.cpp:1:
/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<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::reference = std::vector<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 'std::vector<int>' to 'std::vector<std::vector<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<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]'
 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 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
traffic.cpp:47:13: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<int>*'
   47 |     dfs(0,0,p);
      |             ^
traffic.cpp:19:44: note: in passing argument 3 of 'void dfs(int, int, std::vector<int>&)'
   19 | void dfs(int nodo, int padre, vector<int> &p){
      |                               ~~~~~~~~~~~~~^