#include <bits/stdc++.h>
const int maxn = 200010;
int n, m;
struct Edge {
  int to, a, b;
  bool d;
  Edge *rev, *next;
  void del() { d = rev->d = 1; }
};
struct Tree {
  Edge E[maxn * 2], *ne, *fir[maxn];
  Tree() { ne = E; }
  void link(int u, int v, int a, int b) {
    *ne = (Edge){v, a, b, 0, ne + 1, fir[u]};
    fir[u] = ne++;
    *ne = (Edge){u, a, b, 0, ne - 1, fir[v]};
    fir[v] = ne++;
  }
} T1, T2;
struct Point {
  long long x, y;
  long long val(long long t) { return t * x + y; }
  bool operator<(const Point& p) const {
    return x < p.x || x == p.x && y < p.y;
  }
  bool operator<=(const Point& p) const { return !(p < *this); }
} P[maxn];
struct Num3 {
  bool s;
  unsigned long long x[3];
  Num3(long long a, long long b) {
    s = 0;
    if (a < 0) s ^= 1, a = -a;
    if (b < 0) s ^= 1, b = -b;
    if (!a || !b) s = 0;
    x[0] = (unsigned long long)(a & ~0u) * (b & ~0u);
    x[1] = (a & ~0u) * (b >> 32) + (a >> 32) * (b & ~0u) + (x[0] >> 32);
    x[2] = (a >> 32) * (b >> 32) + (x[1] >> 32);
    x[0] &= ~0u;
    x[1] &= ~0u;
  }
  bool operator<(const Num3& a) const {
    if (s != a.s) return s;
    if (x[2] != a.x[2]) return s ? x[2] > a.x[2] : x[2] < a.x[2];
    if (x[1] != a.x[1]) return s ? x[1] > a.x[1] : x[1] < a.x[1];
    if (x[0] != a.x[0]) return s ? x[0] > a.x[0] : x[0] < a.x[0];
    return 0;
  }
};
void hull(Point* pl, Point*& pr) {
  Point* tp = pl;
  for (Point* p = pl; p < pr; p++) {
    while (tp > pl + 1 && !(Num3(p->y - tp[-1].y, tp[-1].x - tp[-2].x) <
                            Num3(tp[-1].y - tp[-2].y, p->x - tp[-1].x)))
      tp--;
    *tp++ = *p;
  }
  pr = tp;
}
int tot;
void make(int i) {
  int c = 0, x = i;
  for (Edge* e = T1.fir[i]; e; e = e->next)
    if (!e->d) {
      e->del();
      make(e->to);
      if (c++) T2.link(x, ++tot, 0, 0), x = tot;
      T2.link(x, e->to, e->a, e->b);
    }
}
int Q[maxn], fa[maxn], siz[maxn];
long long A[maxn], B[maxn];
std::vector<Point> solve(int i) {
  int *h = Q, *t = Q;
  std::vector<Point> S;
  fa[*t++ = i] = -1;
  for (; h < t; siz[*h++] = 1)
    for (Edge* e = T2.fir[*h]; e; e = e->next)
      if (!e->d)
        if (e->to != fa[*h]) fa[*t++ = e->to] = *h;
  if (t - Q < 2) return S.push_back((Point){0, 0}), S;
  for (h = t; --h > Q; siz[fa[*h]] += siz[*h])
    (siz[*h] > t - Q - siz[*h] ? siz[*h] : t - Q - siz[*h]) >
            (siz[i] > t - Q - siz[i] ? siz[i] : t - Q - siz[i])
        ? 1
        : i = *h;
  int j = fa[i];
  A[i] = B[i] = 0;
  for (Edge* e = T2.fir[i]; e; e = e->next)
    if (!e->d)
      if (e->to == j) e->del(), A[j] = e->a, B[j] = e->b;
  fa[i] = j;
  fa[j] = i;
  Point *pl[2] = {P}, *pr[2];
  for (int T = 0; T < 2; T++) {
    h = t = Q;
    *t++ = T ? j : i;
    pr[T] = pl[T];
    for (; h < t; h++) {
      bool c = 0;
      for (Edge* e = T2.fir[*h]; e; e = e->next)
        if (!e->d)
          if (e->to != fa[*h])
            c = 1, fa[*t++ = e->to] = *h, A[e->to] = A[*h] + e->a,
            B[e->to] = B[*h] + e->b;
      if (!c) *pr[T]++ = (Point){A[*h], B[*h]};
    }
    std::sort(pl[T], pr[T]);
    hull(pl[T], pr[T]);
    pl[1] = pr[0];
  }
  pr[0]--, pr[1]--;
  while (pl[0] < pr[0] || pl[1] < pr[1]) {
    S.push_back((Point){pl[0]->x + pl[1]->x, pl[0]->y + pl[1]->y});
    if (pl[0] < pr[0] &&
        (pl[1] == pr[1] ||
         Num3(pl[1][1].y - pl[1]->y, pl[0][1].x - pl[0]->x) <
             Num3(pl[0][1].y - pl[0]->y, pl[1][1].x - pl[1]->x)))
      pl[0]++;
    else
      pl[1]++;
  }
  S.push_back((Point){pl[0]->x + pl[1]->x, pl[0]->y + pl[1]->y});
  std::vector<Point> Si = solve(i), Sj = solve(j);
  int k = S.size(), ki = Si.size(), kj = Sj.size();
  Point *ps = P + k + ki + kj, *tp = ps;
  while (k || ki || kj) {
    if (k && (!ki || Si[ki - 1] <= S[k - 1]) && (!kj || Sj[kj - 1] <= S[k - 1]))
      *--tp = S[--k];
    else if (ki && (!k || S[k - 1] < Si[ki - 1]) &&
             (!kj || Sj[kj - 1] <= Si[ki - 1]))
      *--tp = Si[--ki];
    else
      *--tp = Sj[--kj];
  }
  hull(P, ps);
  S.clear();
  for (Point* p = P; p < ps; p++) S.push_back(*p);
  return S;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v, a, b; i < n; i++) {
    scanf("%d%d%d%d", &u, &v, &a, &b);
    T1.link(u, v, a, b);
  }
  tot = n;
  make(1);
  std::vector<Point> v = solve(1);
  int i = 0;
  for (int t = 0; t < m; t++) {
    while (i + 1 < v.size() && v[i + 1].val(t) > v[i].val(t)) i++;
    printf("%lld%c", v[i].val(t), " \n"[t == m - 1]);
  }
}
