#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1000000007;
int n, du[100010], sum[100010];
long long dpa[100010], dpb[100010];
int cnt, head[100010], to[200010], nxt[200010];
void add(int x, int y) {
  cnt++;
  to[cnt] = y;
  nxt[cnt] = head[x];
  head[x] = cnt;
}
long long pw(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) {
      res = res * x % Mod;
    }
    y >>= 1;
    x = x * x % Mod;
  }
  return res;
}
void dfs(int x, int fa) {
  if (du[x] == 1) {
    dpa[x] = dpb[x] = 0;
    return;
  }
  long long a = 0, b = 0;
  int k = 0;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa) {
      continue;
    }
    k++;
    dfs(y, x);
    a = (a + dpa[y]) % Mod;
    b = (b + dpb[y]) % Mod;
  }
  if (x) {
    k++;
  }
  dpa[x] = pw((k - a + Mod) % Mod, Mod - 2);
  dpb[x] = (b + sum[x]) * dpa[x] % Mod;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    add(x, y);
    add(y, x);
    du[x]++;
    du[y]++;
    sum[x] += z;
    sum[y] += z;
  }
  dfs(0, -1);
  cout << dpb[0] << endl;
  return 0;
}
