Submission #526879

#TimeUsernameProblemLanguageResultExecution timeMemory
526879YuisuyunoRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
//Nguyen Huu Hoang Minh #include <bits/stdc++.h> #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define reset(x) memset(x, 0,sizeof(x)) #define pb push_back #define mp make_pair #define fi first #define se second #define N 200005 #define remain(x) if (x > MOD) x -= MOD #define ii pair<int, int> #define iiii pair< ii , ii > #define viiii vector< iiii > #define vi vector<int> #define vii vector< ii > #define bit(x, i) (((x) >> (i)) & 1) #define Task "test" #define int long long using namespace std; typedef long double ld; const int inf = 1e10; const int minf = -1e10; int n, ans, k; vector<ii> g[N]; vector<int> brute; bool rm[N]; int s[N], a[1000005], sub[N], d[N], dep[N]; int dfs(int u, int par=-1){ s[u] = 1; for(auto i : g[u]){ int v = i.fi; if (v==par || rm[v]) continue; s[u] += dfs(v,u); } return s[u]; } int get_centroid(int u, int ms, int par=-1){ for(auto i : g[u]){ int v = i.fi; if (v==par || rm[v]) continue; if (s[v]*2 > ms) return get_centroid(v,ms,u); } return u; } int DFS(int u, int par){ sub[u] = 1; brute.pb(u); for(auto i : g[u]){ int v = i.fi; int uv = i.se; if (v==par || rm[v]) continue; d[v] = d[u] + uv; dep[v] = dep[u] + 1; sub[u] += DFS(v,u); } return sub[u]; } void centroid(int n = 0){ int C = get_centroid(n,dfs(n)); rm[C] = 1; if (s[n]==1) return; queue<int> q; for(auto i : g[C]){ int v = i.fi; int uv = i.se; if (rm[v]) continue; d[C] = 0; d[v] = d[C] + uv; dep[C] = 0; dep[v] = dep[C] + 1; brute.clear(); int siz = DFS(v,C); for(auto x : brute){ if (d[x] > k) continue; if (d[x]== k) ans = min(ans,dep[x]); else if (a[k-d[x]]) ans = min(ans,dep[x] + a[k-d[x]]); } for(auto x : brute){ if (d[x] <= k && (a[d[x]]==0 || a[d[x]] > dep[x])) a[d[x]] = dep[x], q.push(d[x]); } } while (q.size()){ a[q.front()] = 0; q.pop(); } for(auto i : g[C]){ int v = i.fi; if (!rm[v]) centroid(v); } } int best_path(int N, int K, int H[][2], int L[]){ n = N; k = K; for(int i=0; i<n-1; i++){ g[H[i][0]].pb(ii(H[i][1],L[i])); g[H[i][1]].pb(ii(H[i][0],L[i])); } ans = n+1; centroid(); return ans == n+1 ? -1 : ans; }

Compilation message (stderr)

race.cpp: In function 'void centroid(long long int)':
race.cpp:71:13: warning: unused variable 'siz' [-Wunused-variable]
   71 |         int siz = DFS(v,C);
      |             ^~~
race.cpp: At global scope:
race.cpp:10:11: error: expected ',' or '...' before numeric constant
   10 | #define N 200005
      |           ^~~~~~
race.cpp:90:19: note: in expansion of macro 'N'
   90 | int best_path(int N, int K, int H[][2], int L[]){
      |                   ^
race.cpp: In function 'long long int best_path(long long int)':
race.cpp:91:16: error: 'K' was not declared in this scope
   91 |     n = N; k = K;
      |                ^
race.cpp:93:11: error: 'H' was not declared in this scope
   93 |         g[H[i][0]].pb(ii(H[i][1],L[i]));
      |           ^
race.cpp:93:34: error: 'L' was not declared in this scope
   93 |         g[H[i][0]].pb(ii(H[i][1],L[i]));
      |                                  ^