This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
struct point{
int u,x,y,par;
};
int ans=INT_MAX;
vector<vector<pair<int,int>>>adj(2e5);
void dfs(int j,int score,int level,int par,int K){
if (score>K)return ;
if (score==K){
ans=min(ans,level);
return ;
}
for (auto x:adj[j]){
if (x.first!=par){
dfs(x.first,score+x.second,level+1,j,K);
dfs(x.first,x.second,1,j,K);
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
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]});
}
dfs(0,0,0,-1,K);
if (ans==INT_MAX)return -1;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |