#include <bits/stdc++.h>   using namespace std;   inline long long int read() {     char C = getchar();     long long int N = 0, F = 1;     while (( 0  > C || C >  9 ) && (C !=  - )) C = getchar();     if (C ==  - ) F = -1, C = getchar();     while ( 0  <= C && C <=  9 )       N = (N << 1) + (N << 3) + (C - 48), C = getchar();     return F * N;   }   long long int D[250005], NEXT[250005], ST[250005], LIM;   long long int F[250005][2], SUM[250005];   struct DQ {     priority_queue<long long int> A, B;     void push(long long int x) { A.push(x); }     void condense() {       while (A.size() && B.size() && A.top() == B.top()) {         A.pop();         B.pop();       }     }     void pop() {       condense();       A.pop();     }     long long int top() {       condense();       return A.top();     }     void del(long long int x) { B.push(x); }     long long int size() { return A.size() - B.size(); }   } H[250005];   bool vis[250005];   vector<long long int> VECD[250005];   vector<pair<long long int, long long int> > E[250005];   bool cmp(pair<long long int, long long int> A,            pair<long long int, long long int> B) {     return D[A.first] < D[B.first];   }   void dele(long long int wch) {     vis[wch] = true;     for (long long int i = ST[wch]; i < E[wch].size(); i++) {       if (vis[E[wch][i].first]) continue;       long long int to = E[wch][i].first, wei = E[wch][i].second;       H[to].push(wei);       SUM[to] += wei;     }   }   void upd(long long int wch, long long int num, vector<long long int>& cont) {     while (H[wch].size() > num) {       cont.push_back(H[wch].top());       SUM[wch] -= H[wch].top();       H[wch].pop();     }   }   void upd(long long int wch, long long int num) {     while (H[wch].size() > num) {       SUM[wch] -= H[wch].top();       H[wch].pop();     }   }   void dfs(long long int wch) {     long long int tot = 0, ned;     ned = D[wch] - LIM;     vector<long long int> DEL, ADD;     upd(wch, ned);     vis[wch] = true;     while (ST[wch] < E[wch].size() && D[E[wch][ST[wch]].first] <= LIM) ST[wch]++;     for (long long int i = ST[wch]; i < E[wch].size(); i++) {       long long int to = E[wch][i].first, wei = E[wch][i].second;       if (vis[to]) continue;       dfs(to);       if (F[to][0] + wei <= F[to][1]) {         tot += F[to][0] + wei;         ned--;       } else {         long long int c = F[to][0] + wei - F[to][1];         tot += F[to][1];         DEL.push_back(c);         H[wch].push(c);         SUM[wch] += c;       }     }     upd(wch, max(ned, (long long int)0), ADD);     F[wch][1] = tot + SUM[wch];     upd(wch, max((long long int)0, ned - 1), ADD);     F[wch][0] = tot + SUM[wch];     for (long long int i = 0; i < ADD.size(); i++)       H[wch].push(ADD[i]), SUM[wch] += ADD[i];     for (long long int i = 0; i < DEL.size(); i++)       H[wch].del(DEL[i]), SUM[wch] -= DEL[i];   }   int main() {     long long int N, ans = 0;     N = read();     for (long long int i = 1; i < N; i++) {       long long int a, b, c;       a = read(), b = read(), c = read();       D[a]++, D[b]++;       E[a].push_back({b, c});       E[b].push_back({a, c});       ans += c;     }     printf( %I64d , ans);     for (long long int i = 1; i <= N; i++) {       sort(E[i].begin(), E[i].end(), cmp);       VECD[D[i]].push_back(i);     }     NEXT[N - 1] = N;     for (long long int i = N - 2; i >= 1; i--) {       if (VECD[i + 1].size())         NEXT[i] = i + 1;       else         NEXT[i] = NEXT[i + 1];     }     for (LIM = 1; LIM < N; LIM++) {       for (long long int j = 0; j < VECD[LIM].size(); j++) dele(VECD[LIM][j]);       long long int sum = 0;       for (long long int j = LIM + 1; j < N; j = NEXT[j]) {         for (long long int k = 0; k < VECD[j].size(); k++) {           if (vis[VECD[j][k]]) continue;           dfs(VECD[j][k]);           sum += F[VECD[j][k]][1];         }       }       printf(  %I64d , sum);       for (long long int j = LIM + 1; j < N; j = NEXT[j])         for (long long int k = 0; k < VECD[j].size(); k++)           vis[VECD[j][k]] = false;     }     return 0;   }