#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 10;
const int N = 3e5 + 10;
const int maxn = 3020;
const long long mod = 1e9 + 7;
struct node {
  int next, to;
} e[N * 2];
int head[N], cnt;
int deg[N], sumw[N], n;
pair<long long, long long> f[N];
inline void adde(int x, int y) {
  e[++cnt].to = y;
  e[cnt].next = head[x];
  head[x] = cnt;
}
inline long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
void dfs(int x, int fa) {
  if (deg[x] == 1) return;
  long long a = 0, b = 0;
  for (register int i = head[x]; i; i = e[i].next) {
    if (e[i].to == fa) continue;
    dfs(e[i].to, x);
    a += f[e[i].to].first, b += f[e[i].to].second;
  }
  f[x].first = power(deg[x] - a % mod + mod, mod - 2);
  f[x].second =
      power(deg[x] - a % mod + mod, mod - 2) * ((b + sumw[x]) % mod) % mod;
}
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n - 1; i++) {
    int x, y, w;
    scanf("%d %d %d", &x, &y, &w), x++, y++;
    adde(x, y), adde(y, x);
    sumw[x] += w, sumw[y] += w;
    deg[x]++, deg[y]++;
  }
  dfs(1, 0);
  printf("%lld\n", f[1].second);
}
