#include <bits/stdc++.h>
using namespace std;
int n;
int m;
struct st {
  int go;
  long long int a;
  long long int b;
  st() {
    go = -1;
    a = 0;
    b = 0;
  }
  st(int a_, long long int b_, long long int c_) {
    go = a_;
    a = b_;
    b = c_;
  }
};
vector<st> v[300002];
vector<st> g[300002];
int lim;
st p[300002];
inline void trans(int b, int pr = -1) {
  if (pr == -1) {
    lim = n;
  }
  for (int j = 0; j < v[b].size(); j++) {
    if (v[b][j].go == pr) continue;
    if (g[b].size() == 2) {
      swap(g[b], g[lim]);
      lim++;
      g[b].push_back({lim - 1, 0, 0});
    }
    g[b].push_back(v[b][j]);
  }
  for (int j = 0; j < v[b].size(); j++) {
    if (v[b][j].go == pr) continue;
    trans(v[b][j].go, b);
  }
}
bool used[300002];
int dp[300002];
pair<int, int> cent(int b, int whole, int pr = -1) {
  pair<int, int> ret = make_pair(INT_MAX, -1);
  dp[b] = 1;
  int deg = 0;
  for (int i = 0; i < g[b].size(); i++) {
    int go = g[b][i].go;
    if (go == pr) continue;
    if (used[go]) continue;
    ret = min(ret, cent(go, whole, b));
    dp[b] += dp[go];
    deg = max(deg, dp[go]);
  }
  deg = max(deg, whole - dp[b]);
  ret = min(ret, make_pair(deg, b));
  return ret;
}
struct line {
  long long int a;
  long long int b;
  line(long long int A = 0, long long int B = 0) {
    a = A;
    b = B;
  }
  long long int at(long long int x) { return a * x + b; }
};
inline bool enu(int b, vector<line> &lis, int pr = -1,
                line propagate = line()) {
  bool leaf = true;
  for (int i = 0; i < g[b].size(); i++) {
    int go = g[b][i].go;
    if (go == pr) continue;
    if (used[go]) continue;
    leaf = false;
    propagate.a += g[b][i].a;
    propagate.b += g[b][i].b;
    enu(go, lis, b, propagate);
    propagate.a -= g[b][i].a;
    propagate.b -= g[b][i].b;
  }
  if (leaf) lis.emplace_back(propagate);
  return true;
}
vector<line> all;
bool cmp(line a, line b) {
  if (a.a == b.a) {
    return a.b < b.b;
  }
  return a.a < b.a;
}
vector<line> v2;
void clean(vector<line> &v1) {
  v2.clear();
  sort(v1.begin(), v1.end(), cmp);
  for (int i = 0; i < v1.size(); i++) {
    while (v2.size()) {
      if (v2.back().a == v1[i].a) {
        v2.pop_back();
        continue;
      }
      if (v2.size() > 1) {
        auto a = v2[v2.size() - 2];
        auto b = v2[v2.size() - 1];
        auto c = v1[i];
        if ((c.b - a.b) * (a.a - b.a) <= (b.b - a.b) * (a.a - c.a)) {
          v2.pop_back();
          continue;
        }
      }
      break;
    }
    v2.push_back(v1[i]);
  }
  v1 = v2;
}
inline void init(int b) {
  cent(b, -1);
  b = cent(b, dp[b]).second;
  used[b] = true;
  vector<vector<line> > vv;
  for (int i = 0; i < g[b].size(); i++) {
    if (used[g[b][i].go]) continue;
    vv.push_back(vector<line>());
    if (!enu(g[b][i].go, vv.back(), b, line(g[b][i].a, g[b][i].b)))
      vv.pop_back();
  }
  while (1) {
    if (vv.size() == 0) break;
    if (vv.size() == 1) {
      for (auto el : vv[0]) {
        all.push_back(el);
      }
      vv.clear();
      break;
    }
    for (int i = 0; i < vv.size(); i++) {
      clean(vv[i]);
    }
    for (int i1 = 0; i1 < vv.size(); i1++) {
      for (int j1 = i1 + 1; j1 < vv.size(); j1++) {
        int i = 0;
        int j = 0;
        while (i < vv[i1].size() && j < vv[j1].size()) {
          all.push_back(
              line(vv[i1][i].a + vv[j1][j].a, vv[i1][i].b + vv[j1][j].b));
          if (i == vv[i1].size() - 1 && j == vv[j1].size() - 1) break;
          if (i == vv[i1].size() - 1) {
            j++;
            continue;
          }
          if (j == vv[j1].size() - 1) {
            i++;
            continue;
          }
          if (vv[i1][i].a == vv[i1][i + 1].a) {
            i++;
            continue;
          }
          if (vv[j1][j].a == vv[j1][j + 1].a) {
            j++;
            continue;
          }
          if ((vv[i1][i + 1].b - vv[i1][i].b) *
                  (vv[j1][j].a - vv[j1][j + 1].a) <=
              (vv[i1][i].a - vv[i1][i + 1].a) *
                  (vv[j1][j + 1].b - vv[j1][j].b)) {
            i++;
          } else {
            j++;
          }
        }
      }
    }
    break;
  }
  for (int i = 0; i < g[b].size(); i++) {
    if (used[g[b][i].go] == false) {
      init(g[b][i].go);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int a, b;
    long long int c, d;
    scanf("%d%d%lld%lld", &a, &b, &c, &d);
    a--;
    b--;
    v[a].push_back(st(b, c, d));
    v[b].push_back(st(a, c, d));
  }
  trans(0);
  n = lim;
  for (int i = 0; i < n; i++) p[i].go = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      p[g[i][j].go] = g[i][j];
      p[g[i][j].go].go = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (p[i].go == -1) continue;
    g[i].push_back(p[i]);
  }
  init(0);
  int idx = 0;
  all.push_back(line());
  clean(all);
  for (int t = 0; t <= m - 1; t++) {
    if (t) {
      printf(" ");
    }
    long long int mx = 0;
    int pos = -1;
    while (idx + 1 < all.size() && all[idx].at(t) <= all[idx + 1].at(t)) {
      idx++;
    }
    printf("%lld", all[idx].at(t));
  }
  puts("");
  return 0;
}
