#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50, inf = 1e9;
int gi() {
  char ch = getchar();
  int x = 0, q = 0;
  while (ch < '0' || ch > '9') q = ch == '-' ? 1 : q, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return q ? -x : x;
}
namespace tmp {
int head[N], nn[N][2], a[N], b[N], cnt;
void link(int x, int y, int w, int v) {
  nn[++cnt][1] = y, nn[cnt][0] = head[x], a[cnt] = w, b[cnt] = v, head[x] = cnt;
  nn[++cnt][1] = x, nn[cnt][0] = head[y], a[cnt] = w, b[cnt] = v, head[y] = cnt;
  return;
}
}  // namespace tmp
struct D {
  long long x, y;
  D() {}
  D(long long _x, long long _y) {
    x = _x, y = _y;
    return;
  }
  D operator+(const D &v) const { return D(x + v.x, y + v.y); }
  D operator-(const D &v) const { return D(x - v.x, y - v.y); }
  long long operator*(const D &v) const { return x * v.y - y * v.x; }
  long long Val(int k) { return k * x + y; }
  bool operator<(const D &v) const {
    if (x != v.x) return x < v.x;
    return y > v.y;
  }
} ans[N * 50], A[N], B[N];
int top, la, lb;
int vis[N * 2], head[N], nn[N * 2][2], a[N * 2], b[N * 2], siz[N], cnt = 1, id;
int st[N], tot, Mx, rt1, rt2, sz;
void link(int x, int y, int w, int v) {
  nn[++cnt][1] = y, nn[cnt][0] = head[x], a[cnt] = w, b[cnt] = v, head[x] = cnt;
  nn[++cnt][1] = x, nn[cnt][0] = head[y], a[cnt] = w, b[cnt] = v, head[y] = cnt;
  return;
}
void rebuild(int x, int fa) {
  for (int i = tmp::head[x], y; i; i = tmp::nn[i][0])
    if ((y = tmp::nn[i][1]) != fa) rebuild(y, x);
  tot = 0;
  for (int i = tmp::head[x]; i; i = tmp::nn[i][0])
    if (tmp::nn[i][1] != fa) st[++tot] = i;
  if (!tot) return;
  link(x, tmp::nn[st[1]][1], tmp::a[st[1]], tmp::b[st[1]]);
  for (int i = 2, y = x; i <= tot; ++i, y = id) {
    ++id, link(id, y, 0, 0);
    link(id, tmp::nn[st[i]][1], tmp::a[st[i]], tmp::b[st[i]]);
  }
  return;
}
void dfsrt(int x, int fa) {
  siz[x] = 1;
  for (int i = head[x], y; i; i = nn[i][0])
    if (!vis[i] && (y = nn[i][1]) != fa) dfsrt(y, x), siz[x] += siz[y];
  if (Mx > (siz[x] > sz - siz[x] ? siz[x] : sz - siz[x]))
    Mx = (siz[x] > sz - siz[x] ? siz[x] : sz - siz[x]), rt1 = x, rt2 = fa;
  return;
}
void calc(int x, int fa, D s, D *val, int &num) {
  val[++num] = s;
  for (int i = head[x], y; i; i = nn[i][0])
    if (!vis[i] && (y = nn[i][1]) != fa)
      calc(y, x, s + D(a[i], b[i]), val, num);
  return;
}
void build(D *val, int &num) {
  sort(val + 1, val + num + 1);
  st[tot = 1] = 1;
  for (int i = 2; i <= num; ++i)
    if (val[i].x != val[st[tot]].x) {
      while (tot > 1 &&
             (val[i] - val[st[tot - 1]]) * (val[st[tot]] - val[st[tot - 1]]) <=
                 0)
        --tot;
      st[++tot] = i;
    }
  num = tot;
  for (int i = 1; i <= tot; ++i) val[i] = val[st[i]];
  return;
}
void dfs(int x, int S) {
  if (S == 1) return;
  Mx = inf, sz = S, dfsrt(x, 0);
  int i, j;
  for (i = head[rt1]; i; i = nn[i][0])
    if (nn[i][1] == rt2) break;
  vis[i] = vis[i ^ 1] = 1;
  la = 0, calc(rt1, 0, D(a[i], b[i]), A, la), build(A, la);
  lb = 0, calc(rt2, 0, D(0, 0), B, lb), build(B, lb);
  i = 1, j = 1;
  ans[++top] = A[1] + B[1];
  while (i + j < la + lb)
    if (j == lb || (i < la && (A[i + 1] - A[i]) * (B[j + 1] - B[j]) <= 0))
      ans[++top] = A[++i] + B[j];
    else
      ans[++top] = A[i] + B[++j];
  int ls = rt1, rs = rt2;
  dfs(rs, S - siz[ls]), dfs(ls, siz[ls]);
  return;
}
int main() {
  int n = gi(), m = gi(), x, y, w, v;
  for (int i = 2; i <= n; ++i)
    x = gi(), y = gi(), w = gi(), v = gi(), tmp::link(x, y, w, v);
  id = n, rebuild(1, 0);
  dfs(1, id);
  build(ans, top);
  int k = 1;
  for (int i = 0; i < m; ++i) {
    while (k < top && ans[k + 1].Val(i) > ans[k].Val(i)) ++k;
    printf("%I64d ", ans[k].Val(i));
  }
  return 0;
}
