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;
using ll = long long int;
vector<pair<int,ll>> g[100100];
ll level[100100], dist[100100];
ll k, ans = -1;
void dfs(int node, int prev = -1){
if(dist[node] == k){
ans = ans == -1 ? level[node] : min(ans, level[node]);
}
for(auto i : g[node]){
if(i.first != prev){
level[i.first] = level[node] + 1;
dist[i.first] = dist[node] + i.second;
dfs(i.first, node);
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K;
for(int i = 0; i < N - 1; ++i){
g[H[i][0]].push_back({H[i][1], L[i]});
g[H[i][1]].push_back({H[i][0], L[i]});
}
for(int i = 0; i < N; ++i){
fill(level, level + N, 0);
fill(dist, dist + N, 0);
dfs(i);
}
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... |