#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct edge {
  int to, next, a, b, id;
} e[N * 2];
int head[N], mat[N], tot;
int deg[N], n, T, nd, ed, mxv;
int sz[N], vis[N], px, py, pid;
vector<pair<long long, long long> > ans;
bool cmp(pair<long long, long long> x, pair<long long, long long> y,
         pair<long long, long long> z) {
  y.first -= x.first;
  y.second -= x.second;
  z.first -= x.first;
  z.second -= x.second;
  return y.first * z.second >= z.first * y.second;
}
pair<long long, long long> operator+(pair<long long, long long> a,
                                     pair<long long, long long> b) {
  return pair<long long, long long>(a.first + b.first, a.second + b.second);
}
vector<pair<long long, long long> > convex_hull(
    vector<pair<long long, long long> > v) {
  static pair<long long, long long> a[N * 30];
  int sz = v.size();
  for (int i = (int)(0); i <= (int)(sz - 1); i++) a[i + 1] = v[i];
  sort(a + 1, a + sz + 1);
  int tp = 1;
  for (int i = (int)(2); i <= (int)(sz); i++) {
    for (; tp >= 1 && a[tp].first == a[i].first && a[tp].second < a[i].second;
         --tp)
      ;
    for (; tp >= 2 && cmp(a[tp - 1], a[tp], a[i]); --tp)
      ;
    a[++tp] = a[i];
  }
  vector<pair<long long, long long> > res;
  for (int i = (int)(1); i <= (int)(tp); i++) res.push_back(a[i]);
  return res;
}
void merge(vector<pair<long long, long long> > va,
           vector<pair<long long, long long> > vb, int a, int b) {
  int sza = va.size(), szb = vb.size();
  int pa = 0, pb = 0;
  for (;;) {
    ans.push_back(pair<long long, long long>(
        va[pa].first + vb[pb].first + a, va[pa].second + vb[pb].second + b));
    if (pa == sza - 1)
      ++pb;
    else if (pb == szb - 1)
      ++pa;
    else if (cmp(va[pa] + vb[pb], va[pa + 1] + vb[pb], va[pa] + vb[pb + 1]))
      ++pb;
    else
      ++pa;
    if (pa == sza || pb == szb) break;
  }
}
void add(int x, int y, int a, int b) {
  ++ed;
  ++deg[x];
  ++deg[y];
  e[++tot] = (edge){y, head[x], a, b, ed};
  head[x] = tot;
  e[++tot] = (edge){x, head[y], a, b, ed};
  head[y] = tot;
}
int getid(int x) {
  if (deg[mat[x]] != 2) return mat[x];
  add(mat[x], ++nd, 0, 0);
  return mat[x] = nd;
}
void dfs(int x, int fa, int faid, int n) {
  sz[x] = 1;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa && !vis[e[i].id]) {
      dfs(e[i].to, x, e[i].id, n);
      sz[x] += sz[e[i].to];
    }
  if (abs(n - 2 * sz[x]) < mxv)
    mxv = abs(n - 2 * sz[x]), px = x, py = fa, pid = faid;
}
void dfs2(int x, int fa, long long a, long long b,
          vector<pair<long long, long long> > &v) {
  v.push_back(pair<long long, long long>(a, b));
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa && !vis[e[i].id])
      dfs2(e[i].to, x, a + e[i].a, b + e[i].b, v);
}
void convex(int x, vector<pair<long long, long long> > &y) {
  y.resize(0);
  dfs2(x, 0, 0, 0, y);
  y = convex_hull(y);
}
void solve(int x, int n) {
  if (n == 1) return;
  mxv = 1 << 30;
  dfs(x, 0, 0, n);
  vis[pid] = 1;
  vector<pair<long long, long long> > v1, v2;
  convex(px, v1);
  convex(py, v2);
  merge(v1, v2, e[pid * 2].a, e[pid * 2].b);
  int pp = px;
  solve(py, n - sz[pp]);
  solve(pp, sz[pp]);
}
int main() {
  scanf("%d%d", &n, &T);
  nd = n;
  ed = 0;
  for (int i = (int)(1); i <= (int)(n); i++) mat[i] = i;
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x, y, a, b;
    scanf("%d%d%d%d", &x, &y, &a, &b);
    int p = getid(x), q = getid(y);
    add(p, q, a, b);
  }
  solve(1, nd);
  ans = convex_hull(ans);
  int sz = ans.size(), p = 0;
  for (int i = (int)(0); i <= (int)(T - 1); i++) {
    for (; p != sz - 1;) {
      long long v1 = 1ll * i * ans[p].first + ans[p].second;
      long long v2 = 1ll * i * ans[p + 1].first + ans[p + 1].second;
      if (v1 <= v2)
        ++p;
      else
        break;
    }
    printf("%lld ", 1ll * i * ans[p].first + ans[p].second);
  }
}
