#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const long long P = 1000000007;
int n, cnt;
int fa[maxn], to[maxn << 1], nxt[maxn << 1], head[maxn], q[maxn], d[maxn];
long long k[maxn], b[maxn], f[maxn];
inline long long pm(long long x, long long y) {
  long long z = 1;
  while (y) {
    if (y & 1) z = z * x % P;
    x = x * x % P, y >>= 1;
  }
  return z;
}
inline void add(int a, int b) {
  to[cnt] = b, nxt[cnt] = head[a], head[a] = cnt++;
}
void dfs(int x) {
  q[++q[0]] = x;
  for (int i = head[x]; i != -1; i = nxt[i])
    if (to[i] != fa[x]) fa[to[i]] = x, dfs(to[i]);
}
inline int rd() {
  int ret = 0, f = 1;
  char gc = getchar();
  while (gc < '0' || gc > '9') {
    if (gc == '-') f = -f;
    gc = getchar();
  }
  while (gc >= '0' && gc <= '9') ret = ret * 10 + (gc ^ '0'), gc = getchar();
  return ret * f;
}
int main() {
  n = rd();
  int i, x, y, z;
  memset(head, -1, sizeof(head));
  for (i = 1; i < n; i++)
    x = rd() + 1, y = rd() + 1, z = rd(), add(x, y), add(y, x), k[x]++, k[y]++,
    d[x]++, d[y]++, b[x] += z, b[y] += z;
  dfs(1);
  for (i = n; i >= 2; i--)
    if (d[q[i]] != 1) {
      x = q[i];
      long long tmp = pm(k[x], P - 2);
      k[fa[x]] = (k[fa[x]] - tmp) % P;
      b[fa[x]] = (b[fa[x]] + b[x] * tmp) % P;
    }
  f[1] = b[1] * pm(k[1], P - 2) % P;
  printf("%lld", (f[1] + P) % P);
  return 0;
}
