#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int n,kk,ans,inf=1e7;
int M = 200'010;
vector<vector<pair<int, int>>> g(M);
void dfs(int v, int p, int d, int c) {
if(c==kk) ans = min(ans,d);
for(auto[u,k] : g[v]) {
if(u==p) continue;
dfs(u,v,d+1,c+k);
}
}
int best_path(int N, int K, int H[][2], int L[]) {
n=N; kk=K;
for(ll i=0; i<n-1; ++i) {
ll a = H[i][0];
ll b = H[i][1];
ll c = L[i];
g[a].push_back({b,c});
g[b].push_back({a,c});
}
for(int i=0; i<n; ++i) {
dfs(i,-1, 0,0);
}
if(ans==inf) return -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... |