#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 15, INF = 0x3f3f3f3f;
int a[N][N], n, m;
int main() {
    // freopen("in.txt", "r", stdin);
    int x, y, w;
    while(scanf("%d", &m) && m) {
        n = 0;
        for(int i = 0; i < N; i++)
            for(int j = 0; j < N; j++)
                if(i == j)  a[i][j] = 0;
                else    a[i][j] = INF;
        for(int i = 0; i < m; i++) {
            scanf("%d %d %d", &x, &y, &w);
            n = max({x, y, n});
            a[x][y] = a[y][x] = min(a[x][y],w);
        }
        for(int k = 0; k <= n; k++)
            for(int i = 0; i <= n; i++)
                for(int j = 0; j <= n; j++)
                    if(a[i][j] > a[i][k] + a[k][j])
                        a[i][j] = a[i][k] + a[k][j];
        ll ans = INF, pos;
        for(int i = 0; i <= n; i++) {
            ll sum = 0;
            for(int j = 0; j <= n; j++)
                sum += a[i][j];
            if(sum < ans) {
                ans = sum;
                pos = i;
            }
        }
        printf("%lld %lld\n", pos, ans);
    }
    return 0;
}
