Submission #1003465

# Submission time Handle Problem Language Result Execution time Memory
1003465 2024-06-20T11:17:29 Z ilef Race (IOI11_race) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
const int inf=1e9+17;
const int N=2e5+14;
const int K=1e6+1;
int n,k;
int ans;
int mx_depth;
int cnt[K]={0};
bool removed[N];
bool subtree[N];
vector<vector<pair<int,int>>graph;
int treesize(int node,int parent){
    subtree[node]=1;
    for(auto [w,child]:graph[node]){
        if(child!=parent && !removed[child]){
            subtree[node]+=treesize(child,node);
        }
    }
    return subtree[node];
}
int findcentroid(int node,int parent,int treesz){
    for(auto[w,child]:graph[node]){
        if(child!=parent && !removed[child]&& treesize(child,node)>(treesz/2)){
            findcentroid(child,node,teesz);
        }
    }
    return node;
}
void getans(int sum,int node,int parent,int depth,bool filling){
    if (sum>k)return;
    mx_depth=max(mx_depth,sum);
    if(filling)cnt[sum]=min(cnt[sum],depth);
    else{
        ans=min(ans,depth+cnt[k-depth]);
    }
    for(auto[w,child]:graph[node]){
        if(child!=parent && ! removed[child]){
            getans(sum+w,child,node,depth+1,filling);
        }
    }
}
void centroid_decomp(int node,int parent,int treesz){
    centroid=findcentroid(int node,int parent,int treesz);
    removed[centroid]=true;
    for(auto [w,child]:graph[centroid]){
            if(!removed[child]){
        getans(w,child,centroid,1,false);
        getans(w,child,centroid,1,true);}
    }
    fill(cnt+1,cnt+mx_depth+1,inf);
    for(int i:graph[centroid]){
        if(!removed[child]){
        cetroid_decomp(i,centroid,treesize(centroid,centroid));}
    }
}
int best_path(int N,int K,int H[][2],int L){
    mx_depth=0;
    n=N;
    k=k;
    graph.assign(n,vector<pair<int,int>>(n,0));
    for(int i=0;i<n-1;i++){
        int u=H[i][0];
        int v=H[i][1];
        int w=L[i];
        graph[u].push_back({w,v});
        graph[v].push_back({w,u});
    }
    ans=inf;
    memset(cnt,inf,sizeof(cnt));
    memset(removed,false,sizeof(removed));
    centroid_decomp(0,-1,n/2);
    ans=cnt[k];
    return ans;
}

Compilation message

race.cpp:12:29: error: template argument 1 is invalid
   12 | vector<vector<pair<int,int>>graph;
      |                             ^~~~~
