#include <bits/stdc++.h>
using namespace std;
int n, x, y, c, a[100010], b[100010];
vector<int> V[100010];
int rever(int x, int y) {
  if (x == 1) return 1;
  int t = y / x;
  int r = y % x;
  int s = rever(r, x);
  s = x - s;
  return (1LL * t * s % y + (1LL * r * s + 1) / x) % y;
}
void calc(int v, int par) {
  int d = V[v].size(), sa = 0, sb = 0;
  if (d == 1) {
    a[v] = 0;
    b[v] = 0;
    return;
  }
  for (int i = 0; i < d; i++) {
    int vv = V[v][i] / 10010;
    int cc = V[v][i] % 10010;
    if (vv == par) {
      sb += cc;
      sb %= 1000000007;
    } else {
      calc(vv, v);
      sa += a[vv];
      sa %= 1000000007;
      sb += (cc + b[vv]);
      sb %= 1000000007;
    }
  }
  a[v] = rever((d + 1000000007 - sa) % 1000000007, 1000000007);
  b[v] = 1LL * a[v] * sb % 1000000007;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &c);
    V[x].push_back(y * 10010 + c);
    V[y].push_back(x * 10010 + c);
  }
  calc(0, -1);
  printf("%d", b[0]);
}
