#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const double eps = 1e-10;
int n, m, u, v, x, y, rtsz, rt;
inline int read() {
  int s = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while ('0' <= c && c <= '9')
    s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  return s;
}
void write(long long x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline bool Equ(const double x, const double y) { return fabs(x - y) < eps; }
inline bool Sm(const double x, const double y) { return y - x > eps; }
inline bool Le(const double x, const double y) { return y - x > -eps; }
inline bool Bg(const double x, const double y) { return x - y > eps; }
inline bool Ge(const double x, const double y) { return x - y > -eps; }
struct Point {
  long long x, y;
  Point() {}
  Point(long long xx, long long yy) { x = xx, y = yy; }
  inline void print() { printf("%lld %lld\n", x, y); }
} Exa, E1, E2, s1[200005 << 1], s2[200005 << 1];
inline Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }
inline Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }
inline double operator*(Point A, Point B) {
  return (double)A.x * B.x + (double)A.y * B.y;
}
inline double operator^(Point A, Point B) {
  return (double)A.x * B.y - (double)A.y * B.x;
}
inline double Dis(const Point A, const Point B) {
  return (double)(A.x - B.x) * (A.x - B.x) + (double)(A.y - B.y) * (A.y - B.y);
}
inline int cmx(int x, int y) { return (x > y) ? x : y; }
struct Convex {
  vector<Point> q;
  Convex() {}
  Convex(vector<Point> t) { q = t; }
  inline void print() {
    for (vector<Point>::iterator it = q.begin(); it != q.end(); ++it)
      printf(" %lld %lld\n", it->x, it->y);
    putchar('\n');
  }
} Ans, A0, A1, B0, B1;
inline bool sig(Point A) { return Sm((A - E1) ^ (A - E2), 0.0) ? 1 : -1; }
inline bool cmp(const Point &A, const Point &B) {
  Point C = A - Exa, D = B - Exa;
  int sg1 = sig(C), sg2 = sig(D);
  if (sg1 != sg2) return sg1 < sg2;
  double x = C ^ D;
  if (!Equ(x, 0.0)) return Bg(x, 0.0);
  return Sm(Dis(A, Exa), Dis(B, Exa));
}
inline void cov(Convex &A, Convex &Q) {
  Exa = *A.q.begin();
  A.q.erase(A.q.begin());
  for (vector<Point>::iterator it = A.q.begin(); it != A.q.end(); ++it)
    if (it->y < Exa.y || it->y == Exa.y && it->x < Exa.x) swap(Exa, *it);
  sort(A.q.begin(), A.q.end(), cmp);
  Q.q.clear();
  Q.q.push_back(Exa);
  for (vector<Point>::iterator it = A.q.begin(); it != A.q.end(); ++it) {
    while (Q.q.size() > 1 &&
           Le(0.0, ((*it) - (*(Q.q.end() - 1))) ^
                       ((*(Q.q.end() - 1)) - (*(Q.q.end() - 2)))))
      Q.q.pop_back();
    Q.q.push_back(*it);
  }
}
inline void Minkowski(Convex &A, Convex &B) {
  int n = A.q.size(), m = B.q.size();
  for (int i = 1; i < n; ++i) s1[i] = A.q[i] - A.q[i - 1];
  for (int i = 1; i < m; ++i) s2[i] = B.q[i] - B.q[i - 1];
  if (n > 2)
    s1[n] = A.q[0] - A.q[n - 1];
  else
    --n;
  if (m > 2)
    s2[m] = B.q[0] - B.q[m - 1];
  else
    --m;
  Ans.q.push_back(*A.q.begin() + *B.q.begin());
  int cnt1 = 1, cnt2 = 1;
  Point cur = *A.q.begin() + *B.q.begin();
  while (cnt1 <= n && cnt2 <= m)
    if (Sm(0.0, s1[cnt1] ^ s2[cnt2]))
      cur = cur + s1[cnt1], Ans.q.push_back(cur), ++cnt1;
    else
      cur = cur + s2[cnt2], Ans.q.push_back(cur), ++cnt2;
  while (cnt1 <= n) cur = cur + s1[cnt1], Ans.q.push_back(cur), ++cnt1;
  while (cnt2 <= m) cur = cur + s2[cnt2], Ans.q.push_back(cur), ++cnt2;
}
struct edge {
  int nxt, v;
  Point Vec;
  edge() {}
  edge(int Nxt, int V, Point C) { nxt = Nxt, v = V, Vec = C; }
};
struct Tree {
  int tot, fr[200005];
  edge e[200005 << 1];
  void add(const int x, const int y, const Point C) {
    ++tot;
    e[tot] = edge(fr[x], y, C), fr[x] = tot;
  }
} T;
int cot, tot = 1, fr[200005 << 1], sz[200005 << 1];
edge e[200005 << 2];
bool vis[200005 << 2];
inline void add(const int x, const int y, const Point C) {
  ++tot;
  e[tot] = edge(fr[x], y, C), fr[x] = tot;
}
inline void add_edge(const int x, const int y, const Point C) {
  add(x, y, C), add(y, x, C);
}
void build(int u, int F) {
  int cnt = 0, lst;
  for (int i = T.fr[u]; i; i = T.e[i].nxt) {
    int v = T.e[i].v;
    Point C = T.e[i].Vec;
    if (v == F) continue;
    ++cnt;
    if (cnt == 1)
      add_edge(u, v, C), lst = u;
    else
      add_edge(lst, ++cot, Point(0, 0)), add_edge(cot, v, C), lst = cot;
    build(v, u);
  }
}
void getrt(int u, int F, int rn) {
  sz[u] = 1;
  for (int i = fr[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == F || vis[i]) continue;
    getrt(v, u, rn);
    sz[u] += sz[v];
    if (cmx(sz[v], rn - sz[v]) < rtsz) rtsz = cmx(sz[v], rn - sz[v]), rt = i;
  }
}
void dfs(int u, int F, Point C, int opt) {
  if (opt == 0)
    A0.q.push_back(C);
  else
    A1.q.push_back(C);
  for (int i = fr[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == F || vis[i]) continue;
    dfs(v, u, C + e[i].Vec, opt);
  }
}
void solve(int u, int s) {
  if (s == 1) return;
  rtsz = INF;
  getrt(u, 0, s);
  vis[rt] = vis[rt ^ 1] = true;
  int v1 = e[rt].v, v2 = e[rt ^ 1].v, rsz = s - sz[v1];
  A0.q.clear(), A1.q.clear();
  dfs(v1, 0, Point(0, 0), 0), dfs(v2, 0, e[rt].Vec, 1);
  cov(A0, B0), cov(A1, B1);
  Minkowski(B0, B1);
  solve(v1, sz[v1]), solve(v2, rsz);
}
inline long long calc(const long long x, const Point A) {
  return A.x * x + A.y;
}
int main() {
  E1 = Point(19191919, 1), E2 = Point(-19191919, -1);
  n = read(), m = read(), cot = n;
  if (n == 1) {
    for (register int i = 0; i < m; ++i) printf("0 ");
    putchar('\n');
    return 0;
  }
  for (register int i = 1; i < n; ++i) {
    u = read(), v = read(), x = read(), y = read();
    T.add(u, v, Point(x, y)), T.add(v, u, Point(x, y));
  }
  build(1, 0);
  solve(1, cot);
  cov(Ans, B0);
  int sz = B0.q.size();
  int st = 0;
  for (register int i = 1; i < sz; ++i)
    if (B0.q[i].y > B0.q[st].y) st = i;
  for (register int i = 0; i < m; ++i) {
    while (st && calc(i, B0.q[st]) <= calc(i, B0.q[st - 1])) --st;
    write(calc(i, B0.q[st])), putchar(' ');
  }
  printf("\n");
  return 0;
}
