#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using ll = long long;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int n, maxcity = 0, d[12][12], sum[12], ans = INF;

int main() {
    cin >> n;
    for (int i = 0; i <= 11; i++) {
        for (int j = 0; j <= 11; j++) {
            if (i == j)d[i][j] = 0;
            else d[i][j] = INF;
        }
    }
    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
        maxcity = max(maxcity, b);
    }
    for (int k = 0; k <= maxcity; k++) {
        for (int i = 0; i <= maxcity; i++) {
            for (int j = 0; j <= maxcity; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    for (int i = 0; i <= maxcity; i++) {
        for (int j = 0; j <= maxcity; j++) {
            sum[i] += d[i][j];
        }
    }
    for (int i = 0; i <= maxcity; i++) ans = min(ans, sum[i]);
    cout << ans << endl;
    return 0;
}