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;
#define pb push_back
#define ff first
#define ll long long
#define ss second
const int M=2e5+5;
ll ans=INT_MAX;
vector<pair<ll,ll>>v[M];
bool vis[M];
ll Z;
vector<ll> fun(ll a){
vis[a]=1;
vector<ll>dp(150);
for(ll i=0;i<=Z;i++)dp[i]=INT_MAX;
dp[0]=0;
for(auto p:v[a]){
ll b=p.ff;
ll c=p.ss;
if(vis[b]==0){
vector<ll>vc=fun(b);
for(ll i=0;i<=Z;i++){
ans=min(ans,dp[i]+vc[Z-i]+2);
}
for(int i=0;i<=Z-c;i++){
dp[i+c]=min(dp[i+c],vc[i]+1);
}
}
}
ans=min(ans,dp[Z]);
return dp;
}
int best_path(int N, int K, int H[][2], int L[]){
Z=K;
for(int i=0;i<N-1;i++){
int a=H[i][0];
int b=H[i][1];
int c=L[i];
v[a].pb({b,c});
v[b].pb({a,c});
}
fun(0);
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... |