#include #define mp make_pair #define f first #define s second typedef long long ll; using namespace std; const int N=1e5+10; const int LogN=20; ll k; int cost[N][LogN], st[N][LogN]; vector > g[N]; int n; void dfs (int v, int prev) { for (auto xt: g[v]) { if (xt.f==prev) continue; cost[xt.f][0]=xt.s; st[xt.f][0]=v; dfs (xt.f, v); } } void init () { for (int d=1;d<19;d++) { for (int i=1;i<=n;i++) { st[i][d]=st[st[i][d-1]][d-1]; cost[i][d]=cost[i][d-1]+cost[st[i][d-1]][d-1]; } } } int climb (int v, ll x) { if (st[v][0]==0 || cost[v][0]>x) return 0; int d=0; while (st[v][d+1]!=0 && cost[v][d+1]<=x) d++; return climb(st[v][d], x-cost[v][d])+(1<=k) { sol=mid; r=mid-1; } else l=mid+1; } printf ("%lld", sol); return 0; }