Submission #750924

#TimeUsernameProblemLanguageResultExecution timeMemory
750924LCJLYRace (IOI11_race)C++14
0 / 100
9 ms14420 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; typedef pair<int,int>pii; vector<pii>adj[200005]; multiset<pii>storage[200005]; int offset[200005]; int dist[200005]; int d[200005]; int k; int ans=INT_MAX; void dp(int index, int par){ storage[index].insert({dist[index],d[index]}); for(auto it:adj[index]){ if(it.first==par) continue; dist[it.first]=dist[index]+it.second; d[it.first]=d[index]+1; dp(it.first,index); //swap if(storage[it.first].size()>storage[index].size()){ swap(storage[it.first],storage[index]); } //check for(auto it2:storage[it.first]){ int hold=k-it2.first+dist[index]*2; pii hold2=*storage[index].lower_bound({hold,0}); if(hold2.first==hold){ ans=min(ans,hold2.second+it2.second-d[index]*2); } } //merge for(auto it2:storage[it.first]){ storage[index].insert(it2); } } int hold3=dist[index]+k; pii hold4=*storage[index].lower_bound({hold3,0}); if(hold4.first==hold3){ ans=min(ans,hold4.second-d[index]); } } int best_path(int n, int K, int H[][2], int L[]){ k=K; for(int x=0;x<n-1;x++){ adj[H[x][0]].push_back({H[x][1],L[x]}); adj[H[x][1]].push_back({H[x][0],L[x]}); //cout << H[x][0] << " " << H[x][1] << " edge\n"; } dp(0,-1); if(ans==INT_MAX) return -1; return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...