Submission #992422

#TimeUsernameProblemLanguageResultExecution timeMemory
992422AbodeKuRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define INFLL 1e9 #define rep(f, s, i) for (int i = f; (int) i < s; i++) const int N = 2e5 + 9 ; struct edge{ int u , v , w ; }; vector<pair<int , int>> adj[N]; vector<edge>e(N); int ans = INFLL ; struct Centroid{ vector<int> sub , removed ; map<int,int> mn_sub , mn ; int n , sz , k ; Centroid(int n , int k): n(n) , k(k){ sub = vector<int>(n + 1) ; removed = vector<int>(n + 1); } void build(int node = 1){ int centroid = find_centroid(node); removed[centroid] = true ; mn.clear(); mn[0] = 0 ; for(auto [nd , w] : adj[centroid]){ if(removed[nd])continue ; mn_sub.clear(); dfs_mn(nd , centroid , w); for(auto [key , v] : mn_sub){ if(mn.find(k - key) != mn.end()){ ans = min(ans , mn_sub[key] + mn[k - key]); } } for(auto [key , v] : mn_sub){ if(mn.find(key) == mn.end()) mn[key] = v ; else mn[key] = min(mn[key] , v); } } mn.clear(); for(auto [nd , w] : adj[centroid]){ if(!removed[nd]) build(nd); } } int find_centroid(int node){ sz = dfs_sub(node , node) ; return dfs_centroid(node , node) ; } int dfs_sub(int node , int par){ sub[node] = 1 ; for(auto [nd , w] : adj[node]){ if(nd == par || removed[nd]) continue ; sub[node] += dfs_sub(nd , node); } return sub[node] ; } int dfs_centroid(int node , int par){ for(auto [nd , w] : adj[node]){ if(nd == par || removed[nd]) continue ; if(sub[nd] * 2 > sz) return dfs_centroid(nd , node); } return node ; } void dfs_mn(int node , int par , int c , int depth = 1){ if(c > k) return ; if(mn_sub.find(c) == mn_sub.end()) mn_sub[c] = depth ; else mn_sub[c] = min(mn_sub[c] , depth); for(auto [nd , w] : adj[node]){ if(nd == par || removed[nd]) continue ; dfs_mn(nd , node , c + w , depth + 1); } } }; int best_bath(int n , int k , int h[][2] , int weights[]){ rep(0 , n-1 , i){ int u = h[i][0] , v = h[i][1] ; e[i] = {u , v , 0}; } rep(0 , n-1 , i){ int w = weights[i]; e[i].w = w ; auto [u , v , c] = e[i]; adj[u].push_back(mp(v , w)); adj[v].push_back(mp(u , w)); } Centroid c(n , k); c.build(); if(ans == INFLL) return -1; return ans ; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccP3kLtM.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