#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define Inf 1000000
int dist[105][105];
int main()
{
    int n,a,b,s;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        for (int i=0; i<100; i++)
        {
            for (int j=0; j<100; j++)
            {
                dist[i][j]=Inf;
                dist[j][i]=Inf;
                if(i==j) dist[i][j]=0;
            }
        }
        int m=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d%d%d",&a,&b,&s);
            dist[a][b]=s;
            dist[b][a]=s;
            m=max(m,max(a,b)+1);
        }
        //printf("%d\n",m);
        for (int i=0; i<m; ++i)
        {
            for (int j=0; j<m; ++j)
            {
                for (int k=0; k<m; ++k)
                {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                    /*if (dist[i][k] + dist[k][j] < dist[i][j] )
                    {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }*/
                }
            }
        }
        int aa[100],weizhi[10000];
        memset(aa,0,sizeof(aa));
        for(int i=0; i<m; i++)
        {
            for(int j=0; j<m; j++)
            {
                aa[i]+=dist[i][j];
            }
            weizhi[aa[i]]=i;//weizhi[aa[0]]
        }
        //sort(aa,aa+m);
        int ans = min_element(aa,aa + m) - aa;
        printf("%d %d\n",ans,aa[ans]);
    }
    return 0;
}