#include <iostream>

#define UB 2000

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n == 0) break;
		int D[10][10];
		for (int i=0; i<10; i++) {
			for (int j=0; j<10; j++) D[i][j] = (i==j) ? 0 : UB;
		}
		int towns = 0;
		for (int i=0; i<n; i++) {
			int s, t, cost;
			std::cin >> s >> t >> cost;
			towns = std::max(towns, std::max(s, t));
			D[s][t] = D[t][s] = cost;
		}
		for (int k=0; k<=towns; k++) {
			for (int i=0; i<=towns; i++) {
				for (int j=0; j<=towns; j++) {
					D[i][j] = std::min(D[i][j], D[i][k] + D[k][j]);
				}
			}
		}
		int res = UB;
		int argres;
		for (int i=0; i<=towns; i++) {
			int sum = 0;
			for (int j=0; j<=towns; j++) sum += D[i][j];
			if (sum < res) { res = sum; argres = i; }
		}
		std::cout << argres << " " << res << std::endl;
	}
	return 0;
}

