func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, e = 0, st[100005], d[100005], T[100005], s[100005], Time;   struct Node {     int v, t;     double p;   };   struct {     int v, t, nx;   } edge[200005];   vector<Node> E[100005];   bool cmp(Node a, Node b) { return a.p < b.p; }   void add(int u, int v, int t) {     edge[e].v = v;     edge[e].t = t;     edge[e].nx = st[u];     st[u] = e++;   }   void dfs(int u, int fa, int t) {     s[u] = 1;     d[u] = 2 * t;     for (int i = st[u]; ~i; i = edge[i].nx) {       int v = edge[i].v;       if (v != fa) {         Node tmp;         t = edge[i].t;         tmp.v = v;         tmp.t = t;         E[u].push_back(tmp);         dfs(v, u, t);         s[u] += s[v];         d[u] += d[v];       }     }   }   void Dfs(int u) {     int m = E[u].size();     for (int i = 0; i < m; i++)       E[u][i].p = (double)d[E[u][i].v] / (double)s[E[u][i].v];     sort(E[u].begin(), E[u].end(), cmp);     for (int i = 0; i < m; i++) {       int v = E[u][i].v;       int t = E[u][i].t;       Time += t;       T[v] = Time;       Dfs(v);       Time += t;     }   }   int main() {     while (~scanf( %d , &n)) {       e = 0;       memset(st, -1, sizeof(st));       int a, b, t;       for (int i = 1; i < n; i++) {         scanf( %d%d%d , &a, &b, &t);         add(a, b, t);         add(b, a, t);       }       dfs(1, -1, 0);       Time = 0;       Dfs(1);       double ans = 0;       for (int i = 2; i <= n; i++) ans += 1.0 * T[i];       printf( %.12f n , ans / 1.0 / (n - 1));     }   }   