제출 #725692

#제출 시각아이디문제언어결과실행 시간메모리
725692sofija6경주 (Race) (IOI11_race)C++14
21 / 100
3046 ms10316 KiB
#include <bits/stdc++.h> #include "race.h" #define MAXN 200010 using namespace std; vector<pair<int,int> > G[MAXN]; bool check[MAXN]; int subtree[MAXN],k,res=INT_MAX; void DFS_Subtree(int i,int p) { subtree[i]=1; for (auto next : G[i]) { if (next.first!=p && !check[next.first]) { DFS_Subtree(next.first,i); subtree[i]+=subtree[next.first]; } } } int DFS_Centroid(int i,int p,int root) { for (auto next : G[i]) { if (next.first!=p && !check[next.first] && subtree[next.first]>subtree[root]/2) return DFS_Centroid(next.first,i,root); } return i; } map<int,int> cur; void DFS_Paths(int i,int p,int d,int cnt) { if (d>k) return; cur[d]=(!cur[d])?cnt : min(cnt,cur[d]); for (auto next : G[i]) { if (next.first!=p) DFS_Paths(next.first,i,d+next.second,cnt+1); } } void Solve(int i) { DFS_Subtree(i,i); int c=DFS_Centroid(i,i,i); check[c]=true; map<int,int> ans; for (auto next : G[c]) { cur.clear(); DFS_Paths(next.first,c,next.second,1); for (auto i : cur) { if (!ans[k-i.first]) continue; res=min(res,ans[k-i.first]+i.second); } for (auto i : cur) ans[i.first]=(!ans[i.first])?i.second : min(ans[i.first],i.second); } for (auto next : G[c]) { if (!check[next.first]) Solve(next.first); } } int best_path(int N, int K, int H[][2], int L[]) { k=K; for (int i=0;i<N-1;i++) { G[H[i][0]].push_back({H[i][1],L[i]}); G[H[i][1]].push_back({H[i][0],L[i]}); } Solve(0); return (res==INT_MAX?-1 : res); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...