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;
vector<pair<int,int>>g[200005];
int k,i,inf=2e9,ans=inf;
void dfs(int v,int p,int depth,int val){
if(val==k)ans=min(ans,depth);
if(val>=k)return;
for(auto to:g[v])if(to.first!=p)dfs(to.first,v,depth+1,val+to.second);
}
int best_path(int n,int K,int h[][2],int l[]){
k=K;
for(i=0;i<k;i++){
g[h[i][1]].push_back({h[i][0],l[i]});
g[h[i][0]].push_back({h[i][1],l[i]});
}
for(i=0;i<n;i++)dfs(i,i,0,0);
if(ans==inf)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... |