#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
namespace ywy {
inline int get() {
  int n = 0;
  char c;
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9') break;
    if (c == '-') goto s;
  }
  n = c - '0';
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 + c - '0';
    else
      return (n);
  }
s:
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 - c + '0';
    else
      return (n);
  }
}
void print(long long num) {
  if (num >= 10) print(num / 10);
  putchar(num % 10 + '0');
}
typedef struct _b {
  int dest;
  int nxt;
  int a;
  int b;
  unsigned char gg;
} bian;
bian memchi[2000001];
int gn = 2, fheads[200001], heads[200001];
inline void add(int s, int t, int a, int b, int *hd) {
  memchi[gn].dest = t;
  memchi[gn].a = a;
  memchi[gn].nxt = hd[s];
  memchi[gn].b = b;
  hd[s] = gn;
  gn++;
}
typedef struct _n {
  long long x;
  long long y;
  _n() { x = y = 0; }
  _n(long long i, long long j) {
    x = i;
    y = j;
  }
  friend bool operator<(const _n &a, const _n &b) {
    if (a.x == b.x) return (a.y < b.y);
    return (a.x < b.x);
  }
  friend _n operator-(const _n &a, const _n &b) {
    return (_n(a.x - b.x, a.y - b.y));
  }
  friend long double operator*(const _n &a, const _n &b) {
    return ((long double)a.x * (long double)b.y -
            (long double)a.y * (long double)b.x);
  }
  friend _n operator+(const _n &a, const _n &b) {
    return (_n(a.x + b.x, a.y + b.y));
  }
  friend bool operator==(const _n &a, const _n &b) {
    return ((((long double)a.x * (long double)b.y -
                  (long double)a.y * (long double)b.x <
              0)
                 ? -((long double)a.x * (long double)b.y -
                     (long double)a.y * (long double)b.x)
                 : (long double)a.x * (long double)b.y -
                       (long double)a.y * (long double)b.x) <= 1e-9);
  }
} node;
node tb[6000001], stk[6000001], tmp[200001], mkf[200001];
int ptr = 1, zx, tot, gtb = 1;
inline int cmp(const node &a, const node &b) {
  return ((long double)a.y * (long double)b.x > (long double)a.x * b.y);
}
int gpt = 1;
void dfs(int pt, int baba) {
  int lst = pt;
  for (register int i = fheads[pt]; i; i = memchi[i].nxt) {
    if (memchi[i].dest == baba) continue;
    int me = gpt;
    gpt++;
    add(lst, me, 0, 0, heads);
    add(me, lst, 0, 0, heads);
    add(me, memchi[i].dest, memchi[i].a, memchi[i].b, heads);
    add(memchi[i].dest, me, memchi[i].a, memchi[i].b, heads);
    lst = me;
    dfs(memchi[i].dest, pt);
  }
}
long long siga[200001], sigb[200001];
int size[200001];
int minn = 123456789;
void afs(int pt, int baba) {
  tot++;
  for (register int i = heads[pt]; i; i = memchi[i].nxt) {
    if (memchi[i].dest == baba || memchi[i].gg) continue;
    afs(memchi[i].dest, pt);
  }
}
void bfs(int pt, int baba) {
  size[pt] = 1;
  for (register int i = heads[pt]; i; i = memchi[i].nxt) {
    if (memchi[i].gg || memchi[i].dest == baba) continue;
    bfs(memchi[i].dest, pt);
    size[pt] += size[memchi[i].dest];
    if (((size[memchi[i].dest] - (tot - size[memchi[i].dest]) < 0)
             ? -(size[memchi[i].dest] - (tot - size[memchi[i].dest]))
             : size[memchi[i].dest] - (tot - size[memchi[i].dest])) < minn) {
      minn = ((size[memchi[i].dest] - (tot - size[memchi[i].dest]) < 0)
                  ? -(size[memchi[i].dest] - (tot - size[memchi[i].dest]))
                  : size[memchi[i].dest] - (tot - size[memchi[i].dest]));
      zx = i;
    }
  }
}
void cfs(int pt, int baba) {
  tmp[ptr].x = siga[pt];
  tmp[ptr].y = sigb[pt];
  ptr++;
  for (register int i = heads[pt]; i; i = memchi[i].nxt) {
    if (memchi[i].gg || memchi[i].dest == baba) continue;
    siga[memchi[i].dest] = siga[pt] + memchi[i].a;
    sigb[memchi[i].dest] = sigb[pt] + memchi[i].b;
    cfs(memchi[i].dest, pt);
  }
}
void digui(int pt) {
  tot = 0;
  minn = 1234567890;
  afs(pt, 0);
  bfs(pt, 0);
  if (tot == 1) return;
  int me = zx, a = memchi[me].dest, b = memchi[me ^ 1].dest;
  memchi[me].gg = memchi[me ^ 1].gg = 1;
  ptr = 1;
  siga[a] = memchi[me].a;
  sigb[a] = memchi[me].b;
  cfs(a, 0);
  ptr--;
  int sp = 0;
  sort(tmp + 1, tmp + 1 + ptr);
  for (register int i = 1; i <= ptr; i++) {
    while (sp > 1 && (tmp[i] - stk[sp - 1]) * (tmp[i] - stk[sp - 2]) <= 0) sp--;
    stk[sp] = tmp[i];
    sp++;
  }
  int lp = 1;
  node dll = stk[0];
  for (register int i = 0; i < sp - 1; i++) mkf[lp] = stk[i + 1] - stk[i], lp++;
  ;
  siga[b] = 0;
  sigb[b] = 0;
  ptr = 1;
  cfs(b, 0);
  ptr--;
  sp = 0;
  sort(tmp + 1, tmp + 1 + ptr);
  for (register int i = 1; i <= ptr; i++) {
    while (sp > 1 && (tmp[i] - stk[sp - 1]) * (tmp[i] - stk[sp - 2]) <= 0) sp--;
    stk[sp] = tmp[i];
    sp++;
  }
  node pdb = _n(stk[0].x + dll.x, stk[0].y + dll.y);
  for (register int i = 0; i < sp - 1; i++) {
    mkf[lp] = stk[i + 1] - stk[i];
    lp++;
  }
  lp--;
  sort(mkf + 1, mkf + 1 + lp, cmp);
  tb[gtb] = pdb;
  gtb++;
  for (register int i = 1; i <= lp; i++) {
    pdb = pdb + mkf[i];
    tb[gtb] = pdb;
    gtb++;
  }
  digui(a);
  digui(b);
}
void ywymain() {
  int n = get();
  gpt = n + 1;
  int m = get();
  for (register int i = 1; i < n; i++) {
    int s = get(), t = get(), a = get(), b = get();
    add(s, t, a, b, fheads);
    add(t, s, a, b, fheads);
  }
  dfs(1, 0);
  digui(1);
  gtb--;
  int sp = 0;
  sort(tb + 1, tb + gtb + 1);
  for (register int i = 1; i <= gtb; i++) {
    while (sp > 1 && (tb[i] - stk[sp - 1]) * (tb[i] - stk[sp - 2]) <= 0) sp--;
    stk[sp] = tb[i];
    sp++;
  }
  int pos = 0;
  for (register int i = 0; i < m; i++) {
    while (pos < sp - 1 && (long long)i * stk[pos + 1].x + stk[pos + 1].y >=
                               (long long)i * stk[pos].x + stk[pos].y)
      pos++;
    print(stk[pos].x * (long long)i + stk[pos].y);
    putchar(' ');
  }
}
}  // namespace ywy
int main() {
  ywy::ywymain();
  return (0);
}
