#include<iostream>
#include<queue>
#include<cstring>

#define HOME 10
#define ROAD 45
#define MAX  100000000
using namespace std;

int dis[HOME][HOME];
bool chk[HOME];

class Datum {
public:
	int now;
	int dis;

	Datum(int n, int d) {now = n;dis = d;}
	Datum() {}
};

bool operator<( const Datum& a, const Datum& b ) {
	return a.dis < b.dis;
}

bool operator>( const Datum& a, const Datum& b ) {
	return a.dis > b.dis;
}

int main () {
	while ( true ) {
		int n;
		cin >> n;
		
		if ( n ==  0 ) 
			break;

		for ( int i=0; i<HOME;i ++ ) {
			for ( int j=0; j<HOME; j++ ) {
				dis[i][j] = MAX;
			}
		}

		int find = -1;
		for ( int i=0;i<n; i++ ) {
			int from, to, distance;
			cin >> from >> to >> distance;
			
			if ( find < to )
				find = to;
			if ( find < from )
				find = from;

			dis[from][to] = distance;
			dis[to][from] = distance;

			dis[i][i] = 0;
		}

		n = find+1;

		priority_queue<Datum, vector<Datum>, greater<Datum> > flow;

		while( !flow.empty() ) {
			flow.pop();
		}

		for ( int k=0; k<n; k++ ) {
		
		for ( int i=0 ; i<n; i++ ) {

			while( !flow.empty() ) {
				flow.pop();
			}

			flow.push(Datum(i,0));
		
			int count = n;

			memset( chk, false, n*sizeof(bool) );

			while(!flow.empty()) {
				Datum now;
				now = flow.top();
				flow.pop();

				for ( int j=0; j<n; j++ ) {
					if ( i != j ) {
						if ( chk[j] )
							continue;

						if ( dis[now.now][j] + now.dis <= dis[i][j] ) {
							dis[i][j] = dis[now.now][j] + now.dis;
							dis[j][i] = dis[now.now][j] + now.dis;

							if ( dis[now.now][j] == MAX )
							continue;

							chk[j] = true;
							count--;
	
							flow.push(Datum(j,dis[i][j]));
							
						}
					}
				}

				if ( count == 1 ) {
					break;
				}
			}
		}

		}


		int maxhome = -1;
		int maxdis = MAX;
		for ( int i=0; i<n; i++ ) {
			int sum = 0;
			
			for ( int j=0; j<n; j++ ) {
				sum += dis[i][j];
			}
			
			if ( maxdis > sum ) {
				maxdis = sum;
				maxhome = i;
			}
		}

		cout << maxhome << ' ' << maxdis << endl;
	}
}








	