func_code_string: #include <bits/stdc++.h>   using namespace std;   int N;   vector<int> graph[100010];   int deg[100010];   int sum[100010];   long long dpa[100010], dpb[100010];   long long power(long long x, long long n) {     if (n == 0) return 1;     long long y = power(x, n / 2);     y = y * y % 1000000007ll;     if (n % 2 == 1) y = y * x % 1000000007ll;     return y;   }   void dfs(int p, int x) {     int i;     if (deg[x] == 1) {       dpa[x] = dpb[x] = 0;       return;     }     long long A = 0, B = 0;     int K = 0;     for ((i) = 0; (i) < (int)(graph[x].size()); (i)++) {       int y = graph[x][i];       if (y == p) continue;       K++;       dfs(x, y);       A = (A + dpa[y]) % 1000000007ll;       B = (B + dpb[y]) % 1000000007ll;     }     int K2 = K + 1;     if (x == 0) K2--;     dpa[x] = power((K2 - A + 1000000007ll) % 1000000007ll, 1000000007ll - 2);     dpb[x] = (B + sum[x]) * dpa[x] % 1000000007ll;   }   int main(void) {     int i;     cin >> N;     for ((i) = 0; (i) < (int)(N - 1); (i)++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       graph[a].push_back(b);       graph[b].push_back(a);       deg[a]++;       deg[b]++;       sum[a] += c;       sum[b] += c;     }     dfs(-1, 0);     cout << dpb[0] << endl;     return 0;   }   