#include <bits/stdc++.h>
using namespace std;
int head[100050], to[100050 << 1], nxt[100050 << 1], du[100050],
    val[100050 << 1], cnt, n;
long long K[100050], B[100050], dis[100050];
inline void add(int u, int v, int w) {
  to[++cnt] = v;
  nxt[cnt] = head[u];
  head[u] = cnt;
}
long long qp(long long x, long long y) {
  long long re = 1;
  for (; y; y >>= 1, x = x * x % 1000000007)
    if (y & 1) re = re * x % 1000000007;
  return re;
}
long long INV(long long x) { return qp(x, 1000000007 - 2); }
void dfs(int x, int y) {
  int i;
  if (x != 1 && du[x] == 1) return;
  K[x] = du[x];
  B[x] = dis[x];
  for (i = head[x]; i; i = nxt[i])
    if (to[i] != y) {
      dfs(to[i], x);
      K[x] = (K[x] - INV(K[to[i]])) % 1000000007;
      B[x] = (B[x] + B[to[i]] * INV(K[to[i]])) % 1000000007;
    }
}
int main() {
  scanf("%d", &n);
  int i, x, y, z;
  for (i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    x++;
    y++;
    add(x, y, z);
    add(y, x, z);
    du[x]++;
    du[y]++;
    dis[x] = (dis[x] + z) % 1000000007;
    dis[y] = (dis[y] + z) % 1000000007;
  }
  dfs(1, 0);
  printf("%lld\n", (B[1] * INV(K[1]) % 1000000007 + 1000000007) % 1000000007);
}
