#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline long long moe(long long x) { return x < mod ? x : x % mod; }
inline long long moa(long long x) { return x < mod ? x : x % mod; }
inline long long qpow(long long a, long long b) {
  long long as = 1;
  for (; b; b >>= 1, a = moe(a * a)) {
    if (b & 1) as = moe(as * a);
  }
  return as;
}
inline long long inv(long long x) { return qpow(x, mod - 2); }
struct edge {
  int np, next, va;
} e[100001 << 1];
int e_ct = 1;
int head[100001];
inline void adde(int u, int v, int va) {
  e[++e_ct] = (edge){v, head[u], va};
  head[u] = e_ct;
  e[++e_ct] = (edge){u, head[v], va};
  head[v] = e_ct;
}
struct dat {
  int a, b;
};
int fa[100001], fv[100001];
dat vs[100001];
inline void dfs(int x) {
  int son_ct = 0;
  for (int ne = head[x]; ne; ne = e[ne].next) {
    int cur = e[ne].np;
    if (cur == fa[x]) continue;
    fa[cur] = x, fv[cur] = e[ne].va;
    dfs(cur);
    ++son_ct;
    vs[x].a = (int)moa(vs[x].a + vs[cur].a);
    vs[x].b = (int)moa(vs[x].b + moa(vs[cur].b + e[ne].va));
  }
  if (!son_ct)
    vs[x].a = vs[x].b = 0;
  else if (x) {
    int p = (int)inv(moa(son_ct + 1 - vs[x].a + mod));
    vs[x].a = p;
    vs[x].b = (int)moe(moa(vs[x].b + fv[x]) * p);
  } else {
    int p = (int)inv(moa(son_ct - vs[x].a + mod));
    vs[x].a = (int)moe(p * 1LL * vs[x].b);
  }
}
int n;
int u, v, c;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    scanf("%d%d%d", &u, &v, &c);
    adde(u, v, c);
  }
  dfs(0);
  printf("%d\n", vs[0].a);
  return 0;
}
