func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, u, v, c, a[100005], b[100005];   vector<int> adj[100005];   int mod_pow(int a, int b) {     int rtn = 1;     while (b) {       if (b & 1) rtn = (1ll * rtn * a) % 1000000007;       a = 1ll * a * a % 1000000007;       b /= 2;     }     return rtn;   }   void dfs(int vtx, int p) {     if (adj[vtx].size() == 1 && vtx) return;     for (int i = 0; i < adj[vtx].size(); i++) {       int u = adj[vtx][i] / 10005, w = adj[vtx][i] % 10005;       b[vtx] = (b[vtx] + w) % 1000000007;       if (u == p) continue;       dfs(u, vtx);       a[vtx] = (a[vtx] + a[u]) % 1000000007,       b[vtx] = (1ll * b[vtx] + b[u]) % 1000000007;     }     a[vtx] = mod_pow((adj[vtx].size() - a[vtx] + 1000000007) % 1000000007,                      1000000007 - 2);     b[vtx] = (1ll * a[vtx] * b[vtx]) % 1000000007;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       scanf( %d %d %d , &u, &v, &c);       adj[u].push_back(v * 10005 + c);       adj[v].push_back(u * 10005 + c);     }     dfs(0, -1);     printf( %d , b[0]);   }   