#include <bits/stdc++.h>
using namespace std;
long long h[200005], k[200005], b[200005], cnt, dg[200005], ru[200005], n;
struct l1 {
  long long to, next, v;
} p[400005];
void add(long long x, long long y, long long v) {
  cnt++;
  p[cnt].to = y;
  p[cnt].next = h[x];
  h[x] = cnt;
  p[cnt].v = v;
}
long long ksm(long long x, long long y) {
  long long anss = 1, t = x;
  while (y) {
    if (y & 1) anss = anss * t % 1000000007;
    t = t * t % 1000000007;
    y >>= 1;
  }
  return anss;
}
void dfs(long long x, long long fa) {
  if (dg[x] == 1 && x != 1) return;
  long long totk = 0, totb = 0;
  for (long long i = h[x]; i; i = p[i].next) {
    long long y = p[i].to;
    if (y == fa) continue;
    dfs(y, x);
    totk = (totk + k[y]) % 1000000007;
    totb = (totb + b[y]) % 1000000007;
  }
  k[x] = ksm(dg[x] - totk + 1000000007, 1000000007 - 2);
  b[x] = k[x] * (totb + ru[x]) % 1000000007;
}
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i < n; i++) {
    long long x, y, v;
    scanf("%lld%lld%lld", &x, &y, &v);
    x++;
    y++;
    ru[x] += v;
    ru[y] += v;
    dg[x]++;
    dg[y]++;
    add(x, y, v);
    add(y, x, v);
  }
  dfs(1, 0);
  printf("%lld", b[1]);
}
