#include <bits/stdc++.h>
using namespace std;
namespace IO {
const unsigned int Buffsize = 1 << 15, Output = 1 << 24;
static char Ch[Buffsize], *S = Ch, *T = Ch;
inline char getc() {
  return ((S == T) && (T = (S = Ch) + fread(Ch, 1, Buffsize, stdin), S == T)
              ? 0
              : *S++);
}
static char Out[Output], *nowps = Out;
inline void flush() {
  fwrite(Out, 1, nowps - Out, stdout);
  nowps = Out;
}
template <typename T>
inline void read(T& x) {
  x = 0;
  static char ch;
  T f = 1;
  for (ch = getc(); !isdigit(ch); ch = getc())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getc()) x = x * 10 + (ch ^ 48);
  x *= f;
}
template <typename T>
inline void write(T x, char ch = '\n') {
  if (!x) *nowps++ = '0';
  if (x < 0) *nowps++ = '-', x = -x;
  static unsigned int sta[111], tp;
  for (tp = 0; x; x /= 10) sta[++tp] = x % 10;
  for (; tp; *nowps++ = sta[tp--] ^ 48)
    ;
  *nowps++ = ch;
  if (nowps - Out > 1e7) flush();
}
inline void readmd(int& x) {
  x = 0;
  static char ch;
  for (ch = getc(); !isdigit(ch); ch = getc())
    ;
  for (; isdigit(ch); ch = getc()) x = (x * 10ll + (ch ^ 48)) % 998244353;
}
}  // namespace IO
using namespace IO;
inline void Chkmax(long long& u, long long v) { u < v ? u = v : 0; }
void file() {}
const int MAXN = 1e5 + 7, NODE = MAXN << 1;
static int n, m;
struct edge {
  int v, a, b, nxt;
};
struct line {
  long long k, b;
  line() {}
  line(long long _k, long long _b) : k(_k), b(_b) {}
  bool operator<(const line& a) const { return k ^ a.k ? k < a.k : b < a.b; }
  inline long long getsm(int ps) { return k * ps + b; }
};
inline long long conseq(line a, line b) {
  return (a.b - b.b + b.k - a.k - 1) / (b.k - a.k);
}
static long long seq[MAXN * 26];
namespace Convex_Hull {
static line A[NODE * 20];
static int tp;
inline void Minkowski(line* l, line* r, int lenl, int lenr) {
  if (!lenl || !lenr) return;
  sort(l + 1, l + lenl + 1), sort(r + 1, r + lenr + 1);
  register int z = 0;
  for (register int i = (1); i <= (lenl); ++i)
    if (i == lenl || l[i].b > l[i + 1].b) {
      while (z && conseq(l[z], l[i]) <= seq[z]) --z;
      l[++z] = l[i];
      seq[z] = z == 1 ? 0 : conseq(l[z - 1], l[z]);
    }
  lenl = z, z = 0;
  for (register int i = (1); i <= (lenr); ++i)
    if (i == lenr || r[i].b > r[i + 1].b) {
      while (z && conseq(r[z], r[i]) <= seq[z]) --z;
      r[++z] = r[i];
      seq[z] = z == 1 ? 0 : conseq(r[z - 1], r[z]);
    }
  lenr = z;
  int i = 1, j = 1;
  while (i < lenl && j < lenr) {
    A[++tp] = line(l[i].k + r[j].k, l[i].b + r[j].b);
    if (conseq(l[i], l[i + 1]) <= conseq(r[j], r[j + 1]))
      ++i;
    else
      ++j;
  }
  while (i <= lenl) A[++tp] = line(l[i].k + r[lenr].k, l[i].b + r[lenr].b), ++i;
  while (j <= lenr) A[++tp] = line(l[lenl].k + r[j].k, l[lenl].b + r[j].b), ++j;
}
}  // namespace Convex_Hull
using Convex_Hull::A;
using Convex_Hull::tp;
namespace T2 {
const int NODE = MAXN << 1;
edge p[NODE << 1];
int head[NODE], e = 1, tt;
inline void add(int u, int v, int a, int b) {
  p[++e] = (edge){v, a, b, head[u]}, head[u] = e;
}
static int rt, vis[NODE], all, mm, sz[NODE], tl, tr;
void get_rt(int u, int fr) {
  sz[u] = 1;
  for (register int i = head[u]; i; i = p[i].nxt) {
    int v = p[i].v;
    if (!vis[i >> 1] && v ^ fr) {
      get_rt(v, u), sz[u] += sz[v];
      if (max(sz[v], all - sz[v]) < mm) mm = max(sz[v], all - sz[v]), rt = i;
    }
  }
}
static line L[NODE], R[NODE];
void getline(int u, int fr, long long sa, long long sb, line* dir, int& tp) {
  if (u <= n) dir[++tp] = line(sa, sb);
  for (register int i = head[u]; i; i = p[i].nxt) {
    int v = p[i].v;
    if (!vis[i >> 1] && v ^ fr)
      getline(v, u, sa + p[i].a, sb + p[i].b, dir, tp);
  }
}
void div_tree(int Rt) {
  if (Rt == -1) return;
  vis[Rt >> 1] = 1;
  int u = p[Rt].v, v = p[Rt ^ 1].v;
  if (sz[u] > sz[v])
    sz[u] = all - sz[v];
  else
    sz[v] = all - sz[u];
  tl = tr = 0;
  getline(u, v, 0, 0, L, tl), getline(v, u, p[Rt].a, p[Rt].b, R, tr);
  Convex_Hull::Minkowski(L, R, tl, tr);
  all = mm = sz[u], rt = -1, get_rt(u, v), div_tree(rt);
  all = mm = sz[v], rt = -1, get_rt(v, u), div_tree(rt);
}
inline void get_hull() {
  all = mm = tt, rt = -1;
  get_rt(1, 0);
  div_tree(rt);
}
}  // namespace T2
namespace T1 {
edge p[MAXN << 1];
int head[MAXN], e;
void add(int u, int v, int a, int b) {
  p[++e] = (edge){v, a, b, head[u]}, head[u] = e;
}
void Dicrossed(int u, int fr) {
  int las = u;
  for (register int i = head[u]; i; i = p[i].nxt) {
    int v = p[i].v, a = p[i].a, b = p[i].b;
    if (v ^ fr) {
      T2::add(las, v, a, b), T2::add(v, las, a, b);
      T2::add(las, ++T2::tt, 0, 0), T2::add(T2::tt, las, 0, 0);
      las = T2::tt;
      Dicrossed(v, u);
    }
  }
}
}  // namespace T1
inline void init() {
  read(n), read(m);
  static int u, v, a, b;
  for (register int i = (2); i <= (n); ++i)
    read(u), read(v), read(a), read(b), T1::add(u, v, a, b),
        T1::add(v, u, a, b);
}
inline void solve() {
  if (n == 1) {
    for (register int i = (1); i <= (m); ++i) write(0, ' ');
    flush(), exit(0);
  }
  T2::tt = n, T1::Dicrossed(1, 0);
  T2::get_hull();
  sort(A + 1, A + tp + 1);
  int z = 0;
  for (register int i = (1); i <= (tp); ++i)
    if (i == tp || A[i].b > A[i + 1].b) {
      while (z && conseq(A[z], A[i]) <= seq[z]) --z;
      A[++z] = A[i];
      seq[z] = z == 1 ? 0 : conseq(A[z - 1], A[z]);
    }
  tp = z;
  int ps = 1;
  for (register int i = (0); i <= (m - 1); ++i) {
    while (ps < tp && A[ps].getsm(i) <= A[ps + 1].getsm(i)) ++ps;
    write(A[ps].getsm(i), ' ');
  }
  flush();
}
int main() {
  file();
  init();
  solve();
  return 0;
}
