#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int best_path(int N, int K, int H[][2], int L[])
{
queue<int> q;
vector<vector<pair<int,int>>> ln(N, vector<pair<int,int>>(0));
vector<vector<int>> dist(N, vector<int>(N,0));
int t = 0, mn = INT_MAX, nodoA, pro;
for (int i = 0; i < N - 1; i++)
{
ln[H[i][0]].pb(mp(H[i][1],L[i]));
ln[H[i][1]].pb(mp(H[i][0],L[i]));
}
for (int i = 0; i < N; i++)
{
nodoA = -1;
q.push(i);
dist[i][0] = 0;
t = 0;
pro=1;
while (q.size())
{
int nodo = q.front();
q.pop();
for (int j = 0; j < ln[nodo].size(); j++)
{
if (ln[nodo][j].first == nodoA)
continue;
q.push(ln[nodo][j].first);
dist[i][ln[nodo][j].first] = dist[i][nodo] + ln[nodo][j].second;
if (dist[i][ln[nodo][j].first] > K)
q.pop();
if (dist[i][ln[nodo][j].first] == K)
{
mn = min(mn, pro);
t = 1;
break;
}
nodoA = nodo;
}
if (t == 1)
{
while (q.size())
{
q.pop();
}
}
pro++;
}
}
return (mn==INT_MAX?-1:mn);
}