#include <bits/stdc++.h>   using namespace std;   long long read() {     char x = getchar();     long long ans = 0;     while (!isdigit(x)) x = getchar();     while (isdigit(x)) ans = ans * 10 + x -  0 , x = getchar();     return ans;   }   long long in[250005], now, n, vis[250005], dp[250005][2];   vector<pair<long long, long long> > E[250005];   void add_edge(long long u, long long v, long long w) {     E[u].push_back(make_pair(v, w));   }   bool cmp(pair<long long, long long> x, pair<long long, long long> y) {     return in[x.first] > in[y.first];   }   struct node {     long long siz, sum;     priority_queue<long long> q1, q2;     void pop(long long x) {       q2.push(x);       siz--;       sum -= x;     }     void push(long long x) {       q1.push(x);       siz++;       sum += x;     }     void init() {       while (!q1.empty() && !q2.empty() && q1.top() == q2.top())         q1.pop(), q2.pop();     }     void pop() {       init();       siz--;       sum -= q1.top();       q1.pop();     }     long long top() {       init();       return q1.top();     }   } P[250005];   void erase(long long u) {     for (long long i = 0; i < E[u].size(); i++) {       long long v = E[u][i].first, w = E[u][i].second;       if (in[v] <= now) break;       P[v].push(w);     }   }   void dfs(long long u, long long pre) {     vis[u] = now;     long long tot = 0;     long long num = in[u] - now;     while (P[u].siz > num) P[u].pop();     for (long long i = 0; i < E[u].size(); i++) {       long long v = E[u][i].first, w = E[u][i].second;       if (in[v] <= now) break;       if (v == pre) continue;       dfs(v, u);     }     vector<long long> tmp1, tmp2;     for (long long i = 0; i < E[u].size(); i++) {       long long v = E[u][i].first, w = E[u][i].second;       if (v == pre) continue;       if (in[v] <= now) break;       long long tmp = dp[v][1] + w - dp[v][0];       if (tmp <= 0) {         num--, tot += dp[v][1] + w;         continue;       }       tot += dp[v][0];       P[u].push(tmp), tmp2.push_back(tmp);     }     while (P[u].siz && P[u].siz > num) {       tmp1.push_back(P[u].top());       P[u].pop();     }     dp[u][0] = tot + P[u].sum;     while (P[u].siz && P[u].siz > num - 1) {       tmp1.push_back(P[u].top());       P[u].pop();     }     dp[u][1] = tot + P[u].sum;     for (long long i = 0; i < tmp1.size(); i++) P[u].push(tmp1[i]);     for (long long i = 0; i < tmp2.size(); i++) P[u].pop(tmp2[i]);   }   signed main() {     cin >> n;     long long tot = 0;     for (long long i = 1; i < n; i++) {       long long u = read(), v = read(), w = read();       add_edge(u, v, w);       add_edge(v, u, w);       tot += w;     }     cout << tot <<    ;     for (long long i = 1; i <= n; i++) in[i] = E[i].size();     for (long long i = 1; i <= n; i++) sort(E[i].begin(), E[i].end(), cmp);     vector<pair<long long, long long> > V;     for (long long i = 1; i <= n; i++) V.push_back(make_pair(in[i], i));     sort(V.begin(), V.end());     long long pos = 0;     for (now = 1; now < n; now++) {       while (pos < V.size() && V[pos].first == now) erase(V[pos].second), pos++;       tot = 0;       for (long long j = pos; j < V.size(); j++) {         if (vis[V[j].second] == now) continue;         dfs(V[j].second, 0);         tot += dp[V[j].second][0];       }       cout << tot <<    ;     }   }