#include <iostream>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <cmath>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int dir[9][2] = { 0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1, 0, 0 };
const ll  ll_inf = 0x7fffffff;
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
const int inf = 0x3f3f3f;
const int mod = (int) 998244353;
const int Max = (int) 45 + 22;
stringstream ss;

/**********************************************Head-----Template****************************************/
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}

/********************************Head----Temlate**********************************************/

//tools:
//priority_queue <int, vector<int>, greater<int> > Q;
//ios::sync_with_stdio(false);
//freopen("input.txt", "r", stdin);
//ss<<int; ss>>str;

int n, maxx;
int Map[Max][Max];

void Init() {
	maxx = -1;
	for (int i = 0; i <= 45; ++i)
		for (int j = 0; j <= 45; ++j) 
			Map[i][j] = Map[j][i] = (i == j) ? 0 : inf;	
}

void Floyd() {
	for (int i = 0; i <= maxx; ++i) {
		for (int j = 0; j <= maxx; ++j) {
			for (int k = 0; k <= maxx; ++k) {
				Map[i][k] = min(Map[i][k], Map[i][j] + Map[j][k]);
			}
		}
	}
}

int main() {
	
	while (scanf("%d", &n) && n) {
		
		int a, b, c;
		Init();
		for (int i = 0; i < n; ++i) {
			scanf("%d %d %d", &a, &b, &c);
			maxx = max(maxx, a);
			maxx = max(maxx, b);
			Map[a][b] = Map[b][a] = min(c, Map[b][a]);
		}
		
		Floyd();
		int ans = inf;
		int index = -1;
		for (int i = 0; i <= maxx; ++i) {
			int sum = 0;
			for (int j = 0; j <= maxx; ++j) {
				sum += Map[i][j];
			}
			if (sum < ans) {
				ans = sum;
				index = i;
			}
		}
		
		printf("%d %d\n", index, ans);
	}
	return 0;
}
