#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define scd(x) scanf("%d", &x)
#define scdd(x, y) scanf("%d %d", &x, &y)
#define scddd(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define icc ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;

const int MAX = 10 + 1;
const int INF = 1000000;

int n, V;
int mp[MAX][MAX], d[MAX];

void solve() {
    for (int i = 0; i <= V; ++i) mp[i][i] = 0;
    for (int k = 0; k <= V; ++k)
        for (int i = 0; i <= V; ++i)
            for (int j = 0; j <= V; ++j) mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);

    memset(d, 0, sizeof(d));
    int num, res = INF;
    for (int i = 0; i <= V; ++i){
        for (int j = 0; j <= V; ++j) d[i] += mp[i][j];
        if (res > d[i]){
            res = d[i];
            num = i;
        }
    }
    printf("%d %d\n", num, res);
    return;
}

int main() {
    int x, y, t;
    while (~scd(n) && n){
        V = 0;
        fill(mp[0], mp[0] + MAX * MAX, INF);
        for (int i = 0; i < n; ++i){
            scddd(x, y, t);
            mp[x][y] = mp[y][x] = t;
            V = max(V, max(x, y));
        }
        solve();
    }
    return 0;
}

