#include <cstdio>
#include <algorithm>
using namespace std;

const int INF = 10000000;

int main(){
  
  while(1){
  
  int n;
  int d[11][11] = {0};
  int m=0;
  
  scanf("%d",&n);
  
  if(n == 0)break;
    for(int i = 0;i < 10;i++){
    for(int j = 0;j < 10;j++){
      if(i == j) continue;
      d[i][j] = INF;
    }
  }
  
  for(int i = 0;i < n;i++){
    int a,b,c;
    
    scanf("%d%d%d",&a,&b,&c);
    
    d[a][b] = c;
    d[b][a] = c;
    
    m = max(m,max(a,b));
    
  }
  
  m++;
  
  for(int i = 0;i < m;i++){
    for(int j = 0;j < m;j++){
      for(int k = 0;k < m;k++) d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
    }
  }
  int ans1=0,ans2=100000000;
  for(int i = 0;i < m;i++){
    int tmp = 0;
    for(int j = 0;j < m;j++){
      if(i == j)continue;
      tmp += d[i][j];
    }
    if(ans2 > tmp){
      ans2 = tmp;
      ans1 = i;
    }
  }
  
  
  printf("%d %d\n",ans1,ans2);
  }
  
  return 0;
}
      
  
  
