Submission #992416

#TimeUsernameProblemLanguageResultExecution timeMemory
992416AbodeKuRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll , ll> PII ; typedef vector<bool> vb ; typedef vector<ll> vi; typedef vector<PII> vpi; typedef vector<vector<ll>> vvi; typedef vector<vector<PII>> vvpi; typedef vector<char> vc ; const double EBS = 1e-9; const double pi = 3.14159265358979 ; #define Log(x) (31^__builtin_clz(x)) #define logll(x) (63^__builtin_clzll(x)) // processor cycle counter can be used to get a random number easily :) #define rand __builtin_ia32_rdtsc() #define popcount(i) __builtin_popcount(i) #define popcountll(i) __builtin_popcountll(i) #define mp make_pair #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n"; #define testCase ll t; cin >> t; while (t--) #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define rep(f, s, i) for (ll i = f; (int) i < s; i++) #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} #define calunique(v) disance(v.begin(),unique(v.begin(),v.end())); #define el cout << "\n" #define mb make_pair #define pb push_back #define no cout << "NO\n" #define yes cout << "YES\n" #define all(v) v.begin(), v.end() #define INF (ll) 1e9 #define INFLL (ll)1e9 #define debug cout << "\n___________________________________\n" // #define int ll #define Left ((p << 1) + 1) #define Right ((p << 1) + 2) const int N = 2e5 + 9 ; struct edge{ int u , v , w ; }; vpi adj[N]; vector<edge>e(N); int ans = INFLL ; struct Centroid{ vi sub , removed ; map<int,int> mn_sub , mn ; int n , sz , k ; Centroid(int n , int k): n(n) , k(k){ sub = vi(n + 1) ; removed = vi(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].pb(mp(v , w)); adj[v].pb(mp(u , w)); } Centroid c(n , k); c.build(); if(ans == INFLL) return -1; return ans ; }

Compilation message (stderr)

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