#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long Inf = 1e18;
const int N = 4e5 + 10;
const int mod = 0;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
template <typename T>
bool chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
};
template <typename T>
bool chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
};
int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); }
void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); }
struct edge {
  int to, a, b, nxt;
} e[N << 1];
struct Edge {
  int u, v, a, b;
} E[N << 1];
int tot = 1, h[N];
void adde(int u, int v, int a, int b) {
  e[++tot] = (edge){v, a, b, h[u]};
  h[u] = tot;
  e[++tot] = (edge){u, a, b, h[v]};
  h[v] = tot;
}
int n, m, st[N], top = 0, cnt = 0;
void dfs(int u, int fa) {
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs(v, u);
  }
  top = 0;
  for (int i = h[u]; i; i = e[i].nxt)
    if (e[i].to != fa) st[++top] = i;
  int lst = u;
  if (top) {
    E[++cnt] = {lst, e[st[1]].to, e[st[1]].a, e[st[1]].b};
    for (int i = 2; i < top; i++) {
      E[++cnt] = {lst, ++n, 0, 0};
      E[++cnt] = {lst = n, e[st[i]].to, e[st[i]].a, e[st[i]].b};
    }
    if (top > 1) E[++cnt] = {lst, e[st[top]].to, e[st[top]].a, e[st[top]].b};
  }
}
int siz[N], me, mn, sz;
bool vis[N];
void gete(int u, int fa) {
  siz[u] = 1;
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa || vis[i >> 1]) continue;
    gete(v, u);
    siz[u] += siz[v];
    if (chkmin(mn, max(siz[v], sz - siz[v]))) me = i;
  }
}
struct line {
  long long k, b;
};
bool operator<(line a, line b) {
  if (a.k != b.k) return a.k < b.k;
  return a.b > b.b;
}
vector<line> lx, ly, cx, cy, ret, c;
void dfs(int u, int fa, vector<line> &l, long long s1, long long s2) {
  l.push_back({s1, s2});
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa || vis[i >> 1]) continue;
    dfs(v, u, l, s1 + e[i].a, s2 + e[i].b);
  }
}
bool check(line a, line b, line c) {
  return 1.0 * (c.b - a.b) / (a.k - c.k) <= 1.0 * (b.b - a.b) / (a.k - b.k);
}
void build(vector<line> l, vector<line> &ret) {
  sort(l.begin(), l.end());
  ret.clear();
  for (int i = 0; i < int(l.size()); i++) {
    if (i != 0 && l[i].k == l[i - 1].k) continue;
    while (int(ret.size()) > 1 &&
           check(ret[int(ret.size()) - 2], ret[int(ret.size()) - 1], l[i]))
      ret.pop_back();
    ret.push_back(l[i]);
  }
}
void getsec(vector<line> c, vector<double> &sec) {
  sec.clear();
  for (int i = 0; i < int(c.size()) - 1; i++)
    sec.push_back(1.0 * (c[i + 1].b - c[i].b) / (c[i].k - c[i + 1].k));
}
void merge(vector<line> cx, vector<line> cy, vector<line> &ret) {
  ret.clear();
  vector<double> sx, sy;
  getsec(cx, sx);
  getsec(cy, sy);
  for (int i = 0, j = 0; i < int(cx.size()); i++) {
    while (1) {
      ret.push_back({cx[i].k + cy[j].k, cx[i].b + cy[j].b});
      if (j == int(cy.size()) - 1 || (i < int(cx.size()) - 1 && sx[i] < sy[j]))
        break;
      ++j;
    }
  }
  build(ret, ret);
}
void solve(int u) {
  if (siz[u] == 1) return;
  mn = inf;
  sz = siz[u];
  gete(u, 0);
  int x = e[me].to, y = e[me ^ 1].to;
  vis[me >> 1] = 1;
  if (siz[x] > siz[y])
    siz[x] = sz - siz[y];
  else
    siz[y] = sz - siz[x];
  lx.clear();
  ly.clear();
  dfs(x, 0, lx, 0, 0);
  dfs(y, 0, ly, e[me].a, e[me].b);
  build(lx, cx);
  build(ly, cy);
  merge(cx, cy, ret);
  c.insert(c.end(), ret.begin(), ret.end());
  solve(x);
  solve(y);
}
int main() {
  cin >> n >> m;
  for (int i = 1, u, v, a, b; i < n; i++)
    u = gi(), v = gi(), a = gi(), b = gi(), adde(u, v, a, b);
  dfs(1, 0);
  tot = 1;
  memset(h, 0, sizeof(h));
  for (int i = 1; i <= cnt; i++) adde(E[i].u, E[i].v, E[i].a, E[i].b);
  siz[1] = n;
  solve(1);
  c.push_back({0, 0});
  build(c, c);
  for (int i = 0, j = 0; i < m; i++) {
    while (j < int(c.size()) - 1 &&
           c[j + 1].k * i + c[j + 1].b >= c[j].k * i + c[j].b)
      ++j;
    printf("%lld ", c[j].k * i + c[j].b);
  }
  return 0;
}
