Submission #149230

#TimeUsernameProblemLanguageResultExecution timeMemory
149230anonymousRace (IOI11_race)C++14
100 / 100
755 ms97144 KiB
#include<iostream> #include<tr1/unordered_map> #include<utility> #include<vector> #include "race.h" using namespace std; int N,ui,vi,wi; long long K; int big[200005],out=1<<30; vector <pair<int,int> > adj[200005]; tr1::unordered_map<long long,int> M[200005]; int dfs(int u, int prev, long long depth, int e) { big[u]=u; M[u][depth]=e; for (auto v: adj[u]) { if (v.first == prev) {continue;} int res=dfs(v.first,u,depth+v.second,e+1); if (M[big[u]].size()<M[res].size()) { swap(big[u],res); } for (auto val: M[res]) { if (M[big[u]].find(K+2*depth-val.first) != M[big[u]].end()) { out=min(out,M[big[u]][K+2*depth-val.first]+val.second-2*e); } } for (auto val: M[res]) { if (M[big[u]].find(val.first)==M[big[u]].end()) { M[big[u]][val.first]=val.second; } if (M[big[u]][val.first]>val.second) { M[big[u]][val.first]=val.second; } } } return(big[u]); } int best_path(int n, int k, int H[][2], int L[]) { K=k; for (int i=0; i<n-1; i++) { adj[H[i][0]].push_back({H[i][1],L[i]}); adj[H[i][1]].push_back({H[i][0],L[i]}); } //1 indexify dfs(0,-1,0,0); return(out<=n ? out : -1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...