Submission #975950

#TimeUsernameProblemLanguageResultExecution timeMemory
975950AmaarsaaRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define el '\n' #define fi first #define sc second //#define int ll #define pii pair<int, int> #define all(v) v.begin(), v.end() using namespace std; using ll=long long; using ull=unsigned long long; using ld=long double; const int mod=1e9+7; const int N=2e5+11; const int lim=1e6+11; int n, k, sz[N], vit[N], dp[lim], mx; vector<int> ned; int ans=-1; vector<pii> adj[N]; int subtree(int u, int pa) { sz[u] = 1; for (auto v: adj[u]) { if (v.fi != pa && !vit[v.fi]) { sz[u] += subtree(v.fi, u); } } return sz[u]; } int cen(int u, int pa, int n) { for (auto v: adj[u]) { if (v.fi != pa && !vit[v.fi] && sz[v.fi] > n/2) { return cen(v.fi, u, n); } } return u; } void dfs(int u, int pa, int dis, int h, int ch) { if(dis > k) return; if(ch) { if(dp[dis]==-1) dp[dis]=h; else dp[dis]=min(dp[dis], h); ned.push_back(dis); } else { if(dp[k-dis]!=-1) { if(ans==-1) ans=dp[k-dis]+h; else ans=min(ans, dp[k-dis]+h); } } for(auto v: adj[u]) { if(v.fi != pa && !vit[v.fi]) dfs(v.fi, u, dis+v.sc, h+1, ch); } } void calc(int u) { subtree(u, 0); int c = cen(u, 0, sz[u]); vit[c] = 1; for(auto u: adj[c]) { if (!vit[u.fi]) { dfs(u.fi, c, u.sc, 1, 0); dfs(u.fi, c, u.sc, 1, 1); } } for(int x : ned) dp[x]=-1; ned.clear(); for(auto v: adj[c]) { if (!vit[v.fi]) { calc(v.fi); } } } void sol() { cin >> n >> k; for(int i=1, u, v, x; i<n; i++) { cin >> u >> v >> x; adj[u+1].push_back({v+1, x}); adj[v+1].push_back({u+1, x}); } memset(dp, -1, sizeof dp); dp[0]=0; calc(1); cout << ans; } signed main() { // freopen("divisor.INP", "r", stdin); // freopen("divisor.OUT", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); int t=1; //cin >> t; while(t--) { sol(); } }

Compilation message (stderr)

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