Submission #290110

#TimeUsernameProblemLanguageResultExecution timeMemory
290110REALITYNBRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define pii pair<int,int> #define F first #define S second using namespace std; int n , k ; const int mxn = 2e5+1 ; vector<pii> adj[mxn] ; vector<int> sz(mxn) , w(mxn) ,h(mxn) ; void sub(int a , int p){ sz[a]=1 ; if(p!=-1) h[a]=h[p]+1 ; for(pii& x : a){ if(x.F==p) continue ; w[x]=w[a]+x.S ; sub(x.F,a) ; sz[a]+=sz[x] ; } } int mn = 1e9 ; vector<int> p[mxn] ; map<int,multiset> cnt ; void dfs(int a , int p , int keep){ int bigchild = -1 , mx = -1 ; for(pii& y : adj[a]){ int x = y.F ; if(x==p) continue ; if(sz[x]>mx){ mx=sz[x] ; bigchild= x ; } } for(pii& y : adj[a]){ int x = y.F ; if(x==p||x==bigchild) continue ; dfs(x,a,0) ; } if(bigchild!=-1){ dfs(bigchild,a,1) ; swap(p[bigchild],p[a]) ; } p[a].push_back(a) ; int target = k+2*w[a] ; if(cnt.count(target-w[a])) mn = min(mn,*(cnt[target-w[a]].begin())-h[a]) ; cnt[w[a]].insert(h[a]) ; for(pii& y : adj[a]){ if(y==p||y==bigchild) continue ; for(int& x : p[y.F]){ if(cnt.count(target-w[x])) mn = min(*(cnt[target-w[x]].begin())+h[x]-h[a]*2+,mn) ; p.pb(x) ; } for(int& x :p[y.F]) cnt[w[a]].insert(h[x]) ; } if(keep==0){ for(int& x: p[a]){ cnt[w[x]].erase(cnt[w[x]].find(h[x])) ; if(cnt[w[x]].empty()) cnt.erase(cnt.find(w[x])) ; } } } int best_path(int N , int K , int H[][2] , int L[]){ n = N ; k = K ; for(int i=0;i<n;i++){ adj[h[i][0]].push_back(mp(h[i][1],L[i])); adj[h[i][1]].push_back(mp(h[i][0],L[i])) ; } return solve() ; } int solve(){ sub(1,-1) ; dfs(1,-1,1) ; if(mn==1e9) return -1 ; return mn : } int main(){ input() ; solve() ; return 0; }

Compilation message (stderr)

