#include <bits/stdc++.h>
using namespace std;
template <typename tp>
inline void read(tp &x) {
  x = 0;
  char c = getchar();
  int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
    ;
  if (f) x = -x;
}
struct P {
  long long x, y;
  P(long long _x = 0, long long _y = 0) {
    x = _x;
    y = _y;
  }
  inline void in() {
    read(x);
    read(y);
  }
  inline void ovo() { cout << x << " " << y << "\n"; }
  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 bool operator<(P a, P b) {
    return a.x < b.x || (a.x == b.x && a.y > b.y);
  }
  inline long long F(int t) { return x * t + y; }
};
inline long long crs(P a, P b) { return a.x * b.y - a.y * b.x; }
const int N = 3e5 + 233;
vector<pair<int, P> > F[N], G[N];
int n, m, root, proot;
int ban[N], sz[N];
P st[N], dep[N];
int top;
vector<P> l, r, all;
inline void rebuild(int u, int fat) {
  vector<pair<int, P> > son;
  for (auto i : F[u])
    if (i.first != fat) {
      son.push_back(i);
      rebuild(i.first, u);
    }
  int pre = u;
  for (register int i = 0; i < (int)son.size(); i++) {
    if (i) {
      ++n;
      G[n].push_back({pre, P(0, 0)});
      G[pre].push_back({n, P(0, 0)});
      pre = n;
    }
    G[son[i].first].push_back({pre, son[i].second});
    G[pre].push_back({son[i].first, son[i].second});
  }
}
inline void dfs(int u, int fat, int all_n) {
  sz[u] = 1;
  for (auto i : G[u]) {
    if (i.first == fat || ban[i.first]) continue;
    dfs(i.first, u, all_n);
    sz[u] += sz[i.first];
  }
  if (!root ||
      fat && max(sz[root], all_n - sz[root]) > max(sz[u], all_n - sz[u])) {
    root = u;
    proot = fat;
  }
}
inline void get_dep(int u, int fat, bool right) {
  if (right)
    r.push_back(dep[u]);
  else
    l.push_back(dep[u]);
  for (auto i : G[u]) {
    if (i.first == fat || ban[i.first]) continue;
    dep[i.first] = dep[u] + i.second;
    get_dep(i.first, u, i.first == root ? 0 : right);
  }
}
vector<P> build(vector<P> a) {
  sort(a.begin(), a.end());
  top = 0;
  for (register int i = 0; i < (int)a.size(); i++) {
    if (i && a[i].x == a[i - 1].x) continue;
    while (top && st[top].y <= a[i].y) --top;
    while (top > 1 && crs(a[i] - st[top - 1], st[top] - st[top - 1]) <= 0)
      --top;
    st[++top] = a[i];
  }
  vector<P> ret;
  for (register int i = 1; i <= (top); i++) ret.push_back(st[i]);
  return ret;
}
inline void make(const vector<P> &l, const vector<P> &r) {
  all.push_back(l[0] + r[0]);
  unsigned i = 0, j = 0;
  while (i + 1 < l.size() || j + 1 < r.size()) {
    if (j + 1 == r.size() ||
        (i + 1 < l.size() && crs(l[i + 1] - l[i], r[j + 1] - r[j]) <= 0)) {
      all.push_back(l[++i] + r[j]);
    } else {
      all.push_back(l[i] + r[++j]);
    }
  }
}
inline void divide(int u, int size) {
  if (size <= 1) return;
  root = proot = 0;
  dfs(u, 0, size);
  int x = root, y = proot;
  int sx = sz[x], sy = size - sx;
  l.clear();
  r.clear();
  dep[y] = P(0, 0);
  get_dep(y, 0, true);
  l = build(l);
  r = build(r);
  make(l, r);
  ban[x] = true;
  divide(y, sy);
  ban[x] = false;
  ban[y] = true;
  divide(x, sx);
  ban[y] = false;
}
inline void doit(vector<P> ans) {
  unsigned i = 0;
  for (register int t = 0; t < (int)m; t++) {
    while (i + 1 < ans.size() && ans[i + 1].F(t) > ans[i].F(t)) {
      ++i;
    }
    cout << ans[i].F(t) << " ";
  }
  cout << "\n";
}
int main(void) {
  read(n);
  read(m);
  for (register int i = 1; i <= (n - 1); i++) {
    int x, y;
    P w;
    read(x);
    read(y);
    w.in();
    F[x].push_back({y, w});
    F[y].push_back({x, w});
  }
  rebuild(1, 0);
  divide(1, n);
  all.push_back(P(0, 0));
  all = build(all);
  doit(all);
}
