Submission #1037965

#TimeUsernameProblemLanguageResultExecution timeMemory
1037965karokRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; struct Edges { int target, weight; }; const int MAXN = 200000; const int MAXK = 1000000; int n, k; vector<vector<Edges>> adj(MAXN); int tree_size[MAXN] = {}; bool is_removed[MAXN]; int get_tree_size(int cur_vertex, int parent = -1) { int &res = tree_size[cur_vertex]; res = 1; for (auto [v, w] : adj[cur_vertex]) { if (v == parent || is_removed[v])continue; continue; res += get_tree_size(v, cur_vertex); } return res; } int get_centroid(int cur_vertex, int n, int parent = -1) { for (auto [v, w] : adj[cur_vertex]) { if (parent == v || is_removed[v]) continue; if (tree_size[v] * 2 > n) return get_centroid(v, n, cur_vertex); } return cur_vertex; } int dfs(int cur_v,int cur_length, int total_ans, set<int> &past_lengths, int parent = -1){ int res = INT_MAX; if(past_lengths.count(k - cur_length)) { return total_ans; } for(auto [v, w]: adj[cur_v]){ if(v == parent || is_removed[v]) continue; res = min(dfs(v, w + cur_length, total_ans + 1, past_lengths, cur_v), res); } past_lengths.insert(cur_length); return res; } int centroid_dfs(int cur_v) { int centroid = get_centroid(cur_v, get_tree_size(cur_v)); int res; { set<int> lengths{0}; res = dfs(centroid, 0, 0, lengths); } is_removed[centroid] = true; for(auto [u, w]: adj[centroid]) { if(is_removed[u])continue; res = min(centroid_dfs(u), res); } return res; } int main() { cin >> n >> k; for (int i = 0; i < n - 1; i++) { int u, v, w; cin >> u >> v >> w; adj[u].push_back(Edges{v, w}); adj[v].push_back(Edges{u, w}); } cout << centroid_dfs(0) << endl; }

Compilation message (stderr)

/usr/bin/ld: /tmp/cckJ96Mn.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cceBxTxr.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cceBxTxr.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