#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<iostream>
#include<cstring>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<algorithm>
#include<queue>
#include<vector>
#include<time.h>
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
const long long INF=1e17;
typedef long long ll;
const double eps = 1e-8;
const int row=3000;
const int cow=220;
const int MAXN=cow*cow;

int n,m;

ll dp[100][100];
bool vis[100];

int main()
{
    //freopen("1","r",stdin);
    int i,j,t;
    while(scanf("%d",&m)!=EOF&&m){
        memset(vis,false,sizeof(vis));
        for(i=0;i<50;i++)for(j=0;j<50;j++)dp[i][j]=INF;
        for(i=0;i<m;i++){
            ll a,b,c;
            cin>>a>>b>>c;
            dp[a][b]=dp[b][a]=c;
            vis[a]=vis[b]=true;
        }


        for(i=0;i<50;i++){
            for(j=0;j<50;j++){
                for(t=0;t<=m;t++){
                    if(dp[i][j]!=INF&&dp[j][t]!=INF){
                        dp[i][t]=min(dp[i][t],dp[i][j]+dp[j][t]);
                    }
                }
            }
        }
        ll ans=1e18,ob=0;
        for(i=0;i<50;i++){
            ll tem=0;
            if(!vis[i])continue;
            for(j=0;j<50;j++){
                if(!vis[j])continue;
                tem+=dp[i][j];
            }
            if(tem<ans){
                ans=tem;
                ob=i;
            }
        }
        cout<<ob<<" "<<ans<<endl;
    }
    return 0;
}