#include <bits/stdc++.h>
using namespace std;
int const N = 100000, M = 1000000;
int n, m, sz[N + 1];
pair<long long, int> an[M];
bool vis[N + 1];
vector<int> need[N + 1];
struct L {
  long long a, b;
  int id;
  L() {}
  L(long long x, long long y, int i = 0) : a(x), b(y), id(i) {}
  long long F(int x) { return a * x + b; }
  L operator+(L const &o) const { return L(a + o.a, b + o.b, id); }
};
vector<pair<int, L> > tr[N + 1];
struct ND {
  ND *l, *r;
  L ln;
  ND(ND *a, ND *b, L x) : l(a), r(b), ln(x) {}
};
struct LCT {
  ND *R;
  int sz;
  LCT() : R(0), sz(0) {}
  ND *ad(L ln, ND *v, int l = 0, int r = m - 1) {
    if (!v) return new ND(0, 0, ln);
    if (l == r) {
      if (ln.F(l) > v->ln.F(l)) v->ln = ln;
      return v;
    }
    int m = l + r >> 1;
    bool okl = ln.F(l) >= v->ln.F(l);
    bool okm = ln.F(m) >= v->ln.F(m);
    if (okm) swap(ln, v->ln), okl = !okl;
    if (okl)
      v->l = ad(ln, v->l, l, m);
    else
      v->r = ad(ln, v->r, m + 1, r);
    return v;
  }
  void ad(L ln) {
    R = ad(ln, R);
    ++sz;
  }
  pair<long long, int> gt(int x, ND *v, int l = 0, int r = m - 1) {
    if (!v) return make_pair(-1e18, 0);
    pair<long long, int> an = make_pair(v->ln.F(x), v->ln.id);
    if (l == r) return an;
    int m = l + r >> 1;
    return max(an, x <= m ? gt(x, v->l, l, m) : gt(x, v->r, m + 1, r));
  }
  pair<long long, int> gt(int x) { return gt(x, R); }
  void dl(ND *v) {
    if (!v) return;
    dl(v->l);
    dl(v->r);
    delete v;
  }
  void cl() {
    dl(R);
    R = 0;
  }
} lc[N + 1];
void plsz(int v, int p = 0) {
  sz[v] = 1;
  for (int i = 0; i < (int)(tr[v].size()); ++i) {
    int u = tr[v][i].first;
    if (u == p || vis[u]) continue;
    plsz(u, v);
    sz[v] += sz[u];
  }
}
int S;
int C(int v, int p = 0) {
  bool ok = S - sz[v] <= S >> 1;
  int an = 0;
  for (int i = 0; i < (int)(tr[v].size()); ++i) {
    int u = tr[v][i].first;
    if (u == p || vis[u]) continue;
    int t = C(u, v);
    if (t) an = t;
    ok &= sz[u] <= S >> 1;
  }
  if (ok) an = v;
  return an;
}
int lvs;
L lv[N];
void fl(int v, L ln, int p = 0) {
  if (tr[v].size() == 1) {
    ln.id = v;
    lv[lvs++] = ln;
  }
  for (auto const &t : tr[v])
    if (t.first != p && !vis[t.first]) fl(t.first, ln + t.second, v);
}
void go(int v = 1) {
  plsz(v);
  S = sz[v];
  v = C(v);
  vis[v] = true;
  LCT l;
  for (auto const &t : tr[v])
    if (!vis[t.first]) {
      lvs = 0;
      fl(t.first, t.second);
      for (int i = 0; i < (int)(lvs); ++i)
        for (int j : need[lv[i].id]) {
          pair<long long, int> t = l.gt(j);
          t.first += lv[i].F(j);
          if (t > an[j]) an[j] = t;
        }
      for (int i = 0; i < (int)(lvs); ++i) l.ad(lv[i]);
    }
  for (int j : need[v]) an[j] = max(an[j], l.gt(j));
  l.cl();
  for (int i = tr[v].size() - 1; i >= 0; --i)
    if (!vis[tr[v][i].first]) {
      pair<int, L> &t = tr[v][i];
      lvs = 0;
      fl(t.first, t.second);
      for (int i = 0; i < (int)(lvs); ++i)
        for (int j : need[lv[i].id]) {
          pair<long long, int> t = l.gt(j);
          t.first += lv[i].F(j);
          if (t > an[j]) an[j] = t;
        }
      for (int i = 0; i < (int)(lvs); ++i) l.ad(lv[i]);
    }
  for (auto const &t : tr[v])
    if (!vis[t.first]) go(t.first);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < (int)(n); ++i) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    tr[a].emplace_back(b, L(c, d));
    tr[b].emplace_back(a, L(c, d));
  }
  int lf;
  for (int i = 1; i < (int)(n + 1); ++i)
    if (tr[i].size() == 1) {
      lf = i;
      break;
    }
  for (int i = 0; i < (int)(m); ++i) need[lf].push_back(i);
  go();
  need[lf].clear();
  for (int i = 0; i < (int)(m); ++i) need[an[i].second].push_back(i);
  for (int i = 1; i < (int)(n + 1); ++i) vis[i] = false;
  go();
  printf("%lld", an[0].first);
  for (int i = 1; i < (int)(m); ++i) printf(" %lld", an[i].first);
  printf("\n");
}
