#include<iostream>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>

using namespace std;


int main(){

    int n;
    vector< vector<int> > map(100,vector<int>(100));
    int a,b,c;
    int ma=0;
    cin >> n;
    vector<int> v(100);
    fill(v.begin(),v.end(),1<<20);
    fill(map.begin(),map.end(),v);
    for(int i=0;i<n;i++){
	cin >> a >> b >> c;
	map[a][b] = c;
	map[b][a] = c;
	ma = max(ma,b);
    }
    for(int i=0;i<ma;i++){
	map[i][i] = 0;
    }
    ma++;
    for(int l=0;l<2;l++){
    for(int i=0;i<ma;i++){
	for(int j=0;j<ma;j++){
	    for(int k=0;k<ma;k++){
		    map[i][j] = min(map[i][j] ,map[i][k] + map[k][j] );
	    }
	}
    }
    }

    bool flag = false;
    int res = 1<<30,t;
    for(int i=0;i<ma;i++){
	a =0;
	for(int j=0;j<ma;j++){
	    a += map[i][j];
	}
	if(a!=0 && res>a){
	    res = a;
	    t = i;
	}
    }
    cout << t<<" " << res << endl;
    
    return 0;
}