#include #include #include using namespace std; #define maxn 100010 int n, kk, med; vector v[maxn], w[maxn]; long long k, paths; int st[maxn], f[maxn]; int df(int nod, int dst, int p) { f[nod]=1; st[++kk]=dst; while(st[kk]-st[p]>med) ++p; paths=paths+kk-p; for(int i=0; i