# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
638125 | Iwanttobreakfree | 경주 (Race) (IOI11_race) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include <vector>
using namespace std;
int best;
void dfs(int a,int par,vector<vector<pair<int,int>>>& g,int cnt,int dist,int k){
if(cnt==k)best=min(best,dist);
for(auto x:g[a]){
if(x.first==par)continue;
dfs(x.first,a,g,cnt+x.second,dist+1,k);
}
}
int best_path(int N, int K, int H[][2], int L[]){
vector<vector<pair<int,int>>> g(N,vector<pair<int,int>>());
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]});
}
best=1e9;
for(int i=0;i<n;i++)dfs(i,i,g,0,0,K);
if(best==1e9)best=-1;
return best;
}