#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int edges[20][20];
int dist[20][20];

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N==0)break;

        int m = 0;

        memset(edges,0,sizeof(edges));

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            edges[x][y] = edges[y][x] = c;

            m = max(m,max(x,y));

        }

        for(int i=0;i<=m;++i)
            for(int j=0;j<=m;++j){
                if(i==j)
                    dist[i][j]=0;
                else if(edges[i][j]==0)
                    dist[i][j]=100000000;
                else
                    dist[i][j]=edges[i][j];
            }

        for(int k=0;k<=m;++k){
            for(int i=0;i<=m;++i)
                for(int j=0;j<=m;++j)
                    dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
        }

        int ans  = 0;
        int msum = 10000000;

        for(int i=0;i<=m;++i){

            int sum = 0;
            for(int j=0;j<=m;++j){

                if(dist[i][j]==100000000)continue;
                sum += dist[i][j];
            }

            if(sum<msum){
                ans  = i;
                msum = sum;
            }

        }

        cout << ans << " " << msum << endl;


    }

    return 0;

}