This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Coded by Chirath Nirodha
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define P push
typedef long long ll;
map<ll,ll> mp[1000000];
vector<pair<ll,ll> > adj[1000000];
ll ans=10000010;
ll kk;
void dfs(ll x,ll y){
for(ll i=0;i<adj[y].size();i++){
ll to=adj[y][i].F;
ll len=adj[y][i].S;
if(to==x)continue;
dfs(y,to);
for(auto itr=mp[to].begin();itr!=mp[to].end();itr++){
pair<ll,ll> p=*itr;
if(p.F+len==kk)ans=min(ans,p.S+1);
if(mp[y][kk-(p.F+len)]!=0)ans=min(ans,p.S+1+mp[y][kk-(p.F+len)]);
}
mp[y][len]=1;
for(auto itr=mp[to].begin();itr!=mp[to].end();itr++){
pair<ll,ll> p=*itr;
if(mp[y][p.F+len]==0)mp[y][p.F+len]=p.S+1;
else mp[y][p.F+len]=min(mp[y][p.F+len],p.S+1);
}
mp[to].clear();
}
}
int best_path(int n, int K, int h[][2], int l[]){
kk=K;
for(ll i=0;i<n-1;i++){
adj[h[i][0]].PB(MP(h[i][1],(long long) l[i]));
adj[h[i][1]].PB(MP(h[i][0],(long long) l[i]));
}
dfs(0,0);
if(ans>=n)return -1;
return ans;
}
Compilation message (stderr)
race.cpp: In function 'void dfs(ll, ll)':
race.cpp:17:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(ll i=0;i<adj[y].size();i++){
| ~^~~~~~~~~~~~~~
# | 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... |