Submission #1294256

#TimeUsernameProblemLanguageResultExecution timeMemory
1294256h1manshusinghRace (IOI11_race)C++20
Compilation error
0 ms0 KiB
#include "race.h"
using i64  = long long;
#include<bits/stdc++.h>
using namespace std;

int best_path(int n, int k, int H[][2], int L[])
{
      const int inf = 1e8;
      vector<vector<pair<int,int>>> G(n);
      for( int i = 0; i < n; i++){
            G[H[i][0]].push_back({H[i][1],L[i]});
            G[H[i][1]].push_back({H[i][0],L[i]});
      }
      vector<vector<int>> CG(n);
      vector<int> sz(n);
      vector<bool> visited(n);
      auto getsz = [&](this auto &&getsz, int u, int p)->void{
            sz[u] = 1;
            for( auto [v,w]:G[u]){
                  if( v != p and !visited[v]){
                        getsz(v,u);
                        sz[u] += sz[v];
                  }
            }
      };

      auto centroid = [&](this auto &&centroid, int u, int p, int S)->int{
            for(auto [v,w]: G[u]){
                  if( v != p and !visited[v]){
                        if( sz[v] > S/2)
                              return centroid(v,u,S);
                  }
            }
            return u;
      };
      //vector<int> K(k+1, inf);
     // vector<int> K_tmp(k+1, inf);
     map<i64,int> K;

      //auto iinf = [&](this auto && iinf, int u, int p)-void{
      //      K[u] = inf;
      //      //K_tmp = inf;
      //      for( auto [v,w]:G[u]){
      //            if( v != p and !visited[v]){
      //                  iinf(v,u);
      //            }
      //      }
      //};

     // auto iinf_temp = [&](this auto && iinf_temp, int u, int p)-void{
     //       K_tmp = inf;
     //       for( auto [v,w]:G[u]){
     //             if( v != p and !visited[v]){
     //                   iinf_temp(v,u);
     //             }
     //       }
     // };
       
      int ans = inf;

      auto find = [&](this auto &&find, int u,int p, int d, i64 l)->void{
            if( l > k) return; // already pass the limit
            //ans = min(ans,K[k-l]+d);
            if( K.find(k-l) != K.end()){
                  ans = min( ans, K[k-l] + d);
            }
            //K_temp[l] = min(K_temp[l], d);
            for( auto [v,w]: G[u]){
                  if( v != p and !visited[v]){
                        find(v,u,d+1,l+w);
                  }
            }
      };
      auto optimize = [&](this auto &&optimize, int u,int p, int d, i64 l)->void{
            if( l > k) return; // already pass the limit
            if( K.find(l) == K.end()) K[l] = d;
            else K[l] = min(K[l],d);
            for( auto [v,w]: G[u]){
                  if( v != p and !visited[v]){
                        optimize(v,u,d+1,l+w);
                  }
            }
      };

      auto decompose = [&](this auto &&decompose, int u)->void{
            getsz(u,-1);
            int c = centroid(u,-1,sz[u]);
            visited[c] = true;
            // do the processing
            //iinf(u,-1);
            K.clear();
            K[0] = 0;
            for( auto [v,w]: G[c]){
                  if( !visited[v]){
                        // this is one component of current centroid
                        // initialise all its children to inf
                        find(v,c,1,w);      
                        optimize(v,c,1,w);
                        //int cent = decompose(v);
                  }
            }
            for( auto [v,w]:G[c]){
                  if( !visited[v]){
                        decompose(v);
                  }
            }
      };
      decompose(0);
      if(ans >= inf) return -1;
      return ans;
}

//int main(){
//
//      const int N = 2e5+5;
//      int high[N][2];
//      int w[N];
//      int n,k; cin >> n >> k;
//      for( int i = 0; i < n-1; i++){
//            cin >> high[i][0] >> high[i][1] >> w[i];
//      }
//      int ans = best_path(n,k,high,w);
//      cout << ans << '\n';
//      return 0;
//}


