#include <bits/stdc++.h>
using namespace std;
const int Q = 1 << 18;
void Graham(vector<pair<long long, long long>>& a) {
  sort(a.begin(), a.end());
  static pair<long long, long long> st[8000000];
  int tp = 0;
  for (int i = 0; i < (int)a.size(); i++) {
    while (tp && a[i].second >= st[tp].second) --tp;
    while (tp > 1) {
      long long t2 =
          (st[tp].second - a[i].second) / (a[i].first - st[tp].first);
      long long t1 = (st[tp - 1].second - st[tp].second + st[tp].first -
                      st[tp - 1].first - 1) /
                     (st[tp].first - st[tp - 1].first);
      if (t1 <= t2) break;
      --tp;
    }
    st[++tp] = a[i];
  }
  a.resize(tp);
  for (int i = 0; i < tp; i++) a[i] = st[i + 1];
}
int las[Q], e[Q << 1], nn[Q << 1], dt[Q], va[Q], vb[Q], inc = 1;
void iNS(int x, int y) {
  e[++inc] = y;
  nn[inc] = las[x];
  las[x] = inc;
}
void ins(int x, int y, int a, int b) {
  iNS(x, y), iNS(y, x), va[inc >> 1] = a, vb[inc >> 1] = b;
}
int si[Q];
void dfs(int x, int last, long long sa, long long sb,
         vector<pair<long long, long long>>& p) {
  si[x] = 1;
  p.push_back(make_pair(sa, sb));
  for (int t = las[x]; t; t = nn[t]) {
    int y = e[t];
    if (y == last || dt[t >> 1]) continue;
    dfs(y, x, sa + va[t >> 1], sb + vb[t >> 1], p);
    si[x] += si[y];
  }
}
int p1, p2, tt, mn;
void Gra(int x, int last, int sizz) {
  si[x] = 1;
  for (int t = las[x]; t; t = nn[t]) {
    int y = e[t];
    if (dt[t >> 1] || y == last) continue;
    Gra(y, x, sizz);
    si[x] += si[y];
    int va = max(sizz - si[y], si[y]);
    if (va < mn) mn = va, p1 = y, p2 = x, tt = t >> 1;
  }
}
vector<pair<long long, long long>> ta, tb, fin;
vector<pair<double, pair<long long, long long>>> cc;
void Mix() {
  Graham(ta), Graham(tb);
  cc.clear();
  for (int i = 1; i < (int)ta.size(); i++) {
    pair<double, pair<long long, long long>> c;
    c.second = make_pair(ta[i].first - ta[i - 1].first,
                         ta[i].second - ta[i - 1].second);
    c.first = 1.0l * (-c.second.second) / c.second.first;
    cc.push_back(c);
  }
  for (int i = 1; i < (int)tb.size(); i++) {
    pair<double, pair<long long, long long>> c;
    c.second = make_pair(tb[i].first - tb[i - 1].first,
                         tb[i].second - tb[i - 1].second);
    c.first = 1.0l * (-c.second.second) / c.second.first;
    cc.push_back(c);
  }
  sort(cc.begin(), cc.end());
  long long p1 = ta[0].first + tb[0].first, p2 = ta[0].second + tb[0].second;
  fin.push_back(make_pair(p1, p2));
  for (auto o : cc)
    p1 += o.second.first, p2 += o.second.second,
        fin.push_back(make_pair(p1, p2));
}
void DC(int x, int sizz) {
  if (sizz == 1) return;
  mn = 1e9, Gra(x, 0, sizz);
  dt[tt] = 1;
  ta.clear(), tb.clear();
  dfs(p1, 0, 0, 0, ta), dfs(p2, 0, va[tt], vb[tt], tb);
  Mix();
  int r2 = p2, rs2 = sizz - si[p1];
  DC(p1, si[p1]), DC(r2, rs2);
}
vector<pair<int, pair<int, int>>> g[Q];
queue<pair<int, pair<int, int>>> q;
int tot;
void rdfs(int x, int last) {
  for (auto o : g[x])
    if (o.first != last) rdfs(o.first, x);
  for (auto o : g[x])
    if (o.first != last) q.push(o);
  while (q.size() > 2) {
    auto o = q.front();
    q.pop();
    auto p = q.front();
    q.pop();
    q.push(make_pair(++tot, make_pair(0, 0)));
    ins(tot, o.first, o.second.first, o.second.second);
    ins(tot, p.first, p.second.first, p.second.second);
  }
  while (q.size()) {
    auto o = q.front();
    q.pop();
    ins(x, o.first, o.second.first, o.second.second);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n == 1) {
    for (int i = 0; i < m; i++) printf("0 ");
    return 0;
  }
  tot = n;
  for (int i = 1, x, y, a, b; i < n; i++) {
    scanf("%d%d%d%d", &x, &y, &a, &b);
    g[x].push_back(make_pair(y, make_pair(a, b)));
    g[y].push_back(make_pair(x, make_pair(a, b)));
  }
  rdfs(1, 0);
  DC(1, tot);
  Graham(fin);
  for (int i = 0, pp = 0; i < m; i++) {
    long long now = fin[pp].first * i + fin[pp].second, nxt;
    while (pp < (int)fin.size() - 1 &&
           now < (nxt = fin[pp + 1].first * i + fin[pp + 1].second))
      ++pp, now = nxt;
    printf("%lld ", now);
  }
  return 0;
}
