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>> g[1005];
int ans, k;
void dfs(int v, int p = -1, int dep = 0, int len = 0) {
if (len == k) ans = min(ans, dep);
for (auto i: g[v]) {
if (i.first != p)
dfs(i.first, v, dep + 1, len + i.second);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K;
for (int i = 0; i < N; i ++) {
g[H[i][0]].push_back({H[i][1], L[i]});
g[H[i][1]].push_back({H[i][0], L[i]});
}
ans = 1e9;
for (int i = 0; i < N; i ++) {
dfs(i);
}
if (ans == 1e9) ans = -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... |