#include<iostream>
#include<string.h>
using namespace std;
const int maxn = 20;
const int INF = 0x3f3f3f3f;
int d[maxn][maxn];
int n;
int m;
int res;
int floyd()
{
	int start;
	for(int i = 0; i <= m; i++)
		d[i][i] = 0;
	
	
	for(int k =0; k<=m; k++)
		for(int i = 0; i <= m; i++)
			for(int j = 0; j <= m; j++)
			{
				if(d[i][j] > d[i][k] + d[k][j])
					d[i][j] = d[i][k] + d[k][j];
			}
	
	for(int i = 0; i <= m; i++)
	{
		int cnt = 0;
		for(int j = 0; j <= m; j++)
			cnt += d[i][j];
		if(cnt < res)
		{
			res = cnt;
			start = i;
		}	
	}	
	return start;	
			
}

int main()
{
	//freopen("c:\\users\\administrator\\desktop\\in.txt","r",stdin);
	while(cin >> n,n)
	{
		memset(d,INF,sizeof(d));
		res = INF,m = 0;
		for(int i = 0; i <n; i++)
		{
			int u,v,w;
			cin >> u >> v >>w;
			d[u][v] = w;
			d[v][u] = w;
			m = max(m,max(u,v));
		}
		cout<< floyd()<<" "<<res<<endl;	
			
	}
		
}