#include <iostream>
#include <vector>
using namespace std;
const int MAX_N = 10;
const int INF = 100000000;
int N;//N是道路的数量，不是点的数量 
int dp[MAX_N][MAX_N];
bool input(){
	fill(dp[0],dp[0]+MAX_N*MAX_N,INF);
	scanf("%d",&N);
	if(N == 0) return false;
	int a,b,c;
	int max_N = 0;
	for(int i = 0;i < N;++i){
		scanf("%d%d%d",&a,&b,&c);
		dp[a][b] = dp[b][a] = c;
		max_N = (max(a,b) > max_N ? max(a,b) : max_N);
	}
	N = max_N + 1;//N变为点的数量 
	for(int i = 0;i < N;++i) dp[i][i] = 0;
	return true;
}

void shortest_path(){
	for(int k = 0;k < N;++k){
		for(int i = 0;i < N;++i){
			for(int j = 0;j < N;++j){
				if(dp[i][k] != INF && dp[k][j] != INF){
					if(dp[i][j] > dp[i][k]+dp[k][j]) dp[i][j] = dp[i][k]+dp[k][j];
				}
			}
		}
	}
}

int main(){
	while(input()){
		shortest_path();
		int street, res = INF;
		for(int i = 0;i < N;++i){
			int tmp = 0;
			for(int j = 0;j < N;++j) tmp += dp[i][j];
			if(tmp < res){
				res = tmp;
				street = i;
			}
		}
		cout << street << " " << res << endl;
	}
	return 0;
}
