#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {
		VI a(n), b(n), c(n);
		rep(i, n)cin >> a[i] >> b[i] >> c[i];
		int v = max(*max_element(all(a)), *max_element(all(b))) + 1;

		VVI d(v, VI(v, inf));
		rep(i, v)d[i][i] = 0;
		rep(i, n) { d[a[i]][b[i]] = c[i]; d[b[i]][a[i]] = c[i]; }
		rep(i, v)rep(j, v)rep(k, v)d[j][k] = min(d[j][k], d[j][i] + d[i][k]);

		int ans1 = -1, ans2 = inf;
		rep(i, v) {
			int sum = accumulate(all(d[i]), 0);
			if (ans2 > sum) { ans1 = i; ans2 = sum; }
		}
		cout << ans1 << " " << ans2 << endl;
	}
}
