#include <iostream>
#include <algorithm>

using namespace std;

// BEGIN_LIBRARY ///////////////////
#define MAX_V (100)
#define INF (999999)

namespace NLibrary{
	class Dijkstra {
	private:
		int cost[MAX_V][MAX_V];
		int d[MAX_V];
		bool used[MAX_V];
		int V;
	public:
		Dijkstra() {
			for (int i = 0; i < MAX_V; i++) {
				fill(cost[i], cost[i] + MAX_V, INF);
			}
		}

		void setV(int V) {
			this->V = V;
		}

		void setCost(int a, int b, int c, bool bidirect = false) {
			this->cost[a][b] = c;
			if (bidirect) {
				this->cost[b][a] = c;
			}
		}

		void calc(int s) {
			// s??????????????????????????¢????±???????
			fill(d, d + MAX_V, INF);
			fill(used, used + MAX_V, false);
			d[s] = 0;
			while (true) {
				int v = -1;
				for (int u = 0; u < V; u++) {
					if (!used[u] && (v == -1 || d[u] < d[v])) {
						v = u;
					}
				}

				if (v == -1) break;
				used[v] = true;
				for (int u = 0; u < V; u++) {
					d[u] = min(d[u], d[v] + cost[v][u]);
				}
			}
		}

		int getL(int a) {
			return d[a];
		}
	};

}

// END_LIBRARY ////////////////////

int main() {
	NLibrary::Dijkstra dijkstra;
	int n;
	int as[100];
	int bs[100];
	int cs[100];
	while (cin >> n, n != 0) {
		int V = -1;
		for (int i = 0; i < n; i++) {
			cin >> as[i] >> bs[i] >> cs[i];
			V = max(V, max(as[i], bs[i]));
		}
		V++;
		dijkstra.setV(V);
		for (int i = 0; i < n; i++) {
			dijkstra.setCost(as[i], bs[i], cs[i], true);
		}
		int m = INF, town = -1;
		for (int i = 0; i < V; i++) {
			int sum = 0;
			dijkstra.calc(i);
			for (int j = 0; j < V; j++) {
				sum += dijkstra.getL(j);
			}

			if (sum < m) {
				town = i;
				m = sum;
			}
		}
		cout << town << " " << m << endl;
	}
	return 0;
}