#include <stdio.h>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;
#define F first
#define S second
const int N=2e5+10;
int p[N],sz[N];
int find(int n){return p[n]==n?n:p[n]=find(p[n]);}
int main(){
    int n,a,b,c;
    pair<int,pi> temp;
    ll ans=0;
    priority_queue<pair<int,pi>,vector<pair<int,pi>>,greater<pair<int,pi>>>pq;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        p[i]=i;
        sz[i]=1;
    }
    for(int i=1;i<n;i++){
        scanf("%d%d%d",&a,&b,&c);
        pq.push({c,{a,b}});
    }
    while(!pq.empty()){
        temp=pq.top();
        pq.pop();
        a=find(temp.S.F);
        b=find(temp.S.S);
        ans+=(ll)sz[a]*(ll)sz[b]*(ll)temp.F;
        sz[a]+=sz[b];
        p[b]=a;
    }
    printf("%lld\n",ans);
}
