#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define INF 1 << 29
using namespace std;

int cost[10][10];

int main(){

  int n, town, from, to, c;
  while(scanf("%d", &n) && n){
    rep(i, 10) rep(j, 10) cost[i][j] = INF;
    rep(i, 10) cost[i][i] = 0;
    town = 0;
    rep(i, n){
      scanf("%d%d%d", &from, &to, &c);
      town = max(town, max(from, to));
      cost[from][to] = cost[to][from] = c;
    }
    town++;
    rep(k, town) rep(i, town) rep(j, town)
      cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);

    /*    rep(i, town){
      rep(j, town) printf("%d ", cost[i][j]<INF?cost[i][j]:-1);
      puts("");
      }*/

    int res1, res2 = INF;
    rep(i, town){
      int sum = 0;
      rep(j, town) if(cost[i][j] < INF) sum += cost[i][j];
      if(res2 > sum){
	res2 = sum;
	res1 = i;
      }
    }
    printf("%d %d\n", res1, res2);
  }
  return 0;
}