#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

typedef vector< int > VI;
typedef vector< VI > VVI;
typedef vector< VVI > VVVi;

int main(){
	while(true){
		int n;
		cin >> n;

		if(n == 0){
			break;
		}

		VI start;
		VI goal;
		VI cost;

		int s, g, c;

		for(int i = 0; i < n; i++){
			cin >> s >> g >> c;
			start.push_back(s);
			goal.push_back(g);
			cost.push_back(c);
		}

		int town;

		for(int i = 0; i < n; i++){
			town = max(start[i], goal[i]);
		}
		town++;

		VVI map(town, VI(town, INT_MAX / 2));

		for(int i = 0; i < n; i++){
			map[start[i]][goal[i]] = cost[i];
			map[goal[i]][start[i]] = cost[i];
		}

		for(int i = 0; i < town; i++){
			map[i][i] = 0;
		}

		for(int k = 0; k < town; k++){
			for(int i = 0; i < town; i++){
				for(int j = 0; j < town; j++){
					map[i][j] = min(map[i][j], map[i][k] + map[k][j]);
				}
			}
		}

		int num;
		int total = INT_MAX / 4;

		for(int i = 0; i < town; i++){
			int sum = 0;
			for(int j = 0; j < town; j++){
				sum += map[i][j];
			}

			if(sum < total){
				num = i;
				total = sum;
			}

		}

		cout << num << " " << total << endl;
	}
}