#include <bits/stdc++.h>
using namespace std;
const int MAXINT = 100010;
const int MAXNODE = 100010;
const int MAXEDGE = 2 * MAXNODE;
char BUF, *buf;
int read() {
  char c = getchar();
  int f = 1, x = 0;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return f * x;
}
char get_ch() {
  char c = getchar();
  while (!isalpha(c)) c = getchar();
  return c;
}
int n, cnt, d[MAXNODE];
struct info {
  long long k, b;
  info(int _k, int _b) : k(_k), b(_b) {}
  info() {}
} dp[MAXNODE], tmp[MAXNODE];
long long rev(long long b) {
  long long ans = 1, u = 1000000007 - 2;
  for (; u; b = b * b % 1000000007, u >>= 1)
    if (u & 1) ans = ans * b % 1000000007;
  return ans;
}
struct edge {
  int u, v, l;
  edge *nxt;
  edge() {}
  edge(int _u, int _v, int _l, edge *_nxt) : u(_u), v(_v), l(_l), nxt(_nxt) {}
} mp[MAXEDGE], *head[MAXNODE];
void addedge(int u, int v, int l) {
  mp[cnt] = edge(u, v, l, head[u]);
  head[u] = &mp[cnt++];
  mp[cnt] = edge(v, u, l, head[v]);
  head[v] = &mp[cnt++];
}
void dfs(int p, int fa) {
  long long _d;
  if (d[p] == 1)
    _d = 0;
  else
    _d = rev(d[p]);
  dp[p].k = 1;
  for (edge *i = head[p]; i; i = i->nxt) dp[p].b += _d * i->l;
  dp[p].b %= 1000000007;
  for (edge *i = head[p]; i; i = i->nxt) {
    if (i->v == fa) continue;
    dfs(i->v, p);
  }
  if (p == 0) return;
  if (d[p] != 1) {
    long long _fd = rev(d[fa]);
    long long k = rev(dp[p].k);
    dp[fa].b = (dp[fa].b + _fd * (dp[p].b * k % 1000000007)) % 1000000007;
    dp[fa].k =
        ((dp[fa].k - _fd * (_d * k % 1000000007)) % 1000000007 + 1000000007) %
        1000000007;
  }
}
void get_input();
void work();
int main() {
  get_input();
  work();
  return 0;
}
void work() {
  dfs(0, -1);
  printf("%lld\n", dp[0].b * rev(dp[0].k) % 1000000007);
}
void get_input() {
  n = read();
  for (int i = 0; i < n - 1; ++i) {
    int u = read(), v = read(), l = read();
    addedge(u, v, l);
    d[u]++;
    d[v]++;
  }
}
