
import std.stdio, std.typecons, std.algorithm, std.conv;

void main() {
  for (int times; scanf("%d", &times), times != 0;) {
    double[][] dp = new double[][](10, 10);
    double[] d = new double[](10);
    double m = double.infinity, ans = -1;
    d[] = 0.0;
    foreach(ref i; dp)
      foreach(ref j; i) j = double.infinity;
    for(int i = 0; i < 10; i++) dp[i][i] = 0;
    foreach(t; 0..times) {
      int from, to, time;
      scanf("%d %d %d", &from, &to, &time);
      dp[from][to] = time.to!double;
      dp[to][from] = time.to!double;
    }
    
    for(int k = 0; k < 10; k++)
      for(int i = 0; i < 10; i++)
        for(int j = 0; j < 10; j++)
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    
    for(int i = 0; i < 10; i++) {
      for(int j = 0; j < 10; j++) {
        if (dp[i][j] != double.infinity) {
          d[i] += dp[i][j];
        }
      }
    }

    for(int i = 0; i < 10; i++) {
      if (m > d[i] && d[i] != 0) {
        m = d[i];
        ans = i;
      }
    }
    writeln(ans, " ", m);
  }
}