#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define INF 1000000
int mat[10][10];
int tn;

int main(){
	int n, a, b, c;
	while (cin >> n && n != 0) {
		tn = 0;
		for (int i = 0; i < 10; i++) {
			fill(mat[i], mat[i] + n, INF);
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			mat[a][b] = mat[b][a] = c;
			tn = max(tn, max(a, b));
		}
		for (int i = 0; i <= tn; i++) {
			mat[i][i] = 0;
		}
		for (int k = 0; k <= tn; k++) {
			for (int i = 0; i <= tn; i++) {
				for (int j = 0; j <= tn; j++) {
					if (mat[i][j] > mat[i][k] + mat[k][j]) {
						mat[i][j] = mat[i][k] + mat[k][j];
					}
				}
			}
		}
		int l = 0, sum, ans = INF;
		for (int i = 0; i <= tn; i++) {
			sum = 0;
			for (int j = 0; j <= tn; j++) {
				sum += mat[i][j];
			}
			if (ans > sum) {
				ans = sum;
				l = i;
			}
		}
		cout << l << " " << ans << endl;
	}

	return 0;
}