#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10, M = 1e6 + 10;
int n, m, mxsiz, id, top, idx;
int to[N << 1], nxt[N << 1], lnk[N], cnt = 1, mark[N << 1];
int siz[N];
vector<int> _to[N];
struct P {
  long long x, y;
  friend P operator+(P a, P b) { return (P){a.x + b.x, a.y + b.y}; }
  friend P operator-(P a, P b) { return (P){a.x - b.x, a.y - b.y}; }
  friend double operator*(P a, P b) {
    return (double)a.x * b.y - (double)a.y * b.x;
  }
  friend bool operator<(P a, P b) { return a.x == b.x ? a.y > b.y : a.x < b.x; }
} val[N << 1], stk[N];
vector<P> q1, q2, tmp, ans, _val[N];
void adde(int x, int y, P p) {
  to[++cnt] = y, nxt[cnt] = lnk[x], lnk[x] = cnt, val[cnt] = p;
}
void predfs(int x, int fa) {
  for (int i = lnk[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa) continue;
    predfs(y, x);
    _to[x].push_back(y), _val[x].push_back(val[i]);
  }
}
void rebuild(int x, int fa) {
  int lst = 0;
  for (int i = 0; i < _to[x].size(); i++) {
    int y = _to[x][i];
    P w = _val[x][i];
    if (y == fa) continue;
    if (!lst) {
      adde(x, y, w), adde(y, x, w);
      lst = x;
    } else {
      int k = ++idx;
      adde(lst, k, (P){0, 0}), adde(k, lst, (P){0, 0});
      adde(k, y, w), adde(y, k, w);
      lst = k;
    }
    rebuild(y, x);
  }
}
void getrt(int x, int fa, int sz) {
  siz[x] = 1;
  for (int i = lnk[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa || mark[i]) continue;
    getrt(y, x, sz);
    siz[x] += siz[y];
    if (max(siz[x], sz - siz[x]) < mxsiz)
      mxsiz = max(siz[x], sz - siz[x]), id = i;
  }
}
void dfs(int x, int fa, P dis, vector<P> &vec) {
  vec.push_back(dis);
  for (int i = lnk[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa || mark[i]) continue;
    dfs(y, x, dis + val[i], vec);
  }
}
void build(vector<P> &vec) {
  if (!vec.size()) return;
  sort(vec.begin(), vec.end());
  stk[top = 1] = vec[0];
  for (int i = 1; i < vec.size(); i++) {
    if (vec[i].x == vec[i - 1].x) continue;
    P x = vec[i];
    while (top > 1 && (stk[top] - stk[top - 1]) * (x - stk[top]) > 0) --top;
    stk[++top] = x;
  }
  vec.clear();
  for (int i = 1; i <= top; i++) vec.push_back(stk[i]);
}
void Minkowski(vector<P> a, vector<P> b, vector<P> &c) {
  if (!a.size()) return c = b, (void)0;
  if (!b.size()) return c = a, (void)0;
  c.clear();
  P sum = a[0] + b[0];
  c.push_back(sum);
  int as = (int)a.size(), bs = (int)b.size();
  for (int i = 0, j = 0, k = 1; k <= as + bs - 2; k++) {
    P t1, t2;
    if (i + 1 < as) t1 = a[i + 1] - a[i];
    if (j + 1 < bs) t2 = b[j + 1] - b[j];
    if (j + 1 >= bs || (i + 1 < as && t1 * t2 < 0))
      sum = sum + t1, ++i;
    else
      sum = sum + t2, ++j;
    c.push_back(sum);
  }
}
void solve(int u, int sz) {
  mxsiz = 1e9, id = 0;
  getrt(u, 0, sz);
  if (!id || sz == 1) return;
  int x = to[id], y = to[id ^ 1];
  mark[id] = mark[id ^ 1] = 1;
  q1.clear(), q2.clear();
  dfs(x, y, (P){0, 0}, q1), dfs(y, x, val[id], q2);
  build(q1), build(q2);
  Minkowski(q1, q2, tmp);
  for (int i = 0; i < tmp.size(); i++) ans.push_back(tmp[i]);
  solve(x, siz[x]), solve(y, sz - siz[x]);
}
long long calc(P a, long long b) { return a.x * b + a.y; }
int main() {
  cin >> n >> m;
  idx = n;
  for (int i = 1; i <= n - 1; i++) {
    int x, y, a, b;
    scanf("%d%d%d%d", &x, &y, &a, &b);
    adde(x, y, (P){a, b}), adde(y, x, (P){a, b});
  }
  predfs(1, 0);
  cnt = 1;
  memset(lnk, 0, sizeof(lnk));
  rebuild(1, 0);
  solve(1, n);
  build(ans);
  int pos = 0, sz = (int)ans.size();
  for (int k = 0; k <= m - 1; k++) {
    if (n == 1)
      printf("0 ");
    else {
      while (pos + 1 < sz && calc(ans[pos], k) < calc(ans[pos + 1], k)) ++pos;
      printf("%lld ", calc(ans[pos], k));
    }
  }
  puts("");
  return 0;
}
