#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

struct st {
	int a, b, c;
};
int s[200000], par[200000];
st v[200000];
ll sum = 0;
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y, int c) {
	x = find(x); y = find(y);
	if (x == y)return;
	sum += c*(ll)s[x] * s[y];
	par[y] = x; s[x] += s[y];
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		s[i] = 1; par[i] = i;
	}
	rep(i, n - 1) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		v[i] = { a,b,c };
	}
	sort(v, v + n - 1, [](st&a, st&b) {return a.c < b.c; });
	rep(i, n - 1) {
		unite(v[i].a, v[i].b, v[i].c);
	}
	printf("%lld\n", sum);
}