#include <iostream>
#include <algorithm>


using namespace std;

const int inf = 100000;

int dis[10][10];
int m;

void floyd()
{
	for (int k = 0; k < m; k++)
		for (int i = 0; i < m; i++)
			for (int j = 0; j < m; j++)
				if (dis[i][k] + dis[k][j] < dis[i][j])
					dis[i][j] = dis[i][k] + dis[k][j];
}

int main()
{
	int n, a, b, c;
	int tmp, ans, p;
	
	while (cin >> n && n)
	{
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				dis[i][j] = inf;
		m = 0;
		ans = inf;
		while (n--)
		{
			cin >> a >> b >> c;
			dis[a][b] = c;
			dis[b][a] = c;
			m = max(m, max(a + 1, b + 1));
		}
		
		floyd();
		for (int i = 0; i < m; i++)
		{
			tmp = 0;
			for (int j = 0; j < m; j++)
			{
				if (i == j)
					continue;
				tmp += dis[i][j];
				if (tmp > inf)
					break;
			}
			if (tmp < ans)
			{
				ans = tmp;
				p = i;
			}
		}
		cout << p << ' ' << ans << endl;
	}
	

	return 0;
}
