#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
const ll mod = 1e9+9;
vector<pair<int ,ll> > adj[50010];
ll fact[50010], inv[50010], weight[50010];
int d[50010], pa[20][50010];
ll power(ll b, ll e = mod-2LL) {
ll c=1;
while(e) {
if(e&1LL) c=(c*b)%mod;
b=(b*b)%mod;
e/=2LL;
}
return c;
}
void pre() {
int i, j;
fact[0]=inv[0]=1;
for(i=1; i<=50001; ++i) {
fact[i]=(fact[i-1]*1LL*i)%mod;
inv[i]=power(i);
}
return;
}
void dfs(int s, int p, int di, ll z) {
d[s]=di;
weight[s]=z;
pa[0][s]=p;
for(int i=0; i<adj[s].size(); ++i) {
int v=adj[s][i].x;
if(v!=p) {
dfs(v, s, di+1, z+adj[s][i].y);
}
}
return;
}
int LCA(int u, int v) {
if(d[u] < d[v]) swap(u,v);
int diff = d[u] - d[v];
for(int i=0; i<20; i++) if( (diff>>i)&1 ) u = pa[i][u];
if(u == v) return u;
for(int i=20-1; i>=0; i--) if(pa[i][u] != pa[i][v]) {
u = pa[i][u];
v = pa[i][v];
}
return pa[0][u];
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int i, j, n, u, v;
ll w;
pre();
cin>>n;
for(i=1; i<n; ++i) {
cin>>u>>v>>w;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
for(i=0; i<20; ++i)
for(j=1; j<=n; ++j)
pa[i][j]=-1;
dfs(1, 0, 0, 0);
ll ans=0;
for(i=1; i<20; ++i)
for(j=1; j<=n; ++j)
if(pa[i-1][j]!=-1)
pa[i][j]=pa[i-1][pa[i-1][j]];
for(i=1; i<=n; ++i) {
for(j=i+1; j<=n; ++j) {
int zz;
zz=LCA(i, j);
int qq=d[i]+d[j]-2*d[zz];
ll pp=weight[i]+weight[j]-2*weight[zz];
ll aux=fact[n];
pp%=mod;
aux=(aux*inv[qq+1])%mod;
aux=(aux*2LL*pp)%mod;
ans=(ans+aux)%mod;
//cout<<i<<" "<<j<<"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IHsKICAgICAgICAgICAgaW50IHp6OwogICAgICAgICAgICB6ej1MQ0EoaSwgaik7CiAgICAgICAgICAgIGludCBxcT1kW2ldK2Rbal0tMipkW3p6XTsKICAgICAgICAgICAgbGwgcHA9d2VpZ2h0W2ldK3dlaWdodFtqXS0yKndlaWdodFt6el07CiAgICAgICAgICAgIGxsIGF1eD1mYWN0W25dOwogICAgICAgICAgICBwcCU9bW9kOwogICAgICAgICAgICBhdXg9KGF1eCppbnZbcXErMV0pJW1vZDsKICAgICAgICAgICAgYXV4PShhdXgqMkxMKnBwKSVtb2Q7CiAgICAgICAgICAgIGFucz0oYW5zK2F1eCklbW9kOwogICAgICAgICAgICAvL2NvdXQ8PGk8PCIgIjw8ajw8IiAiPDxxcTw8IiAiPDxwcDw8IiAiPDxhbnM8PGVuZGw7CiAgICAgICAgfQogICAgfQogICAgY291dDw8YW5zOwogICAgcmV0dXJuIDA7Cn0K