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 rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define repd(i, a, b) for(int i = (a); i >= (b); --i)
#define em emplace
#define eb emplace_back
const int M = 1010;
vector<pair<int, int>> adj[M];
int dfs(int x, int p, int rem, int len) {
if(rem == 0) return len;
if(rem < 0) return M;
int ans = M;
for(auto [y, w] : adj[x]) {
if(y == p) continue;
ans = min(ans, dfs(y, x, rem - w, len + 1));
}
return ans;
}
int best_path(int N, int K, int H[][2], int L[])
{
rep(i, 0, N - 2) {
adj[H[i][0] + 1].eb(H[i][1] + 1, L[i]);
adj[H[i][1] + 1].eb(H[i][0] + 1, L[i]);
}
int ans = N;
rep(i, 1, N) {
ans = min(ans, dfs(i, 0, K, 0));
}
return (ans >= N ? -1 : 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... |