/*
 * 1.cpp
 *
 *  Created on: 2015-10-29
 *      Author: hp
 */
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define mem(a) memset(a,0,sizeof(a))
#define pfn printf("\n")
#define ll __int64
#define pfd(a) printf("%d\n",a)
#define pf2d(a,b) printf("%d %d\n",a,b)
#define pf3d(a,b,c) printf("%d %d %d\n",a,b,c)
#define pfs(a) printf("%s\n",a)
#define sfd(a) scanf("%d",&a)
#define sf2d(a,b) scanf("%d%d",&a,&b)
#define sf3d(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define sf	scanf
#define pf	printf
#define fr(i,n) for(int i=0;i<n;i++)
#define INF 0x7fffffff   //INT_MAX
#define inf 0x3f3f3f3f   //int
const double PI = acos(-1.0);
const double e = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> inline T Min(T a, T b) { return a < b ? a : b; }
template<class T> inline T Max(T a, T b) { return a > b ? a : b; }
bool cmpbig(int a,int b){return a>b;}
bool cmpsmall(int a,int b){return a<b;}
using namespace std;
int dp[20][20];
int n;
void floyd(){
    for(int k=0;k<n;k++)
    	for(int i=0;i<n;i++)
    		for(int j=0;j<n;j++)
    			dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
}
int main()
{
	//freopen("1.txt","r",stdin);
	
	int x,y;
    int d;
    while(~scanf("%d",&n) &&n){
    	int max_n=-1;
       for(int i=0;i<n;i++)
    	   for(int j=0;j<n;j++)
    		   dp[i][j]=inf;
       for(int i=0;i<n;i++){
    	   scanf("%d %d %d",&x,&y,&d);
    	   dp[x][y]=d;
    	   dp[y][x]=d;
    	   dp[i][i]=0;
    	   int tem=max(x,y);
    	   max_n=max(tem,max_n);
    	  //printf("%d %d d=%d\n",dp[x][y],dp[y][x],d);
       }
        floyd();
        int ans=inf;
        int pos;
        int sum=0;

        for(int i=0;i<=max_n;i++){
            sum=0;
        	for(int j=0;j<=max_n;j++){
        		if(dp[i][j]<inf && dp[i][j]!=0)
        		  sum+=dp[i][j];
        	}
            if(sum<ans){
            	ans=sum;
            	pos=i;
            	//printf("ans=%d i=%d\n",ans,pos);
            }
       }

        printf("%d %d\n",pos,ans);
    }

	return 0;
}