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 "bits/stdc++.h"
using namespace std;
const int N = 1e3 + 5;
vector<pair<int, int>> adj[N];
int mn = N, K;
int dfs(int x, int pr, int gal, int edge){
if(!(gal^K))
return edge;
if(gal < 0)
return N;
for(auto &i : adj[x])
if(i.first != x)
mn = min(mn, dfs(i.first, x, gal + i.second, edge + 1));
return mn;
}
int best_path(int n, int k, int H[][2], int L[]){
K = k;
for(int i = 0; i < n; ++i){
int a = H[i][0], b = H[i][1];
adj[a].push_back({b, L[i]});
adj[b].push_back({a, L[i]});
}
int answer = INT_MAX;
for(int i = 0; i < n; ++i)
answer = min(answer, dfs(i, -1, 0, 0));
return (answer >= N ? -1 : answer);
}
# | 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... |