#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

template<class T> bool ChangeMin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }


static const int MAX = 100;
static const long long INF = 1 << 29;

int m;
long long dist[MAX][MAX];

int main()
{
  while (cin >> m) {
    if (m == 0) break;
    for (int i = 0; i < MAX; ++i) {
      for (int j = 0; j < MAX; ++j) {
	dist[i][j] = INF;
      }
    }

    for (int i = 0; i < m; ++i) {
      int u, v, d;
      cin >> u >> v >> d;
      dist[u][v] = d;
      dist[v][u] = d;
      dist[u][u] = 0;
      dist[v][v] = 0;
    }

    for (int k = 0; k < MAX; ++k)
      for (int i = 0; i < MAX; ++i)
	for (int j = 0; j < MAX; ++j)
	  ChangeMin(dist[i][j], dist[i][k] + dist[k][j]);

    long long minDist = INF;
    int minPlace = -1;
    for (int i = 0; i < MAX; ++i) {
      if (dist[i][i] >= INF) continue;
      long long tmpDist = 0;
      for (int j = 0; j < MAX; ++j) {
	if (dist[j][j] >= INF) continue;
	tmpDist += dist[i][j];
	//cout << i << ", " << j << ": " << dist[i][j] << endl;
      }
      if (ChangeMin(minDist, tmpDist)) {
	minPlace = i;
      }
    }
    cout << minPlace << " " << minDist << endl;
  }
}
