#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 10000000
#define rep(i,n) for (int i=0;i<(n);i++)
#define rev(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vp;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

int d[10][10];

void washall_floyd(int v) {
  rep(k,v)
    rep(i,v)
      rep(j,v)
        d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

  int n;
  while(true) {
    cin >> n;
    if(n == 0) break;

    rep(i,n+1) rep(j,n+1) d[i][j] = INF;
    rep(i,n+1) d[i][i] = 0;

    rep(i,n) {
      int a,b,cost;
      cin >> a >> b >> cost;
      d[a][b] = cost;
      d[b][a] = cost;
     }

     washall_floyd(n+1);

    //  rep(i,n+1){ rep(j,n+1) { cout << d[i][j] << " ";} cout << endl;}

    int num = 0;
    int min = 0;
    rep(j,n+1)
      if(d[0][j] != INF) min += d[0][j];

      rep(i,n+1) {
        int tmp = 0;
        rep(j,n+1)
          if(d[i][j] != INF) tmp += d[i][j];
        if(tmp < min && tmp != 0) { min = tmp; num = i;}
      }
      cout << num << " " << min << endl;
  }

	return 0;
}