#include <bits/stdc++.h>
using namespace std;
struct node {
  int to, next, a, b;
} q[405000], nq[405000];
const long double eps = 1e-7;
struct Point {
  long long x, y;
  Point(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}
  Point operator+(const Point &B) const { return Point(x + B.x, y + B.y); }
  Point operator-(const Point &B) const { return Point(x - B.x, y - B.y); }
  bool operator<(const Point &B) const { return x == B.x ? y < B.y : x < B.x; }
  long double operator^(const Point &B) const {
    return (long double)x * B.y - (long double)y * B.x;
  }
} h1[405000], h2[405000], cov1[200400], cov2[200400], HH[200400 * 32],
    mkf[405000], ans[200400 * 32];
int head[200400], ss, a[200400], b[200400], cc, nh[200400],
    ns = 1, sz[200400], all, Rt, m, RS, c1, c2, t1, t2, ccc;
bool vis[200400];
void addedge(int x, int y, int a, int b) {
  q[++ss] = (node){y, head[x], a, b};
  head[x] = ss;
  q[++ss] = (node){x, head[y], a, b};
  head[y] = ss;
}
void addnew(int x, int y, int a, int b) {
  nq[++ns] = (node){y, nh[x], a, b};
  nh[x] = ns;
  nq[++ns] = (node){x, nh[y], a, b};
  nh[y] = ns;
}
void rebuild(int i, int fa) {
  int la = 0;
  for (int j = head[i]; j; j = q[j].next)
    if (q[j].to ^ fa) {
      int t = q[j].to;
      rebuild(t, i);
      if (!la)
        addnew(la = i, t, q[j].a, q[j].b);
      else {
        addnew(la, ++cc, 0, 0);
        addnew(cc, t, q[j].a, q[j].b);
        la = cc;
      }
    }
}
void FRT(int i, int fa) {
  sz[i] = 1;
  for (int j = nh[i]; j; j = nq[j].next)
    if (!vis[j >> 1] && nq[j].to ^ fa) {
      int t = nq[j].to;
      FRT(t, i);
      sz[i] += sz[t];
      if (max(sz[t], all - sz[t]) < RS) RS = max(sz[t], all - sz[t]), Rt = j;
    }
}
void push(Point *cov, int &top, Point A) {
  while (top && ((A - cov[top]) ^ (cov[top] - cov[top - 1])) < eps) --top;
  cov[++top] = A;
}
void dfs(int i, int fa, Point *H, int &c, Point nw) {
  H[++c] = nw;
  for (int j = nh[i]; j; j = nq[j].next)
    if (nq[j].to ^ fa && !vis[j >> 1])
      dfs(nq[j].to, i, H, c, Point(nw.x + nq[j].a, nw.y + nq[j].b));
}
void solve(int x) {
  if (!x) return;
  vis[x >> 1] = true;
  c1 = c2 = t1 = t2 = 0;
  dfs(nq[x].to, nq[x ^ 1].to, h1, c1, Point());
  dfs(nq[x ^ 1].to, nq[x].to, h2, c2, Point(nq[x].a, nq[x].b));
  sort(h1 + 1, h1 + 1 + c1);
  sort(h2 + 1, h2 + 1 + c2);
  cov2[0] = Point(nq[x].a, nq[x].b);
  for (int i = 2; i <= c1; ++i) push(cov1, t1, h1[i]);
  for (int i = 2; i <= c2; ++i) push(cov2, t2, h2[i]);
  for (int i = t1; i; --i) cov1[i] = cov1[i] - cov1[i - 1];
  for (int i = t2; i; --i) cov2[i] = cov2[i] - cov2[i - 1];
  int i1 = 1, i2 = 1, k = 0;
  mkf[0] = cov1[0] + cov2[0];
  while (i1 <= t1 && i2 <= t2)
    ++k, mkf[k] = mkf[k - 1] +
                  ((cov1[i1] ^ cov2[i2]) < eps ? cov1[i1++] : cov2[i2++]);
  while (i1 <= t1) ++k, mkf[k] = mkf[k - 1] + cov1[i1++];
  while (i2 <= t2) ++k, mkf[k] = mkf[k - 1] + cov2[i2++];
  for (int i = 0; i <= k; ++i) HH[++ccc] = mkf[i];
  int tmp = all;
  if (sz[nq[x].to] > sz[nq[x].to]) x ^= 1;
  all = sz[nq[x].to];
  RS = 0x3f3f3f3f;
  Rt = 0;
  FRT(nq[x].to, nq[x ^ 1].to);
  solve(Rt);
  all = tmp - sz[nq[x].to];
  RS = 0x3f3f3f3f;
  Rt = 0;
  FRT(nq[x ^ 1].to, nq[x].to);
  solve(Rt);
}
inline long long fx(Point A, int k) { return A.x * k + A.y; }
inline int read() {
  int n = 0;
  char a;
  bool z = false;
  while (a = getchar()) {
    if (a > '9' || a < '0')
      if (z)
        break;
      else
        continue;
    if (!z) z = true;
    n = (n << 1) + (n << 3) + (a ^ 48);
  }
  return n;
}
int main() {
  int n = read(), a, b, x, y, t = 0;
  cc = n;
  m = read();
  for (int i = 1; i < n; ++i) {
    x = read();
    y = read();
    a = read();
    b = read();
    addedge(x, y, a, b);
  }
  rebuild(1, 1);
  all = cc;
  RS = 0x3f3f3f3f;
  FRT(1, 0);
  solve(Rt);
  sort(HH + 1, HH + 1 + ccc);
  for (int i = 1; i <= ccc; ++i) push(ans, t, HH[i]);
  for (int i = 0, j = 0; i < m; ++i) {
    while (j < t && fx(ans[j], i) <= fx(ans[j + 1], i)) ++j;
    printf("%lld ", fx(ans[j], i));
  }
  return 0;
}
