/* Warshall-Floyd Algorithm */

#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int wf[10][10];
	for(int n_road;cin>>n_road,n_road;){
		for(int i=0;i<10;i++)for(int j=0;j<10;j++)wf[i][j]=10000;

		int n_city=0;
		for(int i=0;i<n_road;i++){
			int a,b,c;	cin>>a>>b>>c;
			n_city=max(n_city,max(a+1,b+1));
			wf[a][b]=wf[b][a]=c;
		}

		for(int k=0;k<n_city;k++){
			for(int i=0;i<n_city;i++){
				for(int j=0;j<n_city;j++){
					if(i==j)	wf[i][j]=0;
					wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j]);
				}
			}
		}

		int opt=10000,iopt;
		for(int i=0;i<n_city;i++){
			int sum=0;
			for(int j=0;j<n_city;j++)	sum+=wf[i][j];
			if(opt>sum)	opt=sum,iopt=i;
		}
		cout<<iopt<<' '<<opt<<endl;
	}
	return 0;
}