#include <bits/stdc++.h>
using namespace std;
struct hh {
  int p, w1, w2;
};
int nx[400005], to[400005], hd[400005], w1[400005], w2[400005], us[400005];
int n, m, ls1[400005], ls2[400005], ls3[400005], cnt = 1;
vector<hh> g[400005];
void add(int x, int y, int s1, int s2) {
  nx[++cnt] = hd[x];
  hd[x] = cnt;
  to[cnt] = y;
  w1[cnt] = s1;
  w2[cnt] = s2;
  nx[++cnt] = hd[y];
  hd[y] = cnt;
  to[cnt] = x;
  w1[cnt] = s1;
  w2[cnt] = s2;
}
void rb(int x, int f) {
  int cnt = 0;
  us[x] = 1;
  for (int i = 0; i < (int)g[x].size(); ++i) {
    int v = g[x][i].p;
    if (us[v]) continue;
    ls1[++cnt] = v;
    ls2[cnt] = g[x][i].w1, ls3[cnt] = g[x][i].w2;
  }
  int pr = x, cs = 1;
  while (cs <= cnt) {
    if (cnt - cs + 1 <= 2) {
      for (int i = cs; i <= cnt; ++i) add(pr, ls1[i], ls2[i], ls3[i]);
      break;
    }
    ++n;
    add(pr, n, 0, 0);
    add(pr, ls1[cs], ls2[cs], ls3[cs]);
    ++cs;
    pr = n;
  }
  for (int i = hd[x]; i; i = nx[i]) {
    int v = to[i];
    if (v == f) continue;
    rb(v, x);
  }
}
int sl, mk[400005], mx, id, sz[400005];
void calc1(int x, int f) {
  sl++;
  sz[x] = 1;
  for (int i = hd[x]; i; i = nx[i])
    if (!mk[i >> 1]) {
      int v = to[i];
      if (v == f) continue;
      calc1(v, x);
      sz[x] += sz[v];
    }
}
void calc2(int x, int f) {
  for (int i = hd[x]; i; i = nx[i])
    if (!mk[i >> 1]) {
      int v = to[i];
      if (v == f) continue;
      calc2(v, x);
      if (max(sl - sz[v], sz[v]) < mx) mx = max(sl - sz[v], sz[v]), id = i >> 1;
    }
}
int calc(int x) {
  sl = 0;
  mx = 1e9;
  id = 0;
  calc1(x, 0);
  calc2(x, 0);
  return id;
}
struct h {
  long long x, y;
  bool operator<(h a) const { return x < a.x; }
  h operator+(h a) { return (h){x + a.x, y + a.y}; }
  h operator-(h a) { return (h){x - a.x, y - a.y}; }
} sk1[400005], sk2[400005];
void solve2(int x, int f, h *sk, int &cnt, long long p1, long long p2) {
  sk[++cnt] = (h){p1, p2};
  for (int i = hd[x]; i; i = nx[i])
    if (!mk[i >> 1]) {
      int v = to[i];
      if (v == f) continue;
      solve2(v, x, sk, cnt, p1 + w1[i], p2 + w2[i]);
    }
}
void solve1(int x, h *sk, int &cnt) {
  solve2(x, 0, sk, cnt, 0, 0);
  sort(sk + 1, sk + cnt + 1);
  int r = 0;
  for (int i = 1; i <= cnt; ++i) {
    while (r && sk[r].x == sk[i].x && sk[r].y <= sk[i].y) --r;
    if (!r || sk[r].x != sk[i].x) sk[++r] = sk[i];
  }
  cnt = r;
  r = 0;
  for (int i = 1; i <= cnt; ++i) {
    while (r > 1 && 1.0 * (sk[i].y - sk[r].y) * (sk[r].x - sk[r - 1].x) >=
                        1.0 * (sk[r].y - sk[r - 1].y) * (sk[i].x - sk[r].x))
      --r;
    sk[++r] = sk[i];
  }
  cnt = r;
}
h ls[400005], ac[400005 * 20];
int fk = 0;
void merge(h *sk1, int n, h *sk2, int m, int id) {
  int sz = 1;
  ls[1] = sk1[1] + sk2[1];
  int l = 1, r = 1;
  while (l < n && r < m) {
    if (1.0 * (sk1[l + 1].y - sk1[l].y) * (sk2[r + 1].x - sk2[r].x) >=
        1.0 * (sk2[r + 1].y - sk2[r].y) * (sk1[l + 1].x - sk1[l].x))
      ls[sz + 1] = ls[sz] + sk1[l + 1] - sk1[l], ++sz, ++l;
    else
      ls[sz + 1] = ls[sz] + sk2[r + 1] - sk2[r], ++sz, ++r;
  }
  while (l < n) ls[sz + 1] = ls[sz] + sk1[l + 1] - sk1[l], ++sz, ++l;
  while (r < m) ls[sz + 1] = ls[sz] + sk2[r + 1] - sk2[r], ++sz, ++r;
  for (int i = 1; i <= sz; ++i)
    ac[++fk] = ls[i] + (h){w1[id << 1], w2[id << 1]};
}
void solve(int id) {
  if (id == 0) return;
  int x = to[id << 1], y = to[id << 1 | 1];
  mk[id] = 1;
  int cnt1 = 0, cnt2 = 0;
  solve1(x, sk1, cnt1);
  solve1(y, sk2, cnt2);
  merge(sk1, cnt1, sk2, cnt2, id);
  solve(calc(x));
  solve(calc(y));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y, w1, w2; i < n; ++i) {
    scanf("%d%d%d%d", &x, &y, &w1, &w2);
    g[x].push_back((hh){y, w1, w2});
    g[y].push_back((hh){x, w1, w2});
  }
  rb(1, 0);
  solve(calc(1));
  sort(ac + 1, ac + fk + 1);
  int r = 0;
  for (int i = 1; i <= fk; ++i) {
    while (r && ac[r].x == ac[i].x && ac[r].y <= ac[i].y) --r;
    if (!r || ac[r].x != ac[i].x) ac[++r] = ac[i];
  }
  fk = r;
  r = 0;
  for (int i = 1; i <= fk; ++i) {
    while (r > 1 && 1.0 * (ac[i].y - ac[r].y) * (ac[r].x - ac[r - 1].x) >=
                        1.0 * (ac[r].y - ac[r - 1].y) * (ac[i].x - ac[r].x))
      --r;
    ac[++r] = ac[i];
  }
  int l = 1;
  for (int i = 0; i < m; ++i) {
    while (l < r &&
           -1.0 * i * (ac[l + 1].x - ac[l].x) <= 1.0 * (ac[l + 1].y - ac[l].y))
      ++l;
    printf("%lld ", ac[l].x * i + ac[l].y);
  }
}
