#include <bits/stdc++.h>
using namespace std;
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;
template <typename T>
inline void read(T &x) {
  char ch, t = 0;
  x = 0;
  while (!isdigit(ch = (iS == iT
                            ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                               (iS == iT ? EOF : *iS++))
                            : *iS++)))
    t |= ch == '-';
  while (isdigit(ch))
    x = x * 10 + (ch ^ 48),
    ch = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                      (iS == iT ? EOF : *iS++))
                   : *iS++);
  x = t ? -x : x;
}
inline int read_int() {
  int x;
  return read(x), x;
}
inline long long read_ll() {
  long long x;
  return read(x), x;
}
template <typename T>
inline void chkmin(T &a, T b) {
  a = a < b ? a : b;
}
const int MAXN = 200010;
struct Node {
  long long k, b;
  Node() {}
  Node(long long k, long long b) : k(k), b(b) {}
  inline void rd() { k = read_int(), b = read_int(); }
  inline long double slope() { return (long double)b / k; }
  inline long long calc(int x) { return b + k * x; }
  friend long double operator*(Node a, Node b) { return a.k * b.b - b.k * a.b; }
  friend Node operator+(Node a, Node b) { return Node(a.k + b.k, a.b + b.b); }
  friend Node operator-(Node a, Node b) { return Node(a.k - b.k, a.b - b.b); }
} r, ept;
int tot;
int fi[MAXN];
int to[MAXN << 1];
int ne[MAXN << 1];
Node l[MAXN << 1];
bool ban[MAXN << 1];
vector<pair<int, Node> > son[MAXN];
inline void Link(int u, pair<int, Node> pr) {
  int v = pr.first;
  Node x = pr.second;
  tot++;
  l[tot] = x;
  to[tot] = v;
  ne[tot] = fi[u];
  fi[u] = tot;
}
inline void Dfs(int x, int la) {
  for (int i = fi[x]; i; i = ne[i]) {
    int u = to[i];
    if (u == la) continue;
    son[x].push_back(make_pair(u, l[i]));
    Dfs(u, x);
  }
}
int t;
int all;
int eu, ev, mx, eid;
Node el;
int sz[MAXN];
Node ans[19 * MAXN];
int si;
Node d[2][19 * MAXN];
int ld[2];
Node sta[19 * MAXN];
int top;
inline void find_edge(int x, int la, int fe = 0) {
  sz[x] = 1;
  for (int i = fi[x]; i; i = ne[i]) {
    int u = to[i];
    if (u == la || ban[i]) continue;
    find_edge(u, x, i);
    sz[x] += sz[u];
  }
  if (min(sz[x], all - sz[x]) > mx) {
    mx = min(sz[x], all - sz[x]);
    eu = x, ev = la, eid = fe;
    el = l[fe];
  }
}
inline void dfs(int x, int la, Node D) {
  ++all, d[t][++ld[t]] = D;
  for (int i = fi[x]; i; i = ne[i]) {
    int u = to[i];
    if (u == la || ban[i]) continue;
    dfs(u, x, D + l[i]);
  }
}
inline bool cmp(Node a, Node b) { return a.k == b.k ? a.b < b.b : a.k < b.k; }
inline void Make(int t) {
  sort(d[t] + 1, d[t] + 1 + ld[t], cmp), top = 0;
  for (int i = 1; i <= ld[t]; i++) {
    if (i > 1 && d[t][i].k == d[t][i - 1].k && d[t][i].b == d[t][i - 1].b)
      continue;
    while (top > 1 && (d[t][i] - sta[top - 1]) * (sta[top] - sta[top - 1]) < 0)
      --top;
    sta[++top] = d[t][i];
  }
  ld[t] = top;
  for (int i = 1; i <= top; i++) d[t][i] = sta[i];
}
inline void Merge(Node D) {
  Make(0), Make(1);
  int st = si + 2;
  ans[++si] = d[0][1] + d[1][1] + D;
  for (int i = 1; i < ld[0]; i++) d[0][i] = d[0][i + 1] - d[0][i];
  for (int i = 1; i < ld[1]; i++) d[1][i] = d[1][i + 1] - d[1][i];
  int i = 1, j = 1;
  while (i < ld[0] && j < ld[1]) {
    if (d[0][i] * d[1][j] < 0)
      ans[++si] = d[0][i++];
    else
      ans[++si] = d[1][j++];
  }
  while (i < ld[0]) ans[++si] = d[0][i++];
  while (j < ld[1]) ans[++si] = d[1][j++];
  for (int i = st; i <= si; i++) ans[i] = ans[i - 1] + ans[i];
}
inline void solve(int u, int v, int id, Node len) {
  ban[id] = ban[id & 1 ? id + 1 : id - 1] = 1;
  int tu1, tv1, tei1;
  Node tel1;
  int tu2, tv2, tei2;
  Node tel2;
  ld[t = 0] = 0, all = eu = ev = eid = mx = 0, dfs(u, 0, ept);
  find_edge(u, 0), tu1 = eu, tv1 = ev, tei1 = eid, tel1 = el;
  ld[t = 1] = 0, all = eu = ev = eid = mx = 0, dfs(v, 0, ept);
  find_edge(v, 0), tu2 = eu, tv2 = ev, tei2 = eid, tel2 = el;
  Merge(len);
  if (tu1) solve(tu1, tv1, tei1, tel1);
  if (tu2) solve(tu2, tv2, tei2, tel2);
}
int main() {
  int n = read_int(), m = read_int(), u, v, K, B, N = n;
  for (int i = 1; i < n; i++) {
    u = read_int(), v = read_int(), r.rd();
    Link(u, make_pair(v, r));
    Link(v, make_pair(u, r));
  }
  Dfs(1, 0), tot = 0, memset(fi, 0, sizeof(fi));
  for (int i = 1; i <= n; i++) {
    int la = i, tg1 = 0, tg2 = 0;
    pair<int, Node> s1, s2;
    for (auto u : son[i]) {
      if (!tg1)
        s1 = u, tg1 = 1;
      else if (!tg2)
        s2 = u, tg2 = 1;
      else {
        ++N, Link(N, s2), Link(s2.first, make_pair(N, s2.second));
        Link(N, u), Link(u.first, make_pair(N, u.second));
        s2 = make_pair(N, ept);
      }
    }
    if (tg1) Link(i, s1), Link(s1.first, make_pair(i, s1.second));
    if (tg2) Link(i, s2), Link(s2.first, make_pair(i, s2.second));
  }
  all = N;
  find_edge(1, 0);
  solve(eu, ev, eid, el);
  ld[0] = si;
  for (int i = 1; i <= si; i++) d[0][i] = ans[i];
  Make(0);
  for (int i = 0, now = 1; i < m; i++) {
    while (now < ld[0] && d[0][now].calc(i) <= d[0][now + 1].calc(i)) ++now;
    printf("%lld ", d[0][now].calc(i));
  }
  puts("");
  return 0;
}
