#include <bits/stdc++.h>
using namespace std;
inline int in() {
  char ch = getchar();
  int f = 1, x = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  return f * x;
}
const int inf = (1 << 30);
const int mod = 1e9 + 7;
const int N = 100010;
int n, m, dfn, id[N], fa[N];
long long d[N], k[N], b[N];
vector<int> e[N];
long long ksm(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
long long inv(long long x) { return ksm(x, mod - 2); }
void dfs(int u, int F) {
  id[++dfn] = u;
  for (auto v : e[u])
    if (v != F) dfs(v, fa[v] = u);
}
int main() {
  n = in();
  for (int i = 2; i <= n; i++) {
    int u = in() + 1, v = in() + 1, z = in();
    e[u].push_back(v);
    e[v].push_back(u);
    k[u]++, k[v]++;
    b[u] += z, b[v] += z;
  }
  for (int i = 1; i <= n; i++) d[i] = k[i];
  dfs(1, 1);
  for (int i = n; i >= 1; i--) {
    int x = id[i];
    if (d[x] == 1) continue;
    k[fa[x]] = (k[fa[x]] - inv(k[x])) % mod;
    b[fa[x]] = (b[fa[x]] + b[x] * inv(k[x])) % mod;
  }
  k[1] = (k[1] + mod) % mod;
  b[1] = (b[1] + mod) % mod;
  b[1] = (b[1] * inv(k[1])) % mod;
  printf("%lld\n", b[1]);
  return 0;
}
