#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mod = 1000000007;
struct E {
  int to, next, w;
} mem[N << 1];
int num, n, x, y, w, ans;
int head[N], d[N], bb[N], kk[N], uw[N];
void add(int x, int y, int w) {
  num++;
  mem[num].to = y;
  mem[num].next = head[x];
  mem[num].w = w;
  head[x] = num;
}
int quickpow(int x, int y) {
  int s = 1;
  for (; y; y >>= 1, x = 1ll * x * x % mod)
    if (y & 1) s = 1ll * s * x % mod;
  return s;
}
void dfs(int k, int pre) {
  int j, u;
  if (d[k] == 1 && k > 1) {
    kk[k] = bb[k] = 0;
    return;
  }
  bb[k] = uw[k];
  kk[k] = d[k];
  for (j = head[k]; j; j = mem[j].next) {
    u = mem[j].to;
    if (u == pre) continue;
    uw[u] = mem[j].w;
    dfs(u, k);
    kk[u] = quickpow(kk[u], mod - 2);
    (kk[k] -= kk[u]) %= mod;
    (bb[k] += (1ll * bb[u] * kk[u] % mod + mem[j].w) % mod) %= mod;
  }
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &w);
    x++;
    y++;
    add(x, y, w);
    add(y, x, w);
    d[x]++;
    d[y]++;
  }
  dfs(1, 0);
  ans = (1ll * bb[1] * quickpow(kk[1], mod - 2) % mod + mod) % mod;
  printf("%d\n", ans);
  return 0;
}
