#include <bits/stdc++.h>
using namespace std;
const int maxn = 100009;
const int mod = 1e9 + 7;
int first[maxn], du[maxn];
struct edg {
  int next, to;
  long long val;
} e[maxn << 1];
long long f[maxn], g[maxn];
int n, e_sum;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void update(long long &x, long long y) {
  x += y;
  x %= mod;
}
void add_edg(int x, int y, int z) {
  e_sum++;
  e[e_sum].next = first[x];
  first[x] = e_sum;
  e[e_sum].to = y;
  e[e_sum].val = z;
}
long long qpow(long long x, int y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
long long inv(long long x) { return qpow(x, mod - 2); }
void dfs(int x, int fa) {
  long long p = 0, q = 0, tmp = inv(du[x]);
  bool leaf = 1;
  for (int i = first[x]; i; i = e[i].next) {
    int w = e[i].to;
    update(q, e[i].val);
    if (w == fa) continue;
    leaf = 0;
    dfs(w, x);
    update(p, f[w]);
    update(q, g[w]);
  }
  if (leaf) return;
  p = p * tmp % mod;
  q = q * tmp % mod;
  p = inv((1 - p + mod) % mod);
  f[x] = tmp * p % mod;
  g[x] = q * p % mod;
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read() + 1, y = read() + 1, z = read();
    add_edg(x, y, z);
    add_edg(y, x, z);
    du[x]++;
    du[y]++;
  }
  dfs(1, 0);
  cout << g[1] << endl;
  return 0;
}
