Submission #42429

#TimeUsernameProblemLanguageResultExecution timeMemory
42429comfileRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back using namespace std; const int MN = 200010; int n,k,ans,sz[MN],dead[MN]; vector<pair<int,int> > g[MN]; void get_sz(int cur,int prev){ sz[cur] = 1; for(auto &x : g[cur]) if(x.first!=prev && !dead[x.first]){ get_sz(x.first,cur); sz[cur] += sz[x.first]; } } int dfs(int cur,int prev,int tot){ for(auto &x : g[cur]) if(x.first!=prev && !dead[x.first]){ if(sz[x.first]>(tot/2)) return dfs(x.first,cur,tot); } return cur; } int one(int root){ get_sz(root,-1); return dfs(root,-1,sz[root]); } void rec(int start){ int c = one(start); dead[c] = 1; for(auto &x : g[c]) if(!dead[x.first]) rec(x.first); map<int,int> cnt; function<void (int,int,int,int,int)> add_cnt = [&](int cur,int prev,int d,int st,int add){ if(d>k) return; cnt[d] = cnt[d]?min(cnt[d],st):st; for(auto &x : g[cur]) if(x.first!=prev && !dead[x.first]){ add_cnt(x.first,cur,d+x.second,st+1,add); } }; function<void (int,int,int,int)> calc = [&](int cur,int prev,int d,int st){ if(d>k) return; if(k!=d && cnt[k-d]) ans = min(ans,st+cnt[k-d]); for(auto &x: g[cur]) if(x.first!=prev && !dead[x.first]){ calc(x.first,cur,d+x.second,st+1); } }; add_cnt(c,-1,0,0,1); if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear(); for(auto &x : g[c]) if(!dead[x.first]){ calc(x.first,c,x.second,1); add_cnt(x.first,c,x.second,1,1); } dead[c] = 0; } int main(){ ans = MN; ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for(int i=1;i<n;i++){ int a,b,c; cin >> a >> b >> c; g[a].pb(mp(b,c)); g[b].pb(mp(a,c)); } rec(0); if(ans>=MN) ans = -1; cout << ans << '\n'; return 0; }

Compilation message (stderr)

/tmp/ccARvWQH.o: In function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cclEUs1O.o:grader.cpp:(.text.startup+0x0): first defined here
/tmp/cclEUs1O.o: In function `main':
grader.cpp:(.text.startup+0x20): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status