#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef pair<string,int>psi;
const int inf=0x3f3f3f3f;
const int N = 1005;
const int M = 1000005;
const ll mod = 1e9+7;
int road[50][50];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt", "w", stdout);
    int n, x, y, c, maxn;
    while(~scanf("%d", &n) && n)
    {
        maxn=0;
//        for(int i=0;i<=10;i++)
//            for(int j=0;j<=10;j++)
//                road[i][j] = 200;
        memset(road,inf,sizeof(road));
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&x,&y,&c);
            road[x][y]=c;
            road[y][x]=c;
            maxn=max(max(x,y), maxn);
        }
        for(int t=1; t<=maxn; t++)
        {
            for(int i=0;i<=maxn;i++)
            {
                for(int j=0;j<=maxn;j++)
                {
                    road[i][j]=min(road[i][t]+road[t][j], road[i][j]);
                }
            }
        }
        int sum=inf, tmp=0, id;
        for(int i=0;i<=maxn;i++)
        {
            tmp = 0;
            for(int j=0; j<=maxn; j++)
            {
                //cout << "road["<<i<<"][" << j << "]=" << road[i][j] << endl;
                if(i!=j)
                    tmp += road[i][j];
            }
            if(tmp < sum)
            {
                sum = tmp;
                //cout << "sum = " << sum << endl;
                id = i;
            }
        }
        printf("%d %d\n", id, sum);
    }
}

