#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const int N = 1e5 + 5;
using line = pair<ll, ll>;
using vline = vector<line>;
ll eval(const line& l, ll x) { return l.first * x + l.second; }
line operator+(const line& l1, const line& l2) {
  return {l1.first + l2.first, l1.second + l2.second};
}
line operator-(const line& l1, const line& l2) {
  return {l1.first - l2.first, l1.second - l2.second};
}
bool cmp(line l1, line l2, line l3, line l4) {
  if (l1.first < l2.first) swap(l1, l2);
  if (l3.first < l4.first) swap(l3, l4);
  return (__int128)(l2.second - l1.second) * (l3.first - l4.first) <=
         (__int128)(l4.second - l3.second) * (l1.first - l2.first);
}
void add_line(vline& v, line l) {
  int s = (int)(v).size();
  while (s >= 2 and cmp(v[s - 2], l, v[s - 2], v[s - 1])) v.pop_back(), s--;
  if (s and v[s - 1].first == l.first)
    v[s - 1].second = max(v[s - 1].second, l.second);
  else
    v.push_back(l);
}
vline add_hull(vline f, vline g) {
  if (f.empty() or g.empty()) return f.empty() ? g : f;
  vline h, v;
  add_line(h, f[0] + g[0]);
  int i = 1, j = 1;
  while (i < (int)(f).size() or j < (int)(g).size()) {
    if (i == (int)(f).size()) {
      add_line(h, f[i - 1] + g[j++]);
    } else if (j == (int)(g).size()) {
      add_line(h, f[i++] + g[j - 1]);
    } else {
      if (cmp(f[i - 1], f[i], g[j - 1], g[j])) {
        add_line(h, f[i++] + g[j - 1]);
      } else {
        add_line(h, f[i - 1] + g[j++]);
      }
    }
  }
  return h;
}
vline min_hull(vline f, vline g) {
  int i = 0, j = 0;
  vline h;
  while (i < (int)(f).size() and j < (int)(g).size()) {
    if (f[i].first < g[j].first)
      add_line(h, f[i++]);
    else
      add_line(h, g[j++]);
  }
  while (i < (int)(f).size()) add_line(h, f[i++]);
  while (j < (int)(g).size()) add_line(h, g[j++]);
  return h;
}
int n, first;
vi g[N];
int l[N], r[N];
line w[N];
line dis[N];
int tym = 0;
int what[2 * N], in[N];
void dfs(int u, int dad) {
  in[u] = ++tym;
  what[tym] = u;
  for (int i : g[u]) {
    int v = l[i] ^ r[i] ^ u;
    if (v != dad) {
      dis[v] = dis[u] + w[i];
      dfs(v, u);
      what[++tym] = u;
    }
  }
}
array<array<vline, 3>, 3> solve(int lo, int hi) {
  array<array<vline, 3>, 3> ret;
  if (lo == hi) {
    ret[0][0] = ret[2][2] = {dis[what[lo]]};
    ret[1][1] = {line(0, 0) - dis[what[lo]] - dis[what[lo]]};
    ret[0][1] = add_hull(ret[0][0], ret[1][1]);
    ret[1][2] = add_hull(ret[1][1], ret[2][2]);
    ret[0][2] = add_hull(ret[0][0], add_hull(ret[1][1], ret[2][2]));
    return ret;
  }
  int mid = (lo + hi) / 2;
  auto L = solve(lo, mid);
  auto R = solve(mid + 1, hi);
  for (int len = 1; len <= 3; ++len) {
    for (int i = 0, j = len - 1; j < 3; ++i, ++j) {
      for (int k = i; k <= j + 1; ++k) {
        vline le = k == i ? vline() : L[i][k - 1];
        vline ri = k > j ? vline() : R[k][j];
        ret[i][j] = min_hull(ret[i][j], add_hull(le, ri));
      }
    }
  }
  return ret;
}
int main(int argc, char const* argv[]) {
  scanf("%d %d", &n, &first);
  for (int i = 1; i < n; ++i) {
    int& u = l[i];
    int& v = r[i];
    line& ww = w[i];
    scanf("%d %d %lld %lld", &u, &v, &ww.first, &ww.second);
    g[u].emplace_back(i);
    g[v].emplace_back(i);
  }
  dfs(1, 0);
  42;
  vline f = solve(1, tym)[0][2];
  int ptr = 0;
  for (int i = 0; i < first; ++i) {
    while (ptr + 1 < (int)(f).size() and eval(f[ptr + 1], i) >= eval(f[ptr], i))
      ++ptr;
    printf("%lld ", eval(f[ptr], i));
  }
  puts("");
  return 0;
}
