#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <math.h>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n ; i++)
#define pb push_back
static const int INF = 1000000;
static const int MAX = 100;

struct edge {int st, fin, cost;};

int d[MAX][MAX];

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

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

int main(void){
  int n;
  cin >> n;

  rep(i,10){
    rep(j,10){
      d[i][j] = ( ( i == j ) ? 0 : INF);
    }
  }

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

  floyd(10);
  int sum = 0;
  int minsum = INF;
  int min_i = 0;

  rep(i,10){
    rep(j,10){
      if( d[i][j] != INF){
        sum += d[i][j];
      }
    }
    //cout << "from " << i << " " << sum << endl;
    if(minsum > sum && sum != 0){
      min_i = i;
      minsum = sum;
    }
    sum = 0;
  }
  cout << min_i << " " << minsum << endl;
}