#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 int INF=1<<30;
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;

int dp[100][100];
bool vis[100];

int main()
{
    //freopen("1","r",stdin);
    int i,j,t;
    while(scanf("%d",&m)!=EOF&&m){
        memset(dp,-1,sizeof(dp));
        memset(vis,false,sizeof(vis));
        n=0;
        for(i=0;i<m;i++){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            dp[a][b]=dp[b][a]=c;
            vis[a]=vis[b]=true;
        }
        for(i=0;i<20;i++)dp[i][i]=0;
        for(i=0;i<20;i++){
            for(j=0;j<20;j++){
                for(t=0;t<20;t++){
                    if(dp[i][j]!=-1&&dp[j][t]!=-1){
                        if(dp[i][t]==-1)dp[i][t]=dp[i][j]+dp[j][t];
                        else dp[i][t]=min(dp[i][t],dp[i][j]+dp[j][t]);
                    }
                }
            }
        }
        int ans=INF,ob=0;
        for(i=0;i<n;i++){
            int tem=0;
            if(!vis[i])continue;
            for(j=0;j<n;j++){
                if(!vis[j])continue;
                tem+=dp[i][j];
            }
            //cout<<tem<<endl;
            if(tem<ans){
                ans=tem;
                ob=i;
            }
        }
        printf("%d %d\n",ob,ans);
    }
    return 0;
}