#include <iostream>
#include <algorithm>

using namespace std;

const int INF = 10000000;

int main(void)
{
	int m,n;
	int city[11][11];
	int dist[11][11];
	n = 0;

	while( cin >> m && m ){
		n = 0;

		for( int i = 0;i < 11;i++ ){
			for( int j = 0;j < 11;j++ ){
				city[i][j] = INF;
				dist[i][j] = INF;
			}
		}

		for( int i = 0;i < 11;i++ ){
			city[i][i] = 0;
			dist[i][i] = 0;
		}

		for( int i = 0;i < m;i++ ){
			int a,b,cost;

			cin >> a >> b >> cost;
			n = max( n, a );
			n = max( n, b );
			city[a][b] = cost;
			city[b][a] = cost;
		}

		for( int k = 0;k <= n;k++ ){
			for( int j = 0;j <= n;j++ ){
				for( int i = 0;i <= n;i++ ){
					dist[k][i] = min( dist[k][i], dist[k][j] + city[j][i] );
				}
			}
		}

		int answer = 0;
		int sum;
		int answer_sum = INF;
		for( int i = 0;i <= n;i++ ){
			sum = 0;
			for( int j = 0;j <= n;j++ ){
				sum += dist[i][j];
			}
			if( answer_sum > sum ){
				answer_sum = sum;
				answer = i;
			}
		}


		cout << answer << " " << answer_sum << endl;
	}

	return 0;
}