# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int MAX_V = 12;
LL d[MAX_V][MAX_V];//d[i][j]???e={u,v}????????????(?????¨???????????¨??????INF,i==j?????¨??????0)
int v;

void warshall_floyd() {
	for (int k = 0; k<v; k++) {
		for (int i = 0; i<v; i++) {
			for (int j = 0; j<v; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}


int main() {
	while (cin >> v&&v) {
		REP(i, MAX_V)REP(j, MAX_V) {
			if (i == j)d[i][j] = 0;
			else d[i][j] = INF;
		}
		int a, b, c;
		for (int i = 0; i < v; i++) {
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
	}
		warshall_floyd();
		int cost = INF, town = -1;
		for (int i = 0; i<10; ++i) {
			LL c = 0;
			for (int j = 0; j<10; ++j) {
				if (d[i][j] == INF) {
					continue;
				}
				c += d[i][j];
			}
			if (c != 0 && cost > c) {
				cost = c;
				town = i;
			}
		}
		cout << town << ' ' << cost << endl;;
	}
}