#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXSRCN = 100000;
const int MAXN = 2 * MAXSRCN - 4;
const int MAXM = MAXN - 1;
const int MAXDAY = 1000000;
struct E {
  int to, a, b;
  E() {}
  E(int to, int a, int b) : to(to), a(a), b(b) {}
};
int srcn, nday;
int n, m;
E e[2 * MAXM];
vector<int> srcadj[MAXSRCN];
vector<int> adj[MAXN];
int src[MAXN];
long long ans[MAXDAY];
bool alive[MAXM];
int sz[MAXN];
void dfssz(int at, int par) {
  sz[at] = 1;
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int x = adj[at][i], to = e[x].to;
    if (!alive[x >> 1] || to == par) continue;
    dfssz(to, at);
    sz[at] += sz[to];
  }
}
int ecentroid(int rt) {
  dfssz(rt, -1);
  int at = rt, ret = -1;
  while (true) {
    bool found = false;
    for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
      int x = adj[at][i], to = e[x].to;
      if (!alive[x >> 1] || (x >> 1) == ret) continue;
      if (sz[to] >= (sz[rt] + 2) / 3) {
        found = true;
        at = to;
        ret = x >> 1;
        break;
      }
    }
    if (!found) return ret;
  }
}
void mlt63(unsigned long long &a, unsigned long long &b) {
  unsigned long long ah = a >> 32, al = a & ((1ULL << 32) - 1), bh = b >> 32,
                     bl = b & ((1ULL << 32) - 1);
  long long ch = ah * bh, cm = ah * bl + al * bh, cl = al * bl;
  cm += cl >> 32;
  cl &= (1ULL << 32) - 1;
  ch = (ch << 1) + (cm >> 31);
  cm &= (1ULL << 31) - 1;
  a = ch, b = (cm << 32) + cl;
}
vector<pair<long long, long long>> loc[2];
vector<pair<long long, long long>> glob;
bool lefrac(long long num1, long long den1, long long num2, long long den2) {
  unsigned long long a1 = num1, a2 = den2, b1 = num2, b2 = den1;
  mlt63(a1, a2);
  mlt63(b1, b2);
  return a1 < b1 || a1 == b1 && a2 <= b2;
}
void genloc(int id, int at, int par, long long a, long long b) {
  loc[id].push_back(make_pair(a, b));
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int x = adj[at][i], to = e[x].to;
    if (!alive[x >> 1] || to == par) continue;
    genloc(id, to, at, a + e[x].a, b + e[x].b);
  }
}
bool ok(const pair<long long, long long> &u,
        const pair<long long, long long> &v,
        const pair<long long, long long> &w) {
  long long da1 = v.first - u.first, db1 = u.second - v.second;
  long long da3 = w.first - v.first, db3 = v.second - w.second;
  return !lefrac(db3, da3, db1, da1);
}
void buildhull(vector<pair<long long, long long>> &p) {
  sort(p.begin(), p.end());
  {
    int nsz = 0;
    for (int i = (0); i < (((int)(p).size())); ++i) {
      while (nsz > 0 && p[i].second >= p[nsz - 1].second) --nsz;
      p[nsz++] = p[i];
    }
    p.resize(nsz);
  }
  {
    int nsz = 0;
    for (int i = (0); i < (((int)(p).size())); ++i) {
      while (nsz >= 2 && !ok(p[nsz - 2], p[nsz - 1], p[i])) --nsz;
      p[nsz++] = p[i];
    }
    p.resize(nsz);
  }
}
void printhull(vector<pair<long long, long long>> &p) {
  for (int i = (0); i < (((int)(p).size())); ++i) {
    if (i >= 1)
      printf(" %lf", 1.0 * (p[i - 1].second - p[i].second) /
                         (p[i].first - p[i - 1].first));
    printf(" (%lld,%lld)", p[i].first, p[i].second);
  }
  puts("");
}
bool better(const pair<long long, long long> &u1,
            const pair<long long, long long> &u2,
            const pair<long long, long long> &v1,
            const pair<long long, long long> &v2) {
  long long uda = u2.first - u1.first, udb = u1.second - u2.second,
            vda = v2.first - v1.first, vdb = v1.second - v2.second;
  return lefrac(udb, uda, vdb, vda);
}
void decompose(int rt) {
  int cent = ecentroid(rt);
  if (cent == -1) return;
  int u = e[2 * cent + 1].to, v = e[2 * cent + 0].to, centa = e[2 * cent + 0].a,
      centb = e[2 * cent + 0].b;
  alive[cent] = false;
  loc[0].clear();
  genloc(0, u, -1, 0, 0);
  loc[1].clear();
  genloc(1, v, -1, 0, 0);
  for (int k = (0); k < (2); ++k) buildhull(loc[k]);
  int i = 0, j = 0;
  while (true) {
    glob.push_back(make_pair(centa + loc[0][i].first + loc[1][j].first,
                             centb + loc[0][i].second + loc[1][j].second));
    if (i + 1 < ((int)(loc[0]).size()) &&
        (j + 1 >= ((int)(loc[1]).size()) ||
         better(loc[0][i], loc[0][i + 1], loc[1][j], loc[1][j + 1])))
      ++i;
    else if (j + 1 < ((int)(loc[1]).size()))
      ++j;
    else
      break;
  }
  decompose(u);
  decompose(v);
}
void solve() {
  for (int i = (0); i < (srcn); ++i) src[i] = i;
  for (int i = (0); i < (srcn); ++i)
    if (((int)(srcadj[i]).size()) >= 4) {
      int cur = i;
      for (int j = (2); j < (((int)(srcadj[i]).size())); ++j) {
        if (j != ((int)(srcadj[i]).size()) - 1) {
          int nxt = n++;
          e[2 * m + 0] = E(nxt, 0, 0), e[2 * m + 1] = E(cur, 0, 0), ++m;
          src[nxt] = i;
          cur = nxt;
        }
        e[srcadj[i][j] ^ 1].to = cur;
      }
    }
  for (int i = (0); i < (n); ++i) adj[i].clear();
  for (int i = (0); i < (2 * m); ++i) adj[e[i].to].push_back(i ^ 1);
  for (int i = (0); i < (n); ++i) assert(((int)(adj[i]).size()) <= 3);
  for (int i = (0); i < (m); ++i) alive[i] = true;
  glob.clear();
  glob.push_back(make_pair(0, 0));
  decompose(0);
  buildhull(glob);
  int at = 0;
  for (int t = (0); t < (nday); ++t) {
    while (at + 1 < ((int)(glob).size()) &&
           glob[at + 1].first * t + glob[at + 1].second >=
               glob[at].first * t + glob[at].second)
      ++at;
    ans[t] = glob[at].first * t + glob[at].second;
  }
}
void run() {
  scanf("%d%d", &srcn, &nday);
  n = srcn, m = 0;
  for (int i = (0); i < (srcn - 1); ++i) {
    int u, v, a, b;
    scanf("%d%d%d%d", &u, &v, &a, &b);
    --u, --v;
    e[2 * m + 0] = E(v, a, b), srcadj[u].push_back(2 * m + 0),
              e[2 * m + 1] = E(u, a, b), srcadj[v].push_back(2 * m + 1), ++m;
  }
  solve();
  for (int i = (0); i < (nday); ++i) {
    if (i != 0) printf(" ");
    printf("%lld", ans[i]);
  }
  puts("");
}
void stress() {
  for (int rep = (0); rep < (100); ++rep) {
    srcn = 100, nday = 100;
    n = srcn, m = 0;
    for (int i = (0); i < (srcn); ++i) srcadj[i].clear();
    for (int i = (0); i < (srcn - 1); ++i) {
      int u = i + 1, v = rand() % u, a = rand() % 100, b = rand() % 100;
      e[2 * m + 0] = E(v, a, b), srcadj[u].push_back(2 * m + 0),
                e[2 * m + 1] = E(u, a, b), srcadj[v].push_back(2 * m + 1), ++m;
    }
    solve();
  }
}
int main() {
  run();
  return 0;
}
