#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
const ll MAXN = 1e2 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 7;
void FastIO(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
void fre(){
freopen("CAU2.inp", "r", stdin);
freopen("CAU2.out", "w", stdout);
}
struct canh{
ll z, x, y;
};
class cmp{
public:
bool operator()(canh a, canh b){
return a.z > b.z;
}
};
ll n;
vector<canh> adj[MAXN];
vector<ll> check;
priority_queue<canh, vector<canh>, cmp> p;
int main()
{
FastIO();
fre();
cin >> n;
ll u, v, c;
while(cin >> u >> v >> c){
adj[v].pb({c, u, v});
adj[u].pb({c, v, u});
}
check.resize(n+1, 0);
check[1] = 1;
for(canh i : adj[1]) p.push(i);
ll s = 0;
for(int i=1; i<n; ++i){
canh k;
do{
k = p.top();
p.pop();
}while(check[k.x] == 1);
check[k.x] = 1;
s += k.z;
for(canh j : adj[k.x])
if(check[j.x] == 0) p.push(j);
}
cout << s;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDx2ZWN0b3I+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIHNlIHNlY29uZAoKY29uc3QgbGwgTUFYTiA9IDFlMiArIDU7CmNvbnN0IGxsIE1PRCA9IDFlOSArIDc7CmNvbnN0IGxsIElORiA9IDFlOSArIDc7Cgp2b2lkIEZhc3RJTygpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOyBjb3V0LnRpZShOVUxMKTsKfQoKdm9pZCBmcmUoKXsKICAgIGZyZW9wZW4oIkNBVTIuaW5wIiwgInIiLCBzdGRpbik7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