#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char ch = getchar();
  long long s = 0, w = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * w;
}
const int mod = 1e9 + 7;
int n;
vector<pair<int, int> > e[300010];
int A[300010], B[300010];
inline int ksm(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % mod;
    b >>= 1;
    a = 1LL * a * a % mod;
  }
  return ans;
}
void dfs(int u, int fa, int fv) {
  int sum = fv, suma = 0, sumb = 0, deg = (fa ? 1 : 0);
  for (auto tmp : e[u]) {
    int v = tmp.first, val = tmp.second;
    if (v == fa) continue;
    dfs(v, u, val);
    deg++;
    sum = (sum + val >= mod ? sum + val - mod : sum + val);
    suma = (suma + A[v] >= mod ? suma + A[v] - mod : suma + A[v]);
    sumb = (sumb + B[v] >= mod ? sumb + B[v] - mod : sumb + B[v]);
  }
  if (deg == 1 && fa) return;
  if (u > 1)
    A[u] = ksm(
        (deg + mod - suma >= mod ? deg + mod - suma - mod : deg + mod - suma),
        mod - 2);
  B[u] =
      1LL * (sum + sumb >= mod ? sum + sumb - mod : sum + sumb) *
      ksm((deg + mod - suma >= mod ? deg + mod - suma - mod : deg + mod - suma),
          mod - 2) %
      mod;
}
int main() {
  n = read();
  for (register int i = 1; i <= n - 1; i++) {
    int x = read() + 1, y = read() + 1, v = read();
    e[x].push_back(make_pair(y, v));
    e[y].push_back(make_pair(x, v));
  }
  dfs(1, 0, 0);
  printf("%d\n", B[1]);
  return 0;
}
