#include <bits/stdc++.h>
using namespace std;
long long n, u, v, c;
vector<long long> G[100007];
long long wolny[100007];
long long wspol[100007];
long long ojciec[100007];
long long deg[100007];
bitset<100007> vis;
long long fpow(long long a, long long w) {
  long long res = 1;
  for (long long i = 0; i < 31; ++i) {
    if (w & (1 << i)) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
  }
  return res;
}
long long inv(long long a) { return fpow(a, 1000000007 - 2); }
void dfs(long long v) {
  vis[v] = 1;
  for (auto it : G[v]) {
    if (!vis[it]) {
      ojciec[it] = v;
      dfs(it);
    }
  }
}
queue<long long> Q;
void elim(long long v) {
  long long ile = (inv(wspol[v]) * inv(G[ojciec[v]].size())) % 1000000007;
  wolny[ojciec[v]] = (wolny[ojciec[v]] + ile * wolny[v]) % 1000000007;
  if (G[v].size() > 1)
    wspol[ojciec[v]] = (wspol[ojciec[v]] +
                        ile * ((1000000007 - inv(G[v].size())) % 1000000007)) %
                       1000000007;
  if (--deg[ojciec[v]] == 1 && ojciec[v]) Q.push(ojciec[v]);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 1; i < n; ++i) {
    cin >> u >> v >> c;
    G[v].push_back(u);
    G[u].push_back(v);
    wolny[u] += c;
    wolny[v] += c;
  }
  dfs(0);
  for (long long i = 0; i < n; ++i) {
    if (G[i].size() == 1) {
      wspol[i] = 1;
      wolny[i] = 0;
      Q.push(i);
    } else {
      wspol[i] = 1;
      wolny[i] = (wolny[i] * inv(G[i].size())) % 1000000007;
    }
    deg[i] = G[i].size();
  }
  while (!Q.empty()) {
    elim(Q.front());
    Q.pop();
  }
  cout << (wolny[0] * inv(wspol[0])) % 1000000007;
}
