Submission #976067

#TimeUsernameProblemLanguageResultExecution timeMemory
976067AmaarsaaRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include "race.h" #define MAX_N 100000 vector < pair < int, int > > adj[200004]; int sz[200004], used[200005], d[1000004]; int N, K; int H[MAX_N][2]; int L[MAX_N]; vector < int > v; int find_size(int node, int parent) { sz[node] = 1; for ( pair <int,int >& A : adj[node]) { int child = A.first; if ( used[child] || parent == child) continue; sz[node] += find_size(child, node); } return sz[node]; } int find_centroid(int node, int parent, int n) { for ( pair <int, int>& A : adj[node]) { int child = A.first; if ( child == parent) continue; if ( sz[child] * 2 > n) find_centroid(child, node, n); } return node; } int ans = -1; void dfs(int node, int parent, int budjaagaa, int dist, int depth) { if ( dist > K) return; if ( budjaagaa) { if ( d[dist] == -1) d[dist] = depth; else d[dist] = min(d[dist], depth); v.push_back(dist); } else { if ( d[K - dist] != -1) { if ( ans == -1) ans = depth + d[K - dist]; else ans = min(ans, depth + d[K - dist]); } } for ( pair < int, int>&A : adj[node]) { int child = A.first; if ( used[child] || child == parent) continue; dfs(child, node, budjaagaa, dist + A.second, depth + 1); } } int solve(int node) { int c = find_centroid(node, node, find_size(node, node)); used[c] = 1; v.clear(); for ( pair <int, int>& A : adj[node]) { int child = A.first; if ( used[child]) continue; dfs(child, node, 0, 0, 0); dfs(child, node, 1, 0, 0); } for (int X : v) { d[X] = -1; } for ( pair <int, int>& A : adj[node]) { int child = A.first; if ( used[child]) continue; solve(child); } } int best_path(int N, int K, int H[][2], int L[]){ for (int i = 0; i < (N - 1); i ++) { adj[H[i][0]].push_back({H[i][1], L[i]}); adj[H[i][1]].push_back({H[i][0], L[i]}); } for (int i = 0; i <=K; i ++) d[i] = -1; solve(0); return ans; }

Compilation message (stderr)

race.cpp:5:1: error: 'vector' does not name a type
    5 | vector < pair < int, int > > adj[200004];
      | ^~~~~~
race.cpp:10:1: error: 'vector' does not name a type
   10 | vector < int > v;
      | ^~~~~~
race.cpp: In function 'int find_size(int, int)':
race.cpp:13:8: error: 'pair' was not declared in this scope
   13 |  for ( pair <int,int >& A : adj[node]) {
      |        ^~~~
race.cpp:13:14: error: expected primary-expression before 'int'
   13 |  for ( pair <int,int >& A : adj[node]) {
      |              ^~~
race.cpp:18:2: error: expected primary-expression before 'return'
   18 |  return sz[node];
      |  ^~~~~~
race.cpp:17:3: error: expected ';' before 'return'
   17 |  }
      |   ^
      |   ;
   18 |  return sz[node];
      |  ~~~~~~
race.cpp:18:2: error: expected primary-expression before 'return'
   18 |  return sz[node];
      |  ^~~~~~
race.cpp:17:3: error: expected ')' before 'return'
   17 |  }
      |   ^
      |   )
   18 |  return sz[node];
      |  ~~~~~~
race.cpp:13:6: note: to match this '('
   13 |  for ( pair <int,int >& A : adj[node]) {
      |      ^
race.cpp: In function 'int find_centroid(int, int, int)':
race.cpp:21:8: error: 'pair' was not declared in this scope
   21 |  for ( pair <int, int>& A : adj[node]) {
      |        ^~~~
race.cpp:21:14: error: expected primary-expression before 'int'
   21 |  for ( pair <int, int>& A : adj[node]) {
      |              ^~~
race.cpp:27:2: error: expected primary-expression before 'return'
   27 |  return node;
      |  ^~~~~~
race.cpp:26:3: error: expected ';' before 'return'
   26 |  }
      |   ^
      |   ;
   27 |  return node;
      |  ~~~~~~
race.cpp:27:2: error: expected primary-expression before 'return'
   27 |  return node;
      |  ^~~~~~
race.cpp:26:3: error: expected ')' before 'return'
   26 |  }
      |   ^
      |   )
   27 |  return node;
      |  ~~~~~~
