#include <bits/stdc++.h>
using namespace std;
const int L = 1 << 19;
char ibuf[L], *ie = ibuf + L, *ip = ie - 1;
inline char nc(void) {
  if (++ip == ie)
    if (fread(ip = ibuf, 1, L, stdin))
      ;
  return *ip;
}
inline int read(void) {
  char opt;
  int flag = 1, res = 0;
  while ((opt = nc()) < '0')
    if (opt == '-') flag = -1;
  while (opt >= '0') {
    res = (res << 3) + (res << 1) + opt - '0';
    opt = nc();
  }
  return res * flag;
}
int n, f[100001], b[100001], k[100001];
struct Edge {
  int to, v;
};
vector<Edge> g[100001];
inline int Mod(int x) { return x >= 1000000007 ? x - 1000000007 : x; }
inline int qpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % 1000000007;
    a = 1ll * a * a % 1000000007;
    b >>= 1;
  }
  return res;
}
inline void dfs(int x, int prt) {
  int y, div = 0;
  if (g[x].size() == 1u) return k[x] = 0, void();
  k[x] = 1;
  for (auto t : g[x]) {
    if ((y = t.to) ^ prt)
      dfs(y, x), div = Mod(div + k[y]), b[x] = Mod(b[x] + b[y]);
    b[x] = Mod(b[x] + t.v);
  }
  div = qpow(Mod(g[x].size() - div + 1000000007), 1000000007 - 2);
  k[x] = 1ll * k[x] * div % 1000000007;
  b[x] = 1ll * b[x] * div % 1000000007;
}
int main() {
  n = read();
  int i, x, y, z;
  for (i = 1; i < n; ++i)
    x = read() + 1, y = read() + 1, z = read(), g[x].push_back({y, z}),
    g[y].push_back({x, z});
  dfs(1, 0);
  printf("%d\n", b[1]);
  return 0;
}
