Submission #237857

#TimeUsernameProblemLanguageResultExecution timeMemory
237857T0p_Race (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; #define pb push_back struct EDGE { int node, weight; }; bool visit[200002]; int ans = 1e9; int lv[200002], jmp[2][20][200002], sz[200002]; vector<int> gc[200002]; vector<EDGE> g[200002]; map<int, int> mp[200002]; void dfs(int u, int l) { lv[u] = l; for(auto x : g[u]) { if(lv[x.node]) continue ; dfs(x.node, l+1); jmp[0][0][x.node] = u; jmp[1][0][x.node] = x.weight; } } int get_sz(int u, int p) { sz[u] = 1; for(auto x : g[u]) { if(visit[x.node] || x.node == p) continue ; sz[u] += get_sz(x.node, u); } return sz[u]; } int get_centroid(int u, int p, int n) { bool ch = (n - sz[u] <= n/2) ? true : false; int nn = 0, nf = 0; for(auto x : g[u]) { if(visit[x.node] || x.node == p) continue ; if(sz[x.node] > n/2) { ch = false; if(sz[x.node] > nf) { nn = x.node; nf = sz[x.node]; } } } return (ch) ? u : get_centroid(nn, u, n); } int build(int u, int p) { int c = get_centroid(u, p, get_sz(u, p)); visit[c] = true; for(auto x : g[c]) { if(visit[x.node]) continue ; gc[c].pb(build(x.node, c)); } return c; } pair<int, int> finddis(int u, int v) { int r1 = 0, r2 = 0; if(lv[u] < lv[v]) swap(u, v); for(int i=19 ; i>=0 ; i--) if(lv[jmp[0][i][u]] >= lv[v]) { r1 += (1<<i); r2 += jmp[1][i][u]; u = jmp[0][i][u]; } if(u == v) return {r1, r2}; for(int i=19 ; i>=0 ; i--) if(jmp[0][i][u] != jmp[0][i][v]) { r1 += (1<<(i+1)); r2 += jmp[1][i][u] + jmp[1][i][v]; u = jmp[0][i][u], v = jmp[0][i][v]; } return {r1+2, r2+jmp[1][0][u] + jmp[1][0][v]}; } void solve(int u) { for(auto x : gc[u]) solve(x); for(auto x : gc[u]) { pair<int, int> dis = finddis(u, x); for(auto y : mp[x]) { int a = y.first + dis.second; int b = _K - a; if(b <= 0) continue ; if(mp[u].count(b)) ans = min(ans, mp[u][b] + y.second + dis.first); } for(auto y : mp[x]) { int a = y.first + dis.second; if(a > _K) continue ; else if(a == _K) ans = min(ans, y.second + dis.first); else if(mp[u].count(a)) mp[u][a] = min(mp[u][a], y.second + dis.first); else mp[u][a] = y.second + dis.first; } } mp[u][0] = 0; } int best_path(int N, int K, int H[][2], int L[]) { int _K = K; for(int i=0 ; i<N-1 ; i++) { g[H[i][0]+1].pb({H[i][1]+1, L[i]}); g[H[i][1]+1].pb({H[i][0]+1, L[i]}); } dfs(1, 1); for(int i=1 ; i<20 ; i++) for(int j=1 ; j<=N ; j++) { jmp[0][i][j] = jmp[0][i-1][jmp[0][i-1][j]]; jmp[1][i][j] = jmp[1][i-1][j] + jmp[1][i-1][jmp[0][i-1][j]]; } solve(build(1, 0)); return (ans == 1e9) ? -1 : ans; }

Compilation message (stderr)

race.cpp: In function 'void solve(int)':
race.cpp:107:12: error: '_K' was not declared in this scope
    int b = _K - a;
            ^~
race.cpp:114:11: error: '_K' was not declared in this scope
    if(a > _K) continue ;
           ^~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:125:6: warning: unused variable '_K' [-Wunused-variable]
  int _K = K;
      ^~