#include <iostream>
#include <algorithm>

using namespace std;
const int INF = 100000;

int main()
{

	int data[11][11];
	int n;
	int a, s, d;
	int ans=9595, anssum;
	int sum = 0;
	int number;

	while (true)
	{

		for (int i = 0; i<11; i++)
		{
			for (int k = 0; k<11; k++)
			{
				data[i][k] = (i==k) ? 0 : INF;
				
			}
		}

		cin >> n;

		if (n == 0)return 0;

		for (int i = 0; i< n; ++i)
		{
			cin >> a >> s >> d;
			data[a][s] = d;
			data[s][a] = d;
			number = max(max (a, s), number);
		}

		for (int i = 0; i<number; i++)
		{
			for (int k = 0; k<number; k++)
			{
				for (int m = 0; m<number; m++)
				{
					data[k][m] = min(data[k][m], data[k][i] + data[i][m]);
					
				}
				
			}
			
		}
	
		anssum = INF;
		for (int i = 0; i<number; ++i)
		{
			sum = 0;
			for (int k = 0; k < number; ++k)
			{
				sum += data[i][k];
			}
			cout << sum << endl;
			if (sum < anssum)
			{
				ans = i;
				anssum = sum;
			}
		}
		cout << ans << " " << anssum << "\n";
	}

}