#include <bits/stdc++.h>
using namespace std;

const int INF = 0x7f7f;
int d[11][11];

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        
        for(int i=0;i<=11;i++)fill(d[i],d[i]+11,INF);        
        
        for (int i = 0; i < 11; i++) d[i][i] = 0;
        int x, y, z, v = 0;
        while (n--) {
            cin >> x >> y >> z;
            v = max(max(v, x), y);
            d[x][y] = z;
            d[y][x] = z;
        }

		for (int k = 0; k <= v; k++) {
            for (int i = 0; i <= v; i++) {
                for (int j = 0; j <= v; j++)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
        
		int sum = INF,number;
        for (int i = 0; i <= v; i++) {
            int t = 0;
            for (int j = 0; j <= v; j++) t += d[i][j];
            if(sum>t){
            	sum=t;
            	number=i;
			}
        }
        cout<<number<<" "<<sum<<"\n";
    }
}
