#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long int
using namespace std;
struct T{
ll u,v,w;
}t[100005];
ll ans,n,cnt[100005],fa[100005];
ll find(ll x){
if(fa[x]!=x)
return fa[x]=find(fa[x]);
else
return fa[x];
}
bool cmp(T a,T b){return a.w<b.w;}
int main(){
scanf("%lld",&n);
for(ll i=1;i<=n-1;i++)
scanf("%lld%lld%lld",&t[i].u,&t[i].v,&t[i].w),ans+=t[i].w;
for(ll i=1;i<=n;i++){
fa[i]=i;cnt[i]=1;
}
sort(t+1,t+n,cmp);
for(ll i=1;i<=n-1;i++){
ll r1=find(t[i].u);
ll r2=find(t[i].v);
if(r1!=r2){
ans+=(cnt[r1]*cnt[r2]-1)*(t[i].w+1);
fa[r2]=r1;
cnt[r1]+=cnt[r2];
}
}
printf("%lld",ans);
return 0;
}