#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma warning(disable : 4996)
template <typename T>
T min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
T max(T x, T y) {
  return x > y ? x : y;
};
const int MAXN = 100001;
const long long mod = 1000000007;
struct node {
  int to;
  int w;
  node *next;
};
void addnode(node *&head, int to, int w) {
  node *p = new node;
  p->to = to;
  p->w = w;
  p->next = head;
  head = p;
}
long long qpow(long long x, long long y) {
  if (!y) return 1;
  long long t = qpow(x, y / 2);
  t = t * t % mod;
  if (y & 1) t = t * x % mod;
  return t;
}
int N;
node *edge[MAXN];
int fa[MAXN], w[MAXN], deg[MAXN], tmp[MAXN];
long long e[MAXN], k[MAXN], t[MAXN];
void dfs(int v) {
  for (node *p = edge[v]; p; p = p->next) {
    if (p->to == fa[v]) continue;
    fa[p->to] = v;
    w[p->to] = p->w;
    dfs(p->to);
  }
}
void solve() {
  std::queue<int> Q;
  memcpy(tmp + 1, deg + 1, sizeof(int) * N);
  for (int i = 1; i <= N; i++) k[i] = deg[i];
  for (int i = 1; i <= N; i++)
    if (deg[i] == 1) {
      t[fa[i]] = (t[fa[i]] - w[i]) % mod;
      tmp[fa[i]]--;
      if (tmp[fa[i]] == 1) Q.push(fa[i]);
    }
  while (Q.size()) {
    int v = Q.front();
    Q.pop();
    long long m = qpow(k[v], mod - 2);
    long long n = m * (w[v] - t[v]) % mod;
    n = (n + w[v]) % mod;
    k[fa[v]] = (k[fa[v]] - m) % mod;
    t[fa[v]] = (t[fa[v]] - n) % mod;
    tmp[fa[v]]--;
    if (tmp[fa[v]] == 1 && v != 1) Q.push(fa[v]);
  }
  long long ans = -t[1] * qpow(k[1], mod - 2) % mod;
  ans = (ans + mod) % mod;
  printf("%lld\n", ans);
}
void init() {
  int u, v, c;
  scanf("%d", &N);
  for (int i = 1; i < N; i++) {
    scanf("%d %d %d", &u, &v, &c);
    u++;
    v++;
    addnode(edge[u], v, c);
    addnode(edge[v], u, c);
    deg[u]++;
    deg[v]++;
  }
  dfs(1);
}
int main() {
  init();
  solve();
  return 0;
}
