Submission #746172

#TimeUsernameProblemLanguageResultExecution timeMemory
746172JooDdaeRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define int long long #define ll long long #define double long double #define fi first #define se second #define all(a) (a).begin(), (a).end() using namespace std; using pii = pair<int, int>; using ti3 = tuple<int, int, int>; const int MAX = 200010, INF = (int) 1e9 + 7; int n, k, sz[MAX], cPar[MAX], visited[MAX], ans = INF; vector<pii> g[MAX]; map<int, int> mp; int getSize(int cur, int p) { sz[cur] = 1; for (pii nxt: g[cur]) { if (nxt.fi != p && !visited[nxt.fi]) sz[cur] += getSize(nxt.fi, cur); } return sz[cur]; } int getCentroid(int cur, int p, int cap) { for (pii nxt: g[cur]) { if (nxt.fi != p && !visited[nxt.fi] && sz[nxt.fi] * 2 > cap) { return getCentroid(nxt.fi, cur, cap); } } return cur; } void dfs(int cur, int p, int length, int edgeCnt) { if (mp.find(k - length) != mp.end()) ans = min(ans, mp[k - length] + edgeCnt); if (mp.find(length) == mp.end()) mp.insert({ length, edgeCnt }); mp[length] = min(mp[length], edgeCnt); for (pii nxt: g[cur]) { if (nxt.fi != p && !visited[nxt.fi]) { dfs(nxt.fi, cur, length + nxt.se, edgeCnt + 1); } } } void buildTree(int cur, int p) { int ctr = getCentroid(cur, -1, getSize(cur, -1)); mp.clear(); mp.insert({ 0, 0 }); dfs(ctr, -1, 0, 0); cPar[ctr] = p, visited[ctr] = true; for (pii nxt: g[ctr]) { if (!visited[nxt.fi]) { buildTree(nxt.fi, ctr); } } } int best_path(int N, int K, int H[][2], int L[]) { int a, b, w; n = N, k = K; for (int i = 0; i < n; i++) { a = H[i][0], b = H[i][1], w = L[i]; g[a].push_back({ b, w }); g[b].push_back({ a, w }); } buildTree(0, -1); if (ans == INF) ans = -1; return ans; }

Compilation message (stderr)

/usr/bin/ld: /tmp/cc3L768C.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status