#include <stdio.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define INF (10000000)


int main(void)
{
	int ans, ans_sum;
	int cost[10][10];
	int n;
	int city_cnt;
	
	while (1){
	scanf("%d", &n);
	
	if (n == 0){
		break;
	}
	
	REP(i, 10){
		REP(j, 10){
			if (i == j){
				cost[i][j] = 0;
			}
			else {
				cost[i][j] = INF;
			}
		}
	}
	
	city_cnt = 0;
	REP(i, n){
		int s, e, c;
		scanf("%d%d%d", &s, &e, &c);
		cost[s][e] = cost[e][s] = c;
		city_cnt = MAX(city_cnt, MAX(s, e));
	}
	city_cnt++;
	
	
	REP(i, city_cnt)REP(j, city_cnt)REP(k, city_cnt) cost[i][j] = MIN(cost[i][j], cost[i][k] + cost[k][j]);
	
	ans = -1;
	ans_sum = INF;
	REP(i, city_cnt){
		int sum = 0;
		REP(j, city_cnt){
			sum += cost[i][j];
		}
		if (ans_sum > sum){
			ans_sum = sum;
			ans = i;
		}
	}
	
	printf("%d %d\n", ans, ans_sum);
	
	}
	return (0);
}