race.cpp: In function 'void sub(int, int)':
race.cpp:15:18: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   15 |     for(pii& x : a){
      |                  ^
      |                  std::begin
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:95,
                 from race.cpp:1:
/usr/include/c++/9/valarray:1224:5: note: 'std::begin' declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
race.cpp:15:18: error: 'end' was not declared in this scope; did you mean 'std::end'?
   15 |     for(pii& x : a){
      |                  ^
      |                  std::end
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:95,
                 from race.cpp:1:
/usr/include/c++/9/valarray:1244:5: note: 'std::end' declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
race.cpp:17:10: error: no match for 'operator[]' (operand types are 'std::vector<int>' and 'std::pair<int, int>')
   17 |         w[x]=w[a]+x.S ;
      |          ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from race.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 = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = 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 'std::pair<int, int>' to '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 = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const 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 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
race.cpp:19:18: error: no match for 'operator[]' (operand types are 'std::vector<int>' and 'std::pair<int, int>')
   19 |         sz[a]+=sz[x] ;
      |                  ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from race.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 = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = 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 'std::pair<int, int>' to '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 = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const 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 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
race.cpp: At global scope:
race.cpp:24:17: error: type/value mismatch at argument 2 in template parameter list for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
   24 | map<int,multiset> cnt ;
      |                 ^
race.cpp:24:17: note:   expected a type, got 'multiset'
race.cpp:24:17: error: template argument 4 is invalid
race.cpp: In function 'void dfs(int, int, int)':
race.cpp:42:24: error: invalid types 'int[int]' for array subscript
   42 |         swap(p[bigchild],p[a]) ;
      |                        ^
race.cpp:42:29: error: invalid types 'int[int]' for array subscript
   42 |         swap(p[bigchild],p[a]) ;
      |                             ^
race.cpp:44:8: error: invalid types 'int[int]' for array subscript
   44 |     p[a].push_back(a) ;
      |        ^
race.cpp:46:12: error: request for member 'count' in 'cnt', which is of non-class type 'int'
   46 |     if(cnt.count(target-w[a])) mn = min(mn,*(cnt[target-w[a]].begin())-h[a]) ;
      |            ^~~~~
race.cpp:46:61: error: invalid types 'int[int]' for array subscript
   46 |     if(cnt.count(target-w[a])) mn = min(mn,*(cnt[target-w[a]].begin())-h[a]) ;
      |                                                             ^
race.cpp:47:13: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   47 |     cnt[w[a]].insert(h[a]) ;
      |             ^
race.cpp:49:13: error: no match for 'operator==' (operand types are 'std::pair<int, int>' and 'int')
   49 |         if(y==p||y==bigchild) continue ;
      |            ~^~~
      |            |  |
      |            |  int
      |            std::pair<int, int>
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from race.cpp:1:
/usr/include/c++/9/bits/regex.h:1026:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator==(const std::__cxx11::sub_match<_BiIter>&, const std::__cxx11::sub_match<_BiIter>&)'
 1026 |     operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1026:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from race.cpp:1:
/usr/include/c++/9/bits/regex.h:1099:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const std::__cxx11::sub_match<_BiIter>&)'
 1099 |     operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1099:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from race.cpp:1:
/usr/include/c++/9/bits/regex.h:1173:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(const std::__cxx11::sub_match<_BiIter>&, std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1173 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1173:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from race.cpp:1:
/usr/include/c++/9/bits/regex.h:1247:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type*, const std::__cxx11::sub_match<_BiIter>&)'
 1247 |     operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1247:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from race.cpp:1:
/usr/include/c++/9/bits/regex.h:1321:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const std::__cxx11::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1321 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1321:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from race.cpp:1:
/usr/include/c++/9/bits/regex.h:1395:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type&, const std::__cxx11::sub_match<_BiIter>&)'
 1395 |     operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1395:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from race.cpp:1:
/usr/include/c++/9/bits/regex.h:1473:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const std::__cxx11::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
 1473 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1473:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from race.cpp:1:
/usr/include/c++/9/bits/regex.h:1991:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator==(const std::__cxx11::match_results<_BiIter, _Alloc>&, const std::__cxx11::match_results<_BiIter, _Alloc>&)'
 1991 |     operator==(const match_results<_Bi_iter, _Alloc>& __m1,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1991:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::__cxx11::match_results<_BiIter, _Alloc>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/iosfwd:40,
                 from /usr/include/c++/9/ios:38,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/9/bits/postypes.h:222:5: note: candidate: 'template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)'
  222 |     operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/9/bits/postypes.h:222:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::fpos<_StateT>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/9/bits/stl_pair.h:448:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
  448 |     operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_pair.h:448:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:325:5: note: candidate: 'template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
  325 |     operator==(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:325:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::reverse_iterator<_Iterator>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:363:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
  363 |     operator==(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:363:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::reverse_iterator<_Iterator>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:1139:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
 1139 |     operator==(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:1139:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::move_iterator<_IteratorL>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:1145:5: note: candidate: 'template<class _Iterator> bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)'
 1145 |     operator==(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:1145:5: note:   template argument deduction/substitution failed:
race.cpp:49:15: note:   'std::pair<int, int>' is not derived from 'const std::move_iterator<_IteratorL>'
   49 |         if(y==p||y==bigchild) continue ;
      |               ^
In file included from /usr/include/c++/9/string:41,
                 from /usr/include/c+