Submission #481242

#TimeUsernameProblemLanguageResultExecution timeMemory
481242CyberSleeperRace (IOI11_race)C++14
43 / 100
2431 ms97732 KiB
#include <bits/stdc++.h> #include "race.h" #define ll long long #define pii pair<ll, ll> #define fi first #define se second #define pb push_back using namespace std; const ll MX=200007, INF=1e9+7; vector<pii> adj[MX]; map<ll, pii> ada[MX]; ll N, K, ret=INF; void add(ll i, ll j, ll x){ if(ada[i].count(j)){ pii now=ada[i][j]; if(now.se>x) now.se=x; if(now.fi>now.se) swap(now.fi, now.se); ada[i][j]=now; }else{ ada[i][j]={x, INF}; } } void DFS(ll par, ll wpar, ll x){ ada[x][0]={0, INF}; for(auto i:adj[x]){ ll v=i.fi, w=i.se; if(v==par) continue; DFS(x, w, v); if(ada[x].size()<ada[v].size()) swap(ada[x], ada[v]); for(auto j:ada[v]){ ll tot=j.fi, sisa=K-tot; pii cnt=j.se; if(tot>K) continue; if(ada[x].count(sisa)){ ret=min(ret, ada[x][sisa].fi+ada[v][tot].fi); } add(x, tot, cnt.fi); add(x, tot, cnt.se); } } vector<ll> delay; vector<pair<ll, pii>> tambah; for(auto i=ada[x].rbegin(); i!=ada[x].rend(); i++){ pair<ll, pii> tmp=*i; tmp.se.fi++; tmp.se.se++; if(tmp.fi+wpar<=K) tambah.pb({tmp.fi+wpar, tmp.se}); delay.pb(tmp.fi); } for(auto i:delay) ada[x].erase(i); for(auto i:tambah) ada[x][i.fi]=i.se; if(ada[x].count(K)) ret=min(ret, ada[x][K].fi); } int best_path(int n, int k, int H[][2], int L[]){ N=n, K=k; for(ll i=0, u, v, w; i<N-1; i++){ u=H[i][0], v=H[i][1], w=L[i]; adj[u].pb({v, w}); adj[v].pb({u, w}); } DFS(0, 0, 0); return (ret>=INF?-1:ret); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...