#include <bits/stdc++.h>
using namespace std;
struct Vector {
  long long x, y;
  Vector(long long a = 0, long long b = 0) { x = a, y = b; }
  Vector operator+(Vector i) { return Vector(x + i.x, y + i.y); }
  Vector operator-(Vector i) { return Vector(x - i.x, y - i.y); }
  long long gval(long long num) { return num * x + y; }
} st[4000007], res[4000007], v1[200007], v2[200007];
long long cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
long long cmp(Vector a, Vector b) {
  return (a.x == b.x) ? a.y < b.y : a.x < b.x;
}
long long gettb(Vector a[], long long& n) {
  long long tp = 0;
  sort(a + 1, a + n + 1, cmp);
  for (long long i = 1; i <= n; i++) {
    while (tp > 1 && cross(st[tp] - st[tp - 1], a[i] - st[tp - 1]) >= 0) tp--;
    st[++tp] = a[i];
  }
  n = tp;
  for (long long i = 1; i <= n; i++) a[i] = st[i];
  return 0;
}
long long n, m, sz[200007], h[200007], to[400007], w1[400007], w2[400007],
    nxt[400007], cnt = 1, tot;
vector<pair<long long, pair<long long, long long> > > e[100007];
bool ck[400007];
long long read() {
  long long num = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = getchar();
  return num;
}
long long add(long long a, long long b,
              pair<long long, long long> c = make_pair(0, 0)) {
  cnt++;
  to[cnt] = b;
  w1[cnt] = c.first;
  w2[cnt] = c.second;
  nxt[cnt] = h[a];
  h[a] = cnt;
  return 0;
}
long long mtree(long long w, long long f) {
  long long lst = w, hv = max(0LL, (long long)e[w].size() - 2);
  for (long long i = (long long)e[w].size() - 1; i >= 0; i--)
    if (e[w][i].first != f) {
      mtree(e[w][i].first, w);
      add(lst, e[w][i].first, e[w][i].second),
          add(e[w][i].first, lst, e[w][i].second);
      if (hv) tot++, add(tot, lst), add(lst, tot), lst = tot, hv--;
    }
  return 0;
}
long long gsize(long long w, long long f) {
  sz[w] = 1;
  for (long long i = h[w]; i; i = nxt[i])
    if (to[i] != f && !ck[i]) {
      gsize(to[i], w);
      sz[w] += sz[to[i]];
    }
  return 0;
}
pair<long long, long long> gzx(long long w, long long f) {
  pair<long long, long long> ret(1e9, 0);
  for (long long i = h[w]; i; i = nxt[i])
    if (to[i] != f && !ck[i])
      ret = min(min(ret, gzx(to[i], w)),
                make_pair(max(sz[to[i]], sz[0] - sz[to[i]]), i));
  return ret;
}
long long dfs(long long w, long long f, long long a, long long b, Vector c[],
              long long& d) {
  bool is = 0;
  for (long long i = h[w]; i; i = nxt[i])
    if (to[i] != f && !ck[i]) {
      dfs(to[i], w, a + w1[i], b + w2[i], c, d);
      is = 1;
    }
  if (!is && (a || b)) c[++d] = Vector(a, b);
  return 0;
}
long long mkfsj(long long a, long long b) {
  long long i = min(a, 1LL), j = min(b, 1LL);
  res[++tot] = v1[i] + v2[j];
  while (i < a && j < b)
    if (cross(v1[i + 1] - v1[i], v2[j + 1] - v2[j]) <= 0)
      i++, res[++tot] = v1[i] + v2[j];
    else
      j++, res[++tot] = v1[i] + v2[j];
  while (i < a) i++, res[++tot] = v1[i] + v2[j];
  while (j < b) j++, res[++tot] = v1[i] + v2[j];
  return 0;
}
long long solve(long long w) {
  gsize(w, 0);
  sz[0] = sz[w];
  long long x = gzx(w, 0).second;
  if (!x) return 0;
  long long a = to[x], b = to[x ^ 1], c1 = 0, c2 = 0;
  ck[x] = ck[x ^ 1] = 1;
  dfs(a, b, w1[x], w2[x], v1, c1);
  dfs(b, a, 0, 0, v2, c2);
  gettb(v1, c1);
  gettb(v2, c2);
  mkfsj(c1, c2);
  solve(a);
  solve(b);
  return 0;
}
signed main() {
  tot = n = read();
  m = read();
  for (long long i = 2; i <= n; i++) {
    long long a = read(), b = read(), c = read(), d = read();
    e[a].push_back(make_pair(b, make_pair(c, d)));
    e[b].push_back(make_pair(a, make_pair(c, d)));
  }
  mtree(1, 0);
  tot = 0;
  solve(1);
  gettb(res, tot);
  long long pos = 1;
  for (long long i = 0; i < m; i++) {
    while (pos < tot && res[pos + 1].gval(i) >= res[pos].gval(i)) pos++;
    printf("%lld\n", res[pos].gval(i));
  }
  return 0;
}
