#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > gph[50001];
int mxd = -0x80000000, mn = 0x7fffffff;
bool cmp(vector<int> a, vector<int> b) {
if (a[0] == b[0])
return a[1] < b[1];
return a[0] > b[0];
}
vector<int> f(int now, int prv) {
if (gph[now].size() == 1)
return { 0, 0 };
if (gph[now].size() == 2 && prv != -1) {
vector<int> ret;
if (gph[now][0].first != prv) {
ret = f(gph[now][0].first, now);
ret[0]++;
ret[1] += gph[now][0].second;
}
else {
ret = f(gph[now][1].first, now);
ret[0]++;
ret[1] += gph[now][1].second;
}
return ret;
}
vector<vector<int> > v;
for (pair<int, int> t : gph[now])
if (t.first != prv) {
vector<int> temp = f(t.first, now);
temp[0]++;
temp[1] += t.second;
v.push_back(temp);
}
sort(v.begin(), v.end(), cmp);
if (v[0][0] + v[1][0] > mxd) {
mxd = v[0][0] + v[1][0];
mn = v[0][1] + v[1][1];
}
else if (v[0][0] + v[1][0] == mxd)
if (mn > v[0][1] + v[1][1])
mn = v[0][1] + v[1][1];
return v[0];
}
int main() {
int n, t, i, u, v, w;
scanf("%d %d", &n, &t);
for (i = 1;i < n;++i) {
scanf("%d %d %d", &u, &v, &w);
gph[u].push_back({ v, w });
gph[v].push_back({ u, w });
}
for (i = 1;i <= n;++i)
if (gph[i].size() > 1) {
f(i, -1);
break;
}
printf("%d", n == 2 ? gph[1][0].second / t + (gph[1][0].second % t ? 1 : 0) : mn / t + (mn % t ? 1 : 0));
return 0;
}