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;
int n;
vector<vector<pair<int,int>>>v;
int best_path(int N, int K, int H[][2], int L[]){
n=N;
vector<int>pref(n);
pref[0]=0;
v.resize(n);
for(int i=0;i<n-1;i++){
v[H[i][0]].push_back({H[i][1],L[i]});
v[H[i][1]].push_back({H[i][0],L[i]});
pref[i+1]=pref[i]+L[i];
}
int ans=n;
for(int i=0;i<n-1;i++){
auto pos=lower_bound(pref.begin(),pref.end(),pref[i]+K)-pref.begin();
if(pos!=n && pref[pos]-pref[i]==K) ans=min(ans,(int)pos-i);
}
return (ans==n ? -1 : ans+1);
}
# | 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... |