
#include <iostream>
#include <cmath>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

typedef long long ll;

const int M = 10;
const int INF = 1000000000;
ll w[M+1][M+1];

int main()
{
    int n, m;
    while(cin >> n && n) {

        int a, b, c;
        m = 0;

        for(int i = 0; i <= M; i++) {
            for(int j = 0; j <= M; j++) {
                if(i == j) w[i][j] = 0;
                else w[i][j] = INF;
            }
        }

        for(int i = 0; i < n; i++) {
            cin >> a >> b >> c;
            w[a][b] = w[b][a] = c;
            m = max(m, max(a,b)); 
        }
        
        for(int i = 0; i <= m; i++) 
            for(int k = 0; k <= m; k++) 
                for(int j = 0; j <= m; j++) 
                    w[i][j] = min(w[i][j], w[i][k] + w[k][j]);

        ll sum = INF * 10, idx = 0, tmp = 0;
        for(int i = 0; i <= m; i++) {
            tmp = 0;
            for(int j = 0; j <= m; j++) tmp += w[i][j];
            if(tmp < sum) {
                idx = i;
                sum = tmp;
            }
        }

        cout << idx << " " << sum << endl;
        
    }
    return 0;
}