#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
vector<pair<int, int>> origE[100005];
vector<pair<int, int>> E[MAXN];
int siz[MAXN];
long long A[MAXN], B[MAXN];
void getSizes(int x, int p = -1) {
  siz[x] = 1;
  for (auto e : E[x]) {
    int y = e.first;
    if (y == p) continue;
    getSizes(y, x);
    siz[x] += siz[y];
  }
}
int findCentroid(int x, int n, int p = -1) {
  for (auto e : E[x]) {
    int y = e.first;
    if (y == p) continue;
    if (siz[y] > n / 2) return findCentroid(y, n, x);
  }
  return x;
}
struct FastHull {
  vector<int> id;
  vector<long long> A, B, P;
  int c;
  int qpos;
  FastHull() {}
  FastHull(int n, bool hasid = false) { c = qpos = 0; }
  long long monotonicQuery(int x) {
    while (qpos + 1 < c && P[qpos + 1] <= x) ++qpos;
    return A[qpos] * x + B[qpos];
  }
  long long query(int x) {
    int pos = upper_bound(P.begin(), P.begin() + c, x) - P.begin() - 1;
    return A[pos] * x + B[pos];
  }
  long long divideCeil(long long p, long long q) {
    if (p >= 0) return (p + q - 1) / q;
    return -((-p) / q);
  }
  void insertLine(long long a, long long b, int i = -1) {
    for (; c; --c) {
      if (A[c - 1] == a) {
        if (B[c - 1] >= b) return;
        continue;
      }
      long long pt = divideCeil(B[c - 1] - b, a - A[c - 1]);
      if (pt > P[c - 1]) break;
    }
    P.resize(c + 1);
    A.resize(c + 1);
    B.resize(c + 1);
    P[c] = c ? divideCeil(B[c - 1] - b, a - A[c - 1]) : LLONG_MIN;
    A[c] = a;
    B[c] = b;
    if (i != -1) {
      id.resize(c + 1);
      id[c] = i;
    }
    ++c;
  }
};
int centroid;
struct Centroid {
  int c, sub;
  long long a, b;
};
vector<Centroid> centroids[MAXN];
vector<pair<long long, long long>> subtree[3];
FastHull hulls[MAXN][3];
void go(int x, int p = -1, long long da = 0, long long db = 0, int sub = -1) {
  centroids[x].push_back({centroid, sub, da, db});
  if (sub != -1) subtree[sub].push_back({da, db});
  int i = 0;
  for (auto e : E[x]) {
    int y = e.first;
    if (y == p) continue;
    go(y, x, da + A[e.second], db + B[e.second], sub == -1 ? i : sub);
    ++i;
  }
}
void decompose(int x) {
  getSizes(x);
  int c = findCentroid(x, siz[x]);
  centroid = c;
  go(c);
  int i = 0;
  for (auto e : E[c]) {
    int y = e.first;
    auto &lines = subtree[i];
    sort(lines.begin(), lines.end());
    FastHull hull(lines.size());
    for (auto &line : lines) {
      hull.insertLine(line.first, line.second);
    }
    subtree[i].clear();
    hulls[c][i++] = hull;
  }
  for (auto e : E[c]) {
    int y = e.first;
    for (auto it = E[y].begin();; ++it)
      if (it->first == c) {
        E[y].erase(it);
        break;
      }
    decompose(y);
  }
}
vector<pair<pair<long long, long long>, int>> lines1;
void dfs(int x, int p = -1, long long da = 0, long long db = 0) {
  lines1.push_back({{da, db}, x});
  for (auto e : E[x]) {
    int y = e.first;
    if (y == p) continue;
    dfs(y, x, da + A[e.second], db + B[e.second]);
  }
}
int N;
void makeDeg3Tree(int x, int p = -1) {
  int cur = x;
  int totch = 0;
  for (auto e : origE[x]) {
    int y = e.first, i = e.second;
    if (y == p) continue;
    makeDeg3Tree(y, x);
    ++totch;
  }
  for (auto e : origE[x]) {
    int y = e.first, i = e.second;
    if (y == p) continue;
    E[cur].push_back({y, i});
    E[y].push_back({cur, i});
    ++N;
    --totch;
    if (totch >= 2) {
      E[cur].push_back({N, N - 1});
      E[N].push_back({cur, N - 1});
      A[N] = B[N] = 0;
      cur = N;
    }
  }
}
int main() {
  int M;
  scanf("%d%d", &N, &M);
  for (int i = 1; i < N; ++i) {
    int x, y;
    scanf("%d%d%lld%lld", &x, &y, &A[i], &B[i]);
    origE[x].push_back({y, i});
    origE[y].push_back({x, i});
  }
  makeDeg3Tree(1);
  dfs(1);
  decompose(1);
  sort(lines1.begin(), lines1.end());
  FastHull hull1(lines1.size(), true);
  for (auto &line : lines1) {
    hull1.insertLine(line.first.first, line.first.second, line.second);
  }
  for (int x = 0; x < M; ++x) {
    long long d1 = hull1.monotonicQuery(x);
    int far = hull1.id[hull1.qpos];
    long long ans = 0;
    for (auto c : centroids[far]) {
      long long v2 = c.a * x + c.b;
      ans = max(ans, v2);
      for (int i = 0; i < 3; ++i) {
        auto &h = hulls[c.c][i];
        if (!h.c) continue;
        if (i == c.sub) continue;
        auto &hull = h;
        long long v = hull.monotonicQuery(x);
        ans = max(ans, v + v2);
      }
    }
    printf("%lld ", ans);
  }
}