Compilation message (stderr)

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:17:24: error: expected identifier before 'this'
   17 |       auto getsz = [&](this auto &&getsz, int u, int p)->void{
      |                        ^~~~
race.cpp:17:24: error: expected ',' or '...' before 'this'
race.cpp: In lambda function:
race.cpp:18:16: error: 'u' was not declared in this scope
   18 |             sz[u] = 1;
      |                ^
race.cpp:20:28: error: 'p' was not declared in this scope
   20 |                   if( v != p and !visited[v]){
      |                            ^
race.cpp:21:25: error: use of 'getsz' before deduction of 'auto'
   21 |                         getsz(v,u);
      |                         ^~~~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:27:27: error: expected identifier before 'this'
   27 |       auto centroid = [&](this auto &&centroid, int u, int p, int S)->int{
      |                           ^~~~
race.cpp:27:27: error: expected ',' or '...' before 'this'
race.cpp: In lambda function:
race.cpp:28:31: error: 'u' was not declared in this scope
   28 |             for(auto [v,w]: G[u]){
      |                               ^
race.cpp:29:28: error: 'p' was not declared in this scope
   29 |                   if( v != p and !visited[v]){
      |                            ^
race.cpp:30:37: error: 'S' was not declared in this scope
   30 |                         if( sz[v] > S/2)
      |                                     ^
race.cpp:31:38: error: use of 'centroid' before deduction of 'auto'
   31 |                               return centroid(v,u,S);
      |                                      ^~~~~~~~
race.cpp:34:20: error: 'u' was not declared in this scope
   34 |             return u;
      |                    ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:61:23: error: expected identifier before 'this'
   61 |       auto find = [&](this auto &&find, int u,int p, int d, i64 l)->void{
      |                       ^~~~
race.cpp:61:23: error: expected ',' or '...' before 'this'
race.cpp: In lambda function:
race.cpp:62:17: error: 'l' was not declared in this scope
   62 |             if( l > k) return; // already pass the limit
      |                 ^
race.cpp:64:26: error: 'l' was not declared in this scope
   64 |             if( K.find(k-l) != K.end()){
      |                          ^
race.cpp:65:44: error: 'd' was not declared in this scope
   65 |                   ans = min( ans, K[k-l] + d);
      |                                            ^
race.cpp:68:32: error: 'u' was not declared in this scope
   68 |             for( auto [v,w]: G[u]){
      |                                ^
race.cpp:69:28: error: 'p' was not declared in this scope
   69 |                   if( v != p and !visited[v]){
      |                            ^
race.cpp:70:25: error: use of 'find' before deduction of 'auto'
   70 |                         find(v,u,d+1,l+w);
      |                         ^~~~
race.cpp:70:34: error: 'd' was not declared in this scope
   70 |                         find(v,u,d+1,l+w);
      |                                  ^
race.cpp:70:38: error: 'l' was not declared in this scope
   70 |                         find(v,u,d+1,l+w);
      |                                      ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:74:27: error: expected identifier before 'this'
   74 |       auto optimize = [&](this auto &&optimize, int u,int p, int d, i64 l)->void{
      |                           ^~~~
race.cpp:74:27: error: expected ',' or '...' before 'this'
race.cpp: In lambda function:
race.cpp:75:17: error: 'l' was not declared in this scope
   75 |             if( l > k) return; // already pass the limit
      |                 ^
race.cpp:76:24: error: 'l' was not declared in this scope
   76 |             if( K.find(l) == K.end()) K[l] = d;
      |                        ^
race.cpp:76:46: error: 'd' was not declared in this scope
   76 |             if( K.find(l) == K.end()) K[l] = d;
      |                                              ^
race.cpp:77:34: error: 'd' was not declared in this scope
   77 |             else K[l] = min(K[l],d);
      |                                  ^
race.cpp:78:32: error: 'u' was not declared in this scope
   78 |             for( auto [v,w]: G[u]){
      |                                ^
race.cpp:79:28: error: 'p' was not declared in this scope
   79 |                   if( v != p and !visited[v]){
      |                            ^
race.cpp:80:25: error: use of 'optimize' before deduction of 'auto'
   80 |                         optimize(v,u,d+1,l+w);
      |                         ^~~~~~~~
race.cpp:80:38: error: 'd' was not declared in this scope
   80 |                         optimize(v,u,d+1,l+w);
      |                                      ^
race.cpp:80:42: error: 'l' was not declared in this scope
   80 |                         optimize(v,u,d+1,l+w);
      |                                          ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:85:28: error: expected identifier before 'this'
   85 |       auto decompose = [&](this auto &&decompose, int u)->void{
      |                            ^~~~
race.cpp:85:28: error: expected ',' or '...' before 'this'
race.cpp: In lambda function:
race.cpp:86:19: error: 'u' was not declared in this scope
   86 |             getsz(u,-1);
      |                   ^
race.cpp:97:29: error: no match for call to '(best_path(int, int, int (*)[2], int*)::<lambda(int)>) (std::tuple_element<0, std::pair<int, int> >::type&, int&, int, std::tuple_element<1, std::pair<int, int> >::type&)'
   97 |                         find(v,c,1,w);
      |                         ~~~~^~~~~~~~~
race.cpp:61:19: note: candidate: 'best_path(int, int, int (*)[2], int*)::<lambda(int)>'
   61 |       auto find = [&](this auto &&find, int u,int p, int d, i64 l)->void{
      |                   ^
race.cpp:61:19: note:   candidate expects 1 argument, 4 provided
race.cpp:98:33: error: no match for call to '(best_path(int, int, int (*)[2], int*)::<lambda(int)>) (std::tuple_element<0, std::pair<int, int> >::type&, int&, int, std::tuple_element<1, std::pair<int, int> >::type&)'
   98 |                         optimize(v,c,1,w);
      |                         ~~~~~~~~^~~~~~~~~
race.cpp:74:23: note: candidate: 'best_path(int, int, int (*)[2], int*)::<lambda(int)>'
   74 |       auto optimize = [&](this auto &&optimize, int u,int p, int d, i64 l)->void{
      |                       ^
race.cpp:74:23: note:   candidate expects 1 argument, 4 provided
race.cpp:104:25: error: use of 'decompose' before deduction of 'auto'
  104 |                         decompose(v);
      |                         ^~~~~~~~~