//#include <bits/stdc++.h>

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_V = 12, MAX_L = 2505;
const int INF = 1e+9+1;

int  V,E;
int G[MAX_V][MAX_V];


//弗洛伊德模板题
void solve(){
    for(int k = 0;k < V;k++){
        for(int i =0 ;i < V;i++){
            for(int j = 0;j <V;j++){
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }

    int minSum = INF, minarg = 0;
    for(int i = 0;i < V;i++){
        int sum = 0;
        for(int j = 0;j < V;j++){
            sum+=G[i][j];
        }
        if(sum < minSum){
            minSum = sum;
            minarg = i;
        }
    }
    cout<<minarg<<' '<<minSum<<endl;
}

/*
6
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0
 */


int main(){
    ios::sync_with_stdio(false);
    while(cin>>E)
    {
        if(E == 0) break;
        V = 0;
        for(int i = 0;i < MAX_V;i++){
            for(int j = 0;j < MAX_V;j++){
                G[i][j] = INF;
                if(i == j) G[i][j] = 0;
            }
        }

        for(int i = 0;i < E;i++){
            int u,v,c;
            cin>>u>>v>>c;
            V = max(V, max(u, v));
            G[u][v] = G[v][u] = c;
        }
        V++;
        solve();

    }

    return 0;

}
