#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

const int INF = 100000;

int main(){
	while(true){
		int n;
		cin>>n;
		if(n==0)break;
		int a[n],b[n],c[n];
		int N = 0;
		for(int i=0;i<n;++i){
			cin>>a[i]>>b[i]>>c[i];
			if(N<a[i]+1)N = a[i]+1;
			if(N<b[i]+1)N = b[i]+1;
		}
		vector<vector<int> > DParr;
		vector<int>tmparr(N,INF);
		for(int i=0;i<N;++i){
			DParr.push_back(tmparr);
			DParr[i][i] = 0;
		}
		for(int i=0;i<n;++i){
			DParr[a[i]][b[i]] = c[i];
			DParr[b[i]][a[i]] = c[i];
		}
		for(int k=0;k<N;++k){
			for(int i=0;i<N;++i){
				for(int j=0;j<N;++j){
					DParr[i][j] = min(DParr[i][j], DParr[i][k] + DParr[k][j]);
				}
			}
		}
		/*
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				cout<<DParr[i][j]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;
		*/
		int ans=100000;
		int city;
		for(int i=0;i<N;++i){
			int tmpans=0;
			for(int j=0;j<N;++j){
				tmpans+=DParr[i][j];
			}
			if(ans>tmpans){
				ans=tmpans;
				city = i;
			}
		}
		cout<<city<<" "<<ans<<endl;
	}
}
