#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>

#define INF 100000000

struct edge{
	int from, to, cost;
	void init(){ from = 0, to = 0, cost = 0; };
};

edge es[100];

int d[1000000];
int V=0, E;

void shortest_path(int s){
	for (int i = 0; i < V+1; ++i)d[i] = INF;
	d[s] = 0;
	while (1){
		bool update = false;
		for (int i = 0; i < E*2; ++i){
			edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update)break;
	}
}

int main(){
	while (1){
		//for (int i = 0; i < E * 2; ++i)es[i].init();
		V = 0;
		scanf("%d", &E);
		if (E == 0)break;
		for (int i = 0; i < E; ++i){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			V < a ? V = a : V = V;
			V < b ? V = b : V = V;
			es[i * 2].from = a;
			es[i * 2].to = b;
			es[i * 2].cost = c;
			es[i * 2 + 1].from = b;
			es[i * 2 + 1].to = a;
			es[i * 2 + 1].cost = c;
		}
		int ans = 0;
		int anspath = INF;
		for (int i = 0; i < V + 1; ++i){
			int anspath_ = 0;
			shortest_path(i);
			for (int j = 0; j < V + 1; ++j){
				anspath_ += d[j];
			}
			if (anspath_ < anspath){
				anspath = anspath_;
				ans = i;
			}
		}
		printf("%d %d\n", ans, anspath);
	}
	return 0;
}//*/