func_code_string: #include <bits/stdc++.h>   using namespace std;   void Read(int &p) {     p = 0;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) p = p * 10 + c -  0 ;   }   struct ma {     int x, y;     ma(int _x = 0, int _y = 0) : x(_x), y(_y) {}   };   bool operator<(ma a, ma b) { return a.x < b.x; }   priority_queue<ma> q[100005], Q, _q;   int n, m, x, y, z, rot, mi = 1e9, si[100005], nm = 0, be[100005];   int fir[100005], tar[200005], len[200005], nex[200005], cnt;   long long ans1;   void Add(int a, int b, int c) {     ++cnt;     tar[cnt] = b;     len[cnt] = c;     nex[cnt] = fir[a];     fir[a] = cnt;   }   int Dfs(int r, int fa) {     int sz = 1, mx = 0;     for (int i = fir[r]; i; i = nex[i]) {       int v = tar[i];       if (v != fa) {         int sum = Dfs(v, r);         mx = max(mx, sum);         sz += sum;         ans1 += (long long)len[i] * min(sum, n - sum);       }     }     mx = max(mx, n - sz);     if (mx < mi) rot = r, mi = mx;     return sz;   }   void DFS(int x, int fa, int d) {     q[d].push(ma{-x, d});     si[d]++;     be[x] = d;     for (int i = fir[x]; i; i = nex[i])       if (tar[i] != fa) DFS(tar[i], x, d);   }   int work(int u) {     while (_q.top().x != q[_q.top().y].top().x || q[_q.top().y].empty()) _q.pop();     ma o;     if (_q.top().y == u) o = _q.top(), _q.pop();     while (_q.top().x != q[_q.top().y].top().x || q[_q.top().y].empty()) _q.pop();     u = _q.top().y;     if (o.x) _q.push(o);     return u;   }   int main() {     Read(n);     if (n == 1) {       printf( 0 n1 n );       return 0;     }     for (int i = 1; i < n; i++) {       int u, v, w;       Read(u), Read(v), Read(w);       Add(u, v, w), Add(v, u, w);     }     Dfs(1, 0);     q[0].push(ma{-rot, 0});     _q.push(ma{-rot, 0});     si[0] = 1;     for (int i = fir[rot]; i; i = nex[i]) {       DFS(tar[i], rot, ++nm);       Q.push(ma{si[nm] << 1, nm});       _q.push(ma(q[nm].top().x, nm));     }     printf( %lld n , ans1 << 1);     for (int i = 1; i <= n; i++) {       while (Q.top().x != si[Q.top().y] + q[Q.top().y].size()) Q.pop();       if (be[i] == Q.top().y || Q.top().x < n - i + 1)         m = work(be[i]);       else         m = Q.top().y;       if (i == rot && -q[m].top().x > rot && !q[0].empty() &&           Q.top().x < n - i + 1)         m = 0;       printf( %d  , -q[m].top().x);       q[m].pop();       si[be[i]]--;       if (!q[m].empty()) _q.push(ma(q[m].top().x, m));       Q.push(ma(si[m] + q[m].size(), m));       Q.push(ma(si[be[i]] + q[be[i]].size(), be[i]));     }   }   