#include <bits/stdc++.h>
using namespace std;
template <int MOD>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int _x) {
    x = _x % MOD;
    if (x < 0) x += MOD;
  }
  ModInt(long long _x) {
    x = _x % MOD;
    if (x < 0) x += MOD;
  }
  ModInt& operator+=(ModInt rhs) {
    x += rhs.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }
  ModInt& operator-=(ModInt rhs) {
    x -= rhs.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(ModInt rhs) {
    x = (long long)x * rhs.x % MOD;
    return *this;
  }
  ModInt& operator/=(ModInt rhs) { return *this *= rhs.inv(); }
  ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
  ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
  ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
  ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
  ModInt inv() const {
    int a = x, b = MOD, u = 1, v = 0;
    while (b != 0) {
      int t = a / b;
      a -= t * b;
      u -= t * v;
      swap(a, b);
      swap(u, v);
    }
    return u;
  }
  ModInt pow(long long e) {
    ModInt r = 1, p = *this;
    while (e) {
      if (e & 1) r *= p;
      p *= p;
      e >>= 1;
    }
    return r;
  }
  bool operator==(ModInt rhs) { return x == rhs.x; }
  bool operator!=(ModInt rhs) { return x != rhs.x; }
  bool operator<(ModInt rhs) { return x < rhs.x; }
  bool operator<=(ModInt rhs) { return x <= rhs.x; }
  bool operator>(ModInt rhs) { return x > rhs.x; }
  bool operator>=(ModInt rhs) { return x >= rhs.x; }
  friend ostream& operator<<(ostream& os, ModInt i) { return os << i.x; }
};
const int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
const int SIZE = 1e5 + 10;
map<int, mint> gg[SIZE];
mint cc[SIZE];
vector<int> e[SIZE];
vector<mint> ev[SIZE];
void dfs(int x, int lt) {
  for (int i = 0; i < (((int)(e[x]).size())); ++i) {
    int y = e[x][i];
    if (y == lt) continue;
    if (((int)(e[y]).size()) != 1) {
      dfs(y, x);
      gg[x][x] -= gg[y][x] * gg[x][y] / gg[y][y];
      cc[x] -= cc[y] * gg[x][y] / gg[y][y];
    }
  }
}
int main() {
  int(n);
  scanf("%d", &n);
  for (int i = (1); i < (n); ++i) {
    int x, y, v;
    scanf("%d%d%d", &x, &y, &v);
    e[x].push_back(y);
    ev[x].push_back(v);
    e[y].push_back(x);
    ev[y].push_back(v);
  }
  if (((int)(e[0]).size()) == 1) return 0 * puts("0");
  for (int i = 0; i < (n); ++i) {
    if (((int)(e[i]).size()) != 1) {
      mint q = ((int)(e[i]).size());
      q = q.inv();
      gg[i][i] = 1;
      mint sum = 0;
      for (int j = 0; j < (((int)(e[i]).size())); ++j) {
        gg[i][e[i][j]] = q * -1;
        sum += ev[i][j];
      }
      cc[i] = sum * q;
    }
  }
  dfs(0, 0);
  cout << cc[0] / gg[0][0];
  return 0;
}
