func_code_string: #include <bits/stdc++.h>   using namespace std;   struct edge {     int to, cost;     edge(int to = 0, int cost = 0) : to(to), cost(cost) {}   };   vector<edge> vec[100005];   long long int F[100005], G[100005];   int nd[100005];   int n;   long long int mpow(long long int m, long long int t) {     if (t == 0) return 1LL;     long long int ret = mpow(m * m % 1000000007, t / 2);     if (t % 2 == 1) ret = ret * m % 1000000007;     return ret;   }   long long int inv(long long int m) { return mpow(m, 1000000007 - 2); }   void dfs(int v = 0, int p = -1) {     if (vec[v].size() == 1) {       F[v] = G[v] = 0;       return;     }     long long int sumG = 0, sumF = vec[v].size();     for (int i = 0; i < vec[v].size(); i++) {       edge e = vec[v][i];       sumG += e.cost;       if (sumG >= 1000000007) sumG -= 1000000007;       if (e.to != p) {         dfs(e.to, v);         sumG += G[e.to];         if (sumG >= 1000000007) sumG -= 1000000007;         sumF -= F[e.to];         if (sumF < 0) sumF += 1000000007;       }     }     long long int g = inv(sumF);     F[v] = g;     G[v] = g * sumG % 1000000007;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       vec[a].push_back(edge(b, c));       vec[b].push_back(edge(a, c));     }     dfs();     printf( %lld n , G[0]);     return 0;   }   