#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[100005];
int mod = 1e9 + 7;
long long f_pow(long long a, long long b) {
  long long res = 1, temp = a;
  while (b) {
    if (b & 1) res = res * temp % mod;
    temp = temp * temp % mod;
    b >>= 1;
  }
  return res;
}
pair<long long, long long> dfs(int first, int f) {
  pair<long long, long long> p = make_pair(0, 0);
  if (v[first].size() == 1) return p;
  for (auto it : v[first]) {
    if (it.first != f) {
      pair<long long, long long> pp = dfs(it.first, first);
      p.first += pp.first;
      p.second += pp.second;
    }
    p.second += it.second;
  }
  p.first %= mod;
  p.second %= mod;
  p.first = p.first * f_pow(v[first].size(), mod - 2) % mod;
  p.second = p.second * f_pow(v[first].size(), mod - 2) % mod;
  pair<long long, long long> res =
      make_pair(f_pow(v[first].size(), mod - 2), p.second);
  if (first == 0) {
    res.first = p.first;
    return res;
  }
  long long val = f_pow((1 - p.first + mod) % mod, mod - 2);
  res.first = res.first * val % mod;
  res.second = res.second * val % mod;
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int first, second, c;
    scanf("%d %d %d", &first, &second, &c);
    v[first].push_back(make_pair(second, c));
    v[second].push_back(make_pair(first, c));
  }
  pair<int, int> p = dfs(0, 0);
  printf("%lld\n", f_pow((1 - p.first + mod) % mod, mod - 2) * p.second % mod);
}
