#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
long long add(long long x, long long y) {
  x += y;
  if (x >= MOD) return x - MOD;
  return x;
}
long long sub(long long x, long long y) {
  x -= y;
  if (x < 0) return x + MOD;
  return x;
}
long long mult(long long x, long long y) { return (x * y) % MOD; }
long long bin_pow(long long x, long long p) {
  if (p == 0) return 1;
  if (p & 1) return mult(x, bin_pow(x, p - 1));
  return bin_pow(mult(x, x), p / 2);
}
long long rev(long long x) { return bin_pow(x, MOD - 2); }
const int N = 100100;
int n;
vector<pair<int, int> > g[N];
long long a[N][2];
void dfs(int v, int par) {
  if ((int)g[v].size() == 1) {
    a[v][0] = a[v][1] = 0;
    return;
  }
  long long p = (int)g[v].size();
  long long q = 0;
  for (pair<int, int> e : g[v]) q = add(q, e.second);
  for (pair<int, int> e : g[v]) {
    int u = e.first;
    if (u == par) continue;
    dfs(u, v);
    p = sub(p, a[u][0]);
    q = add(q, a[u][1]);
  }
  if (p == 0) throw;
  p = rev(p);
  a[v][0] = p;
  a[v][1] = mult(q, p);
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int v, u, w;
    scanf("%d%d%d", &v, &u, &w);
    g[v].push_back(make_pair(u, w));
    g[u].push_back(make_pair(v, w));
  }
  for (pair<int, int> e : g[0]) dfs(e.first, 0);
  long long p = (int)g[0].size();
  long long q = 0;
  for (pair<int, int> e : g[0]) q = add(q, e.second);
  for (pair<int, int> e : g[0]) {
    int u = e.first;
    p = sub(p, a[u][0]);
    q = add(q, a[u][1]);
  }
  if (p == 0) throw;
  printf("%lld\n", mult(q, rev(p)));
  return 0;
}
