#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct Edge
{
int a, b, w;
bool operator< (const Edge& W) const
{
return w < W.w;
}
}e[N];
int p[N], cnt[N];
int find(int x) // 并查集
{
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
int main()
{
int n;
scanf("%d", &n);
long long res = 0;
for (int i = 0; i < n - 1; i ++ )
{
int a, b, w;
cin >> a >> b >> w;
e[i] = {a, b, w};
res += w;
}
sort(e, e + n - 1);
for (int i = 1; i <= n; i ++ ) p[i] = i, cnt[i] = 1;
for (int i = 0; i < n - 1; i ++ )
{
int pa = find(e[i].a), pb = find(e[i].b);
if (pa != pb)
{
res += (cnt[pa] * cnt[pb] - 1) * (e[i].w + 1);
p[pa] = pb;
cnt[pb] += cnt[pa];
}
}
cout << res << endl;
return 0;
}