race.cpp:21:6: note: to match this '('
   21 |  for ( pair <int, int>& A : adj[node]) {
      |      ^
race.cpp: In function 'void dfs(int, int, int, int, int)':
race.cpp:34:18: error: 'min' was not declared in this scope
   34 |   else d[dist] = min(d[dist], depth);
      |                  ^~~
race.cpp:35:3: error: 'v' was not declared in this scope
   35 |   v.push_back(dist);
      |   ^
race.cpp:40:15: error: 'min' was not declared in this scope
   40 |    else ans = min(ans, depth + d[K - dist]);
      |               ^~~
race.cpp:43:8: error: 'pair' was not declared in this scope
   43 |  for ( pair < int, int>&A : adj[node]) {
      |        ^~~~
race.cpp:43:15: error: expected primary-expression before 'int'
   43 |  for ( pair < int, int>&A : adj[node]) {
      |               ^~~
race.cpp:48:1: error: expected primary-expression before '}' token
   48 | }
      | ^
race.cpp:47:3: error: expected ';' before '}' token
   47 |  }
      |   ^
      |   ;
   48 | }
      | ~  
race.cpp:48:1: error: expected primary-expression before '}' token
   48 | }
      | ^
race.cpp:47:3: error: expected ')' before '}' token
   47 |  }
      |   ^
      |   )
   48 | }
      | ~  
race.cpp:43:6: note: to match this '('
   43 |  for ( pair < int, int>&A : adj[node]) {
      |      ^
race.cpp:48:1: error: expected primary-expression before '}' token
   48 | }
      | ^
race.cpp: In function 'int solve(int)':
race.cpp:52:2: error: 'v' was not declared in this scope
   52 |  v.clear();
      |  ^
race.cpp:53:8: error: 'pair' was not declared in this scope
   53 |  for ( pair <int, int>& A : adj[node]) {
      |        ^~~~
race.cpp:53:14: error: expected primary-expression before 'int'
   53 |  for ( pair <int, int>& A : adj[node]) {
      |              ^~~
race.cpp:59:2: error: expected primary-expression before 'for'
   59 |  for (int X : v) {
      |  ^~~
race.cpp:58:3: error: expected ';' before 'for'
   58 |  }
      |   ^
      |   ;
   59 |  for (int X : v) {
      |  ~~~
race.cpp:59:2: error: expected primary-expression before 'for'
   59 |  for (int X : v) {
      |  ^~~
race.cpp:58:3: error: expected ')' before 'for'
   58 |  }
      |   ^
      |   )
   59 |  for (int X : v) {
      |  ~~~
race.cpp:53:6: note: to match this '('
   53 |  for ( pair <int, int>& A : adj[node]) {
      |      ^
race.cpp:62:8: error: 'pair' was not declared in this scope
   62 |  for ( pair <int, int>& A : adj[node]) {
      |        ^~~~
race.cpp:62:14: error: expected primary-expression before 'int'
   62 |  for ( pair <int, int>& A : adj[node]) {
      |              ^~~
race.cpp:67:1: error: expected primary-expression before '}' token
   67 | }
      | ^
race.cpp:66:3: error: expected ';' before '}' token
   66 |  }
      |   ^
      |   ;
   67 | }
      | ~  
race.cpp:67:1: error: expected primary-expression before '}' token
   67 | }
      | ^
race.cpp:66:3: error: expected ')' before '}' token
   66 |  }
      |   ^
      |   )
   67 | }
      | ~  
race.cpp:62:6: note: to match this '('
   62 |  for ( pair <int, int>& A : adj[node]) {
      |      ^
race.cpp:67:1: error: expected primary-expression before '}' token
   67 | }
      | ^
race.cpp:67:1: warning: no return statement in function returning non-void [-Wreturn-type]
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:70:3: error: 'adj' was not declared in this scope
   70 |   adj[H[i][0]].push_back({H[i][1], L[i]});
      |   ^~~