#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10, maxp = 6e6 + 10;
int n, m, u, v, a, b, sz[maxn], fxk, ct, st[maxp], N, tp, cnt;
bool vis[maxn];
struct pt {
  long long x, y;
  pt(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}
};
vector<pt> A, B, C, ans;
pt operator+(pt a, pt b) { return pt(a.x + b.x, a.y + b.y); }
pt operator-(pt a, pt b) { return pt(a.x - b.x, a.y - b.y); }
double operator^(pt a, pt b) { return (double)a.x * b.y - (double)a.y * b.x; }
bool operator<(pt a, pt b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }
struct Graph {
  int to[maxn << 1], nex[maxn << 1], hed[maxn], ed;
  pt p[maxn << 1];
  Graph() {
    memset(hed, -1, sizeof(hed));
    ed = -1;
  }
  inline void add(int u, int v, pt _p) {
    to[++ed] = v;
    nex[ed] = hed[u];
    p[ed] = _p;
    hed[u] = ed;
  }
} G, H;
void rebuild(int u, int fa) {
  int ff = 0;
  for (int i = G.hed[u], v = G.to[i]; ~i; i = G.nex[i], v = G.to[i])
    if (v != fa) {
      rebuild(v, u);
      if (!ff)
        H.add(u, v, G.p[i]), H.add(v, u, G.p[i]), ff = u;
      else
        ++cnt, H.add(ff, cnt, pt(0, 0)), H.add(cnt, ff, pt(0, 0)),
            H.add(cnt, v, G.p[i]), H.add(v, cnt, G.p[i]), ff = cnt;
    }
}
void findct(int u, int fa) {
  sz[u] = 1;
  int w = 0;
  for (int i = H.hed[u], v = H.to[i]; ~i; i = H.nex[i], v = H.to[i])
    if (!vis[i >> 1] && v != fa) {
      findct(v, u), sz[u] += sz[v], w = max(N - sz[v], sz[v]);
      if (w < fxk) fxk = w, ct = i;
    }
}
void dfs(int u, int fa, vector<pt> &ans, pt d) {
  ans.push_back(d);
  for (int i = H.hed[u], v = H.to[i]; ~i; i = H.nex[i], v = H.to[i])
    if (v != fa && !vis[i >> 1]) dfs(v, u, ans, d + H.p[i]);
}
void build(vector<pt> &a) {
  if (!a.size()) return;
  sort(a.begin(), a.end());
  st[tp = 0] = 0;
  for (int i = (1); i <= (a.size() - 1); ++i) {
    while (tp && ((a[st[tp]] - a[st[tp - 1]]) ^ (a[i] - a[st[tp - 1]])) >= 0)
      --tp;
    st[++tp] = i;
  }
  for (int i = (0); i <= (tp); ++i) a[i] = a[st[i]];
  a.resize(tp + 1);
}
vector<pt> operator+(vector<pt> a, vector<pt> b) {
  vector<pt> c;
  c.clear();
  int n = a.size(), m = b.size(), i = 1, j = 1;
  pt x;
  c.push_back(x = a[0] + b[0]);
  while (i < n && j < m)
    if (((a[i] - a[i - 1]) ^ (b[j] - b[j - 1])) > 0)
      c.push_back(x = x + (b[j] - b[j - 1])), ++j;
    else
      c.push_back(x = x + (a[i] - a[i - 1])), ++i;
  while (i < n) c.push_back(x = x + a[i] - a[i - 1]), ++i;
  while (j < m) c.push_back(x = x + b[j] - b[j - 1]), ++j;
  return c;
}
void solve(int u, int SZ) {
  N = SZ;
  ct = cnt;
  fxk = 1e9;
  findct(u, 0);
  if (fxk == 1e9) return;
  int x = ct;
  vis[x >> 1] = true;
  A.clear();
  B.clear();
  dfs(H.to[x], 0, A, pt(0, 0));
  dfs(H.to[x ^ 1], 0, B, H.p[x]);
  build(A);
  build(B);
  C = A + B;
  for (int i = (0); i <= (C.size() - 1); ++i) ans.push_back(C[i]);
  solve(H.to[x], sz[H.to[x]]);
  solve(H.to[x ^ 1], SZ - sz[H.to[x]]);
}
int main() {
  scanf("%d%d", &n, &m);
  cnt = n;
  if (n == 1) {
    for (int i = (0); i <= (m - 1); ++i) printf("0 ");
    return 0;
  }
  for (int i = (1); i <= (n - 1); ++i)
    scanf("%d%d%d%d", &u, &v, &a, &b), G.add(u, v, pt(a, b)),
        G.add(v, u, pt(a, b));
  rebuild(1, 0);
  solve(1, cnt);
  build(ans);
  cerr << ans.size() - 1;
  int tp = (int)ans.size() - 1, j = 0;
  for (int i = (0); i <= (m - 1); ++i) {
    while (j < tp && i * ans[j].x + ans[j].y <= i * ans[j + 1].x + ans[j + 1].y)
      ++j;
    printf("%lld ", i * ans[j].x + ans[j].y);
  }
  return 0;
}
