#include <bits/stdc++.h>
using namespace std;
char cb[1 << 16], *cs = cb, *ct = cb;
template <class T>
void read(T &res) {
  char ch;
  for (; !isdigit(
           ch = (cs == ct && (ct = (cs = cb) + fread(cb, 1, 1 << 16, stdin),
                             cs == ct)
                     ? 0
                     : *cs++));)
    ;
  for (res = ch - '0';
       isdigit(ch = (cs == ct && (ct = (cs = cb) + fread(cb, 1, 1 << 16, stdin),
                                 cs == ct)
                         ? 0
                         : *cs++));
       res = res * 10 + ch - '0')
    ;
}
int n, m;
struct Pt {
  long long x, y;
  double ag;
  Pt(const long long &x = 0, const long long &y = 0) : x(x), y(y) {}
  Pt operator+(const Pt &B) const { return Pt(x + B.x, y + B.y); }
  Pt operator-(const Pt &B) const { return Pt(x - B.x, y - B.y); }
  long long operator*(const Pt &B) const { return x * B.y - y * B.x; }
  bool operator<(const Pt &B) const { return y == B.y ? x < B.x : y > B.y; }
  void ang() { ag = atan2(y, x); }
} cst[400005 << 1];
vector<Pt> H;
int info[400005], Prev[400005 << 1], to[400005 << 1], vis[400005 << 1],
    sz[400005], cnt_e = 1, tot;
void Node(int u, int v, Pt C) {
  Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v, cst[cnt_e] = C;
}
vector<pair<int, Pt> > G[400005];
void dfs0(int u, int ff) {
  int p = 0;
  for (auto v : G[u])
    if (v.first != ff) {
      if (!p)
        Node(u, v.first, v.second), Node(v.first, u, v.second), p = u;
      else {
        ++tot;
        Node(tot, p, Pt()), Node(p, tot, Pt());
        p = tot;
        Node(p, v.first, v.second), Node(v.first, p, v.second);
      }
      dfs0(v.first, u);
    }
}
void dfs1(int u, int ff, int tsz, int &mn, int &rt) {
  sz[u] = 1;
  for (int i = info[u], v; i; i = Prev[i])
    if (v = to[i], !vis[i] && v != ff) {
      dfs1(v, u, tsz, mn, rt);
      if (max(sz[v], tsz - sz[v]) < mn) mn = max(sz[v], tsz - sz[v]), rt = i;
      sz[u] += sz[v];
    }
}
int Gert(int u, int tsz) {
  int mn = 0x3f3f3f3f, rt = -1;
  dfs1(u, 0, tsz, mn, rt);
  return rt;
}
void ser(int u, int ff, Pt C, vector<Pt> &P) {
  P.push_back(C);
  sz[u] = 1;
  for (int i = info[u], v; i; i = Prev[i])
    if ((v = to[i]) != ff && !vis[i]) ser(v, u, C + cst[i], P), sz[u] += sz[v];
}
vector<Pt> Convex(vector<Pt> P) {
  sort(P.begin(), P.end());
  vector<Pt> R;
  for (Pt u : P) {
    for (; R.size() >= 2 &&
           (u - R[R.size() - 2]) * (R.back() - R[R.size() - 2]) <= 0;
         R.pop_back())
      ;
    R.push_back(u);
  }
  return R;
}
bool cmp(const Pt &u, const Pt &v) { return u.ag < v.ag; }
vector<Pt> Minkowski(const vector<Pt> &P, const vector<Pt> &Q) {
  vector<Pt> R, sp, sq;
  for (int i = (1), LIM = (P.size() - 1); i <= LIM; i++) {
    sp.push_back(P[i] - P[i - 1]);
    if (sp.back().x || sp.back().y)
      sp.back().ang();
    else
      sp.pop_back();
  }
  for (int i = (1), LIM = (Q.size() - 1); i <= LIM; i++) {
    sq.push_back(Q[i] - Q[i - 1]);
    if (sq.back().x || sq.back().y)
      sq.back().ang();
    else
      sq.pop_back();
  }
  R.push_back(P[0] + Q[0]);
  for (int i = 0, j = 0; i < sp.size() || j < sq.size();)
    if (j >= sq.size() || (i < sp.size() && sp[i].ag > sq[j].ag))
      R.push_back(R.back() + sp[i++]);
    else
      R.push_back(R.back() + sq[j++]);
  return R;
}
void Solve(int u) {
  if (u == -1) return;
  vector<Pt> P, Q;
  vis[u] = vis[u ^ 1] = 1;
  ser(to[u], to[u ^ 1], cst[u], P);
  ser(to[u ^ 1], to[u], Pt(0, 0), Q);
  P = Convex(P), Q = Convex(Q);
  P = Minkowski(P, Q);
  for (Pt v : P) H.push_back(v);
  Solve(Gert(to[u], sz[to[u]]));
  Solve(Gert(to[u ^ 1], sz[to[u ^ 1]]));
}
int main() {
  read(n), read(m);
  for (int i = (1), LIM = (n - 1); i <= LIM; i++) {
    int u, v;
    Pt C;
    read(u), read(v), read(C.x), read(C.y);
    G[u].push_back(make_pair(v, C)), G[v].push_back(make_pair(u, C));
  }
  tot = n;
  dfs0(1, 0);
  Solve(Gert(1, tot));
  H = Convex(H);
  int j = 0;
  for (int i = (0), LIM = (m - 1); i <= LIM; i++) {
    for (; j < (int)H.size() - 1 && (H[j + 1] - H[j]) * Pt(1, -i) <= 0; j++)
      ;
    printf("%lld%c", j < H.size() ? H[j].y + H[j].x * i : 0, " \n"[i == m - 1]);
  }
}
