#include <bits/stdc++.h>
using namespace std;
int n, m, vis[200010 * 2], tot, siz[200010], mp, S, mn;
struct edge {
  int u, v, a, b;
};
struct line {
  long long k, b;
};
vector<line> l[2], q[2], t;
vector<edge> e, tv[200010];
vector<int> v[200010];
void dfs(int p, int f) {
  int fs = 1, now = p;
  for (edge& i : tv[p])
    if (i.v != f) {
      if (!fs) {
        ++tot;
        e.insert(e.end(), {{now, tot, 0, 0}, {tot, now, 0, 0}});
        v[now].push_back(e.size() - 2);
        v[now = tot].push_back(e.size() - 1);
      }
      e.insert(e.end(), {{now, i.v, i.a, i.b}, {i.v, now, i.a, i.b}});
      v[now].push_back(e.size() - 2), v[i.v].push_back(e.size() - 1);
      dfs(i.v, p);
      fs = 0;
    }
}
void getrt(int p, int f) {
  int mx = 0;
  siz[p] = 1;
  for (int i : v[p])
    if (!vis[i] && e[i].v != f)
      getrt(e[i].v, p), siz[p] += siz[e[i].v], mx = max(mx, siz[e[i].v]);
  mx = max(mx, S - siz[p]);
  if (mx < mn) mn = mx, mp = p;
}
void dfs1(int p, int f, int tp, long long a = 0, long long b = 0) {
  siz[p] = 1;
  l[tp].push_back({a, b});
  for (int i : v[p])
    if (!vis[i] && e[i].v != f)
      dfs1(e[i].v, p, tp, a + e[i].a, b + e[i].b), siz[p] += siz[e[i].v];
}
int chk(line& x, line& y, long long k, long long b) {
  return 1.l * (b - x.b) / (x.k - k) <= 1.l * (y.b - x.b) / (x.k - y.k);
}
void solve(vector<line>& a, vector<line>& o) {
  o.clear();
  sort(a.begin(), a.end(), [](line a, line b) { return a.k < b.k; });
  for (auto& [k, b] : a) {
    while (o.size() > 1 && chk(o.end()[-2], o.back(), k, b)) o.pop_back();
    o.push_back({k, b});
    if (o.size() > 1 && o.end()[-2].k == k) {
      b = max(b, o.end()[-2].b);
      o.pop_back(), o.pop_back(), o.push_back({k, b});
    }
  }
}
void work(int p) {
  edge now;
  int pp, f = 1;
  for (int i : v[p])
    if (!vis[i]) {
      f = 0;
      now = e[i];
      vis[i] = vis[i ^ 1] = 1;
      break;
    }
  if (f) return;
  l[0].clear(), l[1].clear();
  dfs1(p, 0, 0), dfs1(pp = now.v, 0, 1);
  for (int i : {0, 1}) solve(l[i], q[i]);
  int s0 = q[0].size(), s1 = q[1].size();
  for (int i = 0, j = 0; i < s0 && j < s1;) {
    t.push_back({q[0][i].k + q[1][j].k + now.a, q[0][i].b + q[1][j].b + now.b});
    (i >= s0 - 1 || j < s1 - 1 && 1.l * (q[0][i + 1].b - q[0][i].b) /
                                          (q[0][i].k - q[0][i + 1].k) >
                                      1.l * (q[1][j + 1].b - q[1][j].b) /
                                          (q[1][j].k - q[1][j + 1].k)
         ? j
         : i)++;
  }
  for (int i : {p, pp}) S = siz[i], mn = 1e9, getrt(i, 0), work(mp);
}
int main() {
  scanf("%d%d", &n, &m);
  if (n == 1) {
    for (int i = 1; i <= m; i++) printf("0%c", i == m ? '\n' : ' ');
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int x, y, a, b;
    scanf("%d%d%d%d", &x, &y, &a, &b);
    tv[x].push_back({x, y, a, b});
    tv[y].push_back({y, x, a, b});
  }
  tot = n, dfs(1, 0), n = tot;
  S = n, mn = 1e9;
  getrt(1, 0);
  work(mp);
  solve(t, q[0]);
  for (int i = 0, j = 0; i < m; i++) {
    while (j < (int)q[0].size() - 1 &&
           i * q[0][j].k + q[0][j].b < i * q[0][j + 1].k + q[0][j + 1].b)
      j++;
    printf("%lld%c", i * q[0][j].k + q[0][j].b, i == m - 1 ? '\n' : ' ');
  }
  return 0;
}