race.cpp:12:29: error: template argument 2 is invalid
race.cpp: In function 'int treesize(int, int)':
race.cpp:15:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   15 |     for(auto [w,child]:graph[node]){
      |              ^
race.cpp:15:24: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   15 |     for(auto [w,child]:graph[node]){
      |                        ^~~~~
      |                        isgraph
race.cpp: In function 'int findcentroid(int, int, int)':
race.cpp:23:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for(auto[w,child]:graph[node]){
      |             ^
race.cpp:23:23: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   23 |     for(auto[w,child]:graph[node]){
      |                       ^~~~~
      |                       isgraph
race.cpp:25:37: error: 'teesz' was not declared in this scope; did you mean 'treesz'?
   25 |             findcentroid(child,node,teesz);
      |                                     ^~~~~
      |                                     treesz
race.cpp: In function 'void getans(int, int, int, int, bool)':
race.cpp:37:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |     for(auto[w,child]:graph[node]){
      |             ^
race.cpp:37:23: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   37 |     for(auto[w,child]:graph[node]){
      |                       ^~~~~
      |                       isgraph
race.cpp: In function 'void centroid_decomp(int, int, int)':
race.cpp:44:5: error: 'centroid' was not declared in this scope; did you mean 'findcentroid'?
   44 |     centroid=findcentroid(int node,int parent,int treesz);
      |     ^~~~~~~~
      |     findcentroid
race.cpp:44:27: error: expected primary-expression before 'int'
   44 |     centroid=findcentroid(int node,int parent,int treesz);
      |                           ^~~
race.cpp:44:36: error: expected primary-expression before 'int'
   44 |     centroid=findcentroid(int node,int parent,int treesz);
      |                                    ^~~
race.cpp:44:47: error: expected primary-expression before 'int'
   44 |     centroid=findcentroid(int node,int parent,int treesz);
      |                                               ^~~
race.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |     for(auto [w,child]:graph[centroid]){
      |              ^
race.cpp:46:24: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   46 |     for(auto [w,child]:graph[centroid]){
      |                        ^~~~~
      |                        isgraph
race.cpp:52:15: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   52 |     for(int i:graph[centroid]){
      |               ^~~~~
      |               isgraph
race.cpp:53:21: error: 'child' was not declared in this scope
   53 |         if(!removed[child]){
      |                     ^~~~~
race.cpp:54:9: error: 'cetroid_decomp' was not declared in this scope; did you mean 'centroid_decomp'?
   54 |         cetroid_decomp(i,centroid,treesize(centroid,centroid));}
      |         ^~~~~~~~~~~~~~
      |         centroid_decomp
race.cpp: In function 'int best_path(int, int, int (*)[2], int)':
race.cpp:61:5: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   61 |     graph.assign(n,vector<pair<int,int>>(n,0));
      |     ^~~~~
      |     isgraph
race.cpp:61:45: error: no matching function for call to 'std::vector<std::pair<int, int> >::vector(int&, int)'
   61 |     graph.assign(n,vector<pair<int,int>>(n,0));
      |                                             ^
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 race.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:653:2: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
  653 |  vector(_InputIterator __first, _InputIterator __last,
      |  ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:653:2: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_algobase.h:65,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_types.h: In substitution of 'template<class _InIter> using _RequireInputIter = std::__enable_if_t<std::is_convertible<typename std::iterator_traits< <template-parameter-1-1> >::iterator_category, std::input_iterator_tag>::value> [with _InIter = int]':
/usr/include/c++/10/bits/stl_vector.h:652:9:   required from here
/usr/include/c++/10/bits/stl_iterator_base_types.h:249:11: error: no type named 'iterator_category' in 'struct std::iterator_traits<int>'
  249 |     using _RequireInputIter =
      |           ^~~~~~~~~~~~~~~~~
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 race.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:625:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::pair<int, int> >]'
  625 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:625:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::pair<int, int> >'
  625 |       vector(initializer_list<value_type> __l,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:607:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::pair<int, int> >]'
  607 |       vector(vector&& __rv, const allocator_type& __m)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:607:23: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::pair<int, int> >&&'
  607 |       vector(vector&& __rv, const allocator_type& __m)
      |              ~~~~~~~~~^~~~
/usr/include/c++/10/bits/stl_vector.h:589:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::pair<int, int> >; std::false_type = std::integral_constant<bool, false>]'
  589 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:589:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/10/bits/stl_vector.h:585:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::pair<int, int> >; std::true_type = std::integral_constant<bool, true>]'
  585 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:585:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/10/bits/stl_vector.h:575:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, const allocator_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::pair<int, int> >]'
  575 |       vector(const vector& __x, const allocator_type& __a)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:575:28: note:   no known conversion for argument 1 from 'int' to 'const std::vector<std::pair<int, int> >&'
  575 |       vector(const vector& __x, const allocator_type& __a)
      |              ~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:572:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
  572 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:572:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:553:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
  553 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:553:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:522:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::pair<int, int> >]'
  522 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:522:47: note:   no known conversion for argument 2 from 'int' to 'const value_type&' {aka 'const std::pair<int, int>&'}
  522 |       vector(size_type __n, const value_type& __value,
      |                             ~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/10/bits/stl_vector.h:510:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::pair<int, int> >]'
  510 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:510:51: note:   no known conversion for argument 2 from 'int' to 'const allocator_type&' {aka 'const std::allocator<std::pair<int, int> >&'}
  510 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |                             ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:497:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::pair<int, int> >]'
  497 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:497:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:487:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
  487 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:487:7: note:   candidate expects 0 arguments, 2 provided
race.cpp:65:16: error: invalid types 'int[int]' for array subscript
   65 |         int w=L[i];
      |                ^