#include <bits/stdc++.h>
using namespace std;
struct dot {
  long long x, y;
  dot(long long a = 0, long long b = 0) { x = a, y = b; }
  friend dot operator+(const dot &a, const dot &b) {
    return dot(a.x + b.x, a.y + b.y);
  }
  friend dot operator-(const dot &a, const dot &b) {
    return dot(a.x - b.x, a.y - b.y);
  }
  inline long double getk() { return (long double)y / (long double)x; }
};
inline bool cmp(dot a, dot b) { return a.x < b.x || (a.x == b.x && a.y > b.y); }
dot stk[200005 * 30];
template <int SIZE>
struct convex {
  dot p[SIZE];
  int cnt;
  inline void init() {
    for (int i = 1; i <= cnt; ++i) p[i] = dot(0, 0);
    cnt = 0;
  }
  inline void insert(const dot &x) { p[++cnt] = x; }
  inline long double slope(dot a, dot b) {
    return 1.0 * (a.y - b.y) / (long double)(a.x - b.x);
  }
  inline void trans() {
    for (int i = cnt; i >= 2; --i) p[i] = p[i] - p[i - 1];
  }
  inline void build() {
    sort(p + 1, p + cnt + 1, cmp);
    int top = 1;
    for (int i = 2; i <= cnt; ++i)
      if (p[i].x != p[i - 1].x) p[++top] = p[i];
    cnt = top, top = 0;
    for (int i = 1; i <= cnt; ++i) {
      while (top > 1 && slope(p[i], p[top]) > slope(p[i], p[top - 1])) --top;
      p[++top] = p[i];
    }
    cnt = top;
  }
  template <int S1, int S2>
  inline void Minkowski(convex<S1> &a, convex<S2> &b) {
    a.build(), a.trans();
    b.build(), b.trans();
    int ca = 2, cb = 2, cc = 1;
    stk[cc] = a.p[1] + b.p[1];
    while (ca <= a.cnt && cb <= b.cnt) {
      if (a.p[ca].getk() > b.p[cb].getk())
        ++cc, stk[cc] = stk[cc - 1] + a.p[ca++];
      else
        ++cc, stk[cc] = stk[cc - 1] + b.p[cb++];
    }
    while (ca <= a.cnt) ++cc, stk[cc] = stk[cc - 1] + a.p[ca++];
    while (cb <= b.cnt) ++cc, stk[cc] = stk[cc - 1] + b.p[cb++];
    while (cc) p[++cnt] = stk[cc--];
  }
  inline void query(int m) {
    build();
    int ql = 1;
    for (int i = 0; i > -m; --i) {
      while (ql < cnt && slope(p[ql], p[ql + 1]) > 1.0 * i) ++ql;
      long long ans = p[ql].x * (-i) + p[ql].y;
      printf("%lld\n", ans);
    }
  }
};
int n, m, ext, ex[200005 << 1], ey[200005 << 1];
dot ev[200005];
vector<pair<int, int> > G[200005 << 1], e[200005 << 1];
inline void addE(int u, pair<int, int> now) {
  G[u].push_back(now), G[now.first].push_back(make_pair(u, now.second));
  ex[now.second] = u, ey[now.second] = now.first;
}
void rebuild(int u, int p) {
  vector<pair<int, int> > son;
  for (int i = e[u].size() - 1, v; ~i; --i) {
    v = e[u][i].first;
    if (v == p) continue;
    rebuild(v, u);
    son.push_back(e[u][i]);
  }
  if (!son.size()) return;
  if ((int)son.size() == 1) return addE(u, son[0]);
  int las = u;
  for (int i = son.size() - 1; i > 1; --i) {
    ++ext;
    addE(las, make_pair(ext, ext - 1));
    addE(las, son[i]), las = ext;
  }
  addE(las, son[0]), addE(las, son[1]);
}
int ban[200005 << 1], vis[200005 << 1], sz[200005 << 1];
void getsz(int u, int p) {
  sz[u] = 1;
  for (int i = G[u].size() - 1; ~i; --i)
    if (!ban[G[u][i].second] && G[u][i].first != p)
      getsz(G[u][i].first, u), sz[u] += sz[G[u][i].first];
}
void gete(int u, int p, int wh, int &res, int &id) {
  for (int i = G[u].size() - 1, v; ~i; --i) {
    v = G[u][i].first;
    if (ban[G[u][i].second] || v == p) continue;
    gete(v, u, wh, res, id);
    int now = max(sz[v], wh - sz[v]);
    if (now < res) res = now, id = G[u][i].second;
  }
}
convex<200005 * 4> S[2];
convex<200005 * 30> ans;
void calc(int u, int p, dot dis, const int &op) {
  if (dis.x + dis.y) S[op].insert(dis);
  for (int i = G[u].size() - 1, v; ~i; --i) {
    v = G[u][i].first;
    if (v == p || ban[G[u][i].second]) continue;
    calc(v, u, dis + ev[G[u][i].second], op);
  }
}
void dfs(int u) {
  int res = ext + 1, id = 0;
  getsz(u, 0);
  gete(u, 0, sz[u], res, id);
  if (!id) return;
  ban[id] = 1;
  S[0].init(), S[1].init();
  calc(ex[id], 0, ev[id], 0);
  calc(ey[id], 0, dot(0, 0), 1);
  ans.Minkowski(S[0], S[1]);
  dfs(ex[id]), dfs(ey[id]);
}
int main() {
  cin >> n >> m, ext = n;
  for (int i = 1, u, v, a, b; i < n; ++i) {
    scanf("%d%d%d%d", &u, &v, &a, &b);
    e[u].push_back(make_pair(v, i)), e[v].push_back(make_pair(u, i));
    ev[i] = dot(a, b);
  }
  rebuild(1, 0);
  dfs(1);
  ans.insert(dot(0, 0));
  ans.query(m);
  return 0;
}
