// #include "jumps.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
// #define int long long
// #define int unsigned long long
// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
void open_file(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
// const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 2 * 1e5 + 25;
ll dp[maxN][2];
vector<pii> g[maxN];
void dfs(int v, int x, int k, int par = -1) {
dp[v][x] = 0;
vector<ll> t;
for (pii u : g[v]) {
if (u.ff == par) {
if (x) dp[v][x] += u.sc;
continue;
}
dfs(u.ff, 0, k, v);
dfs(u.ff, 1, k, v);
dp[v][x] += dp[u.ff][0];
t.pb(dp[u.ff][1] - dp[u.ff][0]);
} sort(all(t));
for (int i = 0; i < n && t[i] < 0; i++)
if (i < k - x) dp[v][x] += t[i];
}
vector<ll> minimum_closure_costs(int n, vector<int> u, vector<int> v, vector<int> w) {
vector<ll> ans; ans.pb(0);
for (int i = 0; i < n - 1; i++) {
ans[0] += w[i];
g[u[i]].pb({v[i], w[i]});
g[v[i]].pb({u[i], w[i]});
} for (int i = 1; i < n; i++) {
dfs(0, 0, i); ans.pb(dp[0][0]);
} return ans;
}
// int main() {
// int N;
// assert(1 == scanf("%d", &N));
// std::vector<int> U(N - 1), V(N - 1), W(N - 1);
// for (int i = 0; i < N - 1; ++i) {
// assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i]));
// }
// std::vector<long long> closure_costs = minimum_closure_costs(N, U, V, W);
// for (int i = 0; i < static_cast<int>(closure_costs.size()); ++i) {
// if (i > 0) {
// printf(" ");
// }
// printf("%lld",closure_costs[i]);
// }
// printf("\n");
// return 0;
// }