#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch = getchar();
  int f = 0, x = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') x = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    f = (f << 1) + (f << 3) + ch - '0';
    ch = getchar();
  }
  return f * x;
}
const int mod = 1000000007;
int q[100005], d[100005], head[100005];
long long f[100005], b[100005], k[100005], fa[100005];
struct node {
  int from;
  int to;
  int next;
} edge[500005];
int tot, n;
void add(int u, int v) {
  edge[tot].from = u;
  edge[tot].to = v;
  edge[tot].next = head[u];
  head[u] = tot++;
}
void dfs(int x) {
  q[++q[0]] = x;
  for (int i = head[x]; i != -1; i = edge[i].next) {
    if (edge[i].to != fa[x]) {
      fa[edge[i].to] = x;
      dfs(edge[i].to);
    }
  }
}
long long quick_mod(long long x, int y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % mod;
    x = x * x % mod, y >>= 1;
  }
  return ret;
}
int main() {
  memset(head, -1, sizeof(head));
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read() + 1, y = read() + 1, z = read();
    add(x, y);
    add(y, x);
    k[x]++;
    k[y]++;
    d[x]++;
    d[y]++;
    b[x] += z;
    b[y] += z;
  }
  dfs(1);
  for (int i = n; i >= 2; i--) {
    if (d[q[i]] != 1) {
      int x = q[i];
      long long tmp = quick_mod(k[x], mod - 2);
      k[fa[x]] = (k[fa[x]] - tmp) % mod;
      b[fa[x]] = (b[fa[x]] + b[x] * tmp) % mod;
    }
  }
  f[1] = b[1] * quick_mod(k[1], mod - 2) % mod;
  printf("%lld", (f[1] + mod) % mod);
}
