#include <cstdio>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
#define MAX_V 10
using namespace std;
int E, V;
int dp[MAX_V][MAX_V];

void warshall_floyd(){
	for(int k = 0; k < V; k++){
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
}

int main(){
	while(~scanf("%d", &E) && E){
		V = 0;
		memset(dp, 0x3f, sizeof(dp));
		for(int i = 0; i < E; i++){
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			dp[a][b] = dp[b][a] = min(dp[a][b], c);
			V = max(V, max(a, b));
		}
		++V;
		for(int i = 0; i < V; i++) dp[i][i] = 0;
		warshall_floyd();
		int idx, minsum = INF;
		for(int i = 0; i < V; i++){
			int sum = 0;
			for(int j = 0; j < V; j++) sum += dp[i][j];
			if(sum < minsum) minsum = sum, idx = i;
		}
		printf("%d %d\n", idx, minsum);
	}
	return 0;
}
