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> > adj[300000];
void dfs(int v, int d, int length, int par, int& mn, int K)
{
if(length == K)
{
mn = min(mn,d);
}
else if(length > K)
return;
for(int i = 0; i < adj[v].size(); i++)
{
int u = adj[v][i].first;
if(u != par)
dfs(u,d+1,length + adj[v][i].second,v,mn, K);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
for(int i = 0; i < N-1; i++)
{
int v = H[i][0],u = H[i][1],l = L[i];
adj[v].push_back(make_pair(u,l));
adj[u].push_back(make_pair(v,l));
}
int mn = 1e9;
for(int i = 0; i < N; i++)
{
dfs(i,0,0,i,mn,K);
}
if(mn == 1e9)
return -1;
return mn;
}
Compilation message (stderr)
race.cpp: In function 'void dfs(int, int, int, int, int&, int)':
race.cpp:16:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj[v].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... |