#include<queue>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define MAX_N	50
#define INF		100000000


struct edge
{
	int from , to , cost;
};

struct P
{
	int from , to;
};

edge input[MAX_N];


int dp[MAX_N][MAX_N];



int n;


int main(void)
{
	while (cin >> n && n != 0){

		int map_max = 0;

		int min = 2100000000;
		int index = 0;

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				dp[i][j] = INF;
			}
		}

		for (int i = 0; i < n; i++){
			cin >> input[i].from >> input[i].to >> input[i].cost;
		
			dp[input[i].from][input[i].to] = input[i].cost;
			dp[input[i].to][input[i].from] = input[i].cost;

			map_max = std::max(map_max , std::max(input[i].from , input[i].to));
		}

		

		for (int i = 0; i <= map_max; i++){
			dp[i][i] = 0;
			for (int j = 0; j <= map_max; j++){
				for (int k = 0; k <= map_max; k++){
					dp[j][k] = std::min(dp[j][k] , dp[j][i] + dp[i][k]);
				}
			}
		}

		for (int i = 0; i <= map_max; i++){
			int now = 0;
			for (int j = 0; j <= map_max; j++){
				now += dp[i][j];
			}

			if (now < min){
				min = now;
				index = i;
			}
		}

		cout << index << " " << min << endl;
	}
	
	return 0;
}