//can not solve problem with negative edges
//worst O(V^2)
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int INF = 0x7fffffff;
const int MAXV=100+5;

int cost[MAXV][MAXV];
int d[MAXV];
bool used[MAXV];
int prev_vertex[MAXV]; //for path restore
int V;

void dijkstra(int s)
{
    fill(d, d+V, INF);
    fill(used, used+V, false);
    fill(prev_vertex, prev_vertex+V, -1);
    d[s]=0;

    while(true)
    {
        int v=-1;
        for(int u=0;u<V;++u)
            if(!used[u] && (v==-1||d[u]<d[v])) v=u;

        if(v==-1) break;

        used[v] = true;
        for(int u=0;u<V;++u)
        {
            if(cost[v][u]!=INF&&cost[v][u]!=-1&&d[u]>d[v]+cost[v][u])
            {
                d[u] = d[v]+cost[v][u];
                prev_vertex[u] = v;
            }
        }
    }
}

//get min path to t
vector<int> get_path(int t)
{
    vector<int> path;
    for(; t!=-1; t=prev_vertex[t]) path.push_back(t);
    reverse(path.begin(), path.end());
    return path;
}

int main()
{
    int n, a, b, w;
    while(scanf("%d", &n)!=EOF){
        if(n==0) break;
        memset(cost, -1, sizeof(cost));
        int minv=100,maxv=0;
        for(int i=0;i<n;++i){
            scanf("%d%d%d", &a, &b, &w);
            cost[a][b] = cost[b][a] = w;
            if(a<minv) minv = a;
            if(b<minv) minv = b;
            if(a>maxv) maxv = a;
            if(b>maxv) maxv = b;
        }
        V = maxv + 1;
        for(int i=0;i<V;++i) cost[i][i] = 0;
        int ansi = 0;
        int ansd = INF;
        for(int i=0;i<V;++i){
            dijkstra(i);
            int tmp = 0;
            for(int i=0;i<V;++i){
                tmp += d[i];
            }
            if(tmp < ansd){
                ansi = i;
                ansd = tmp;
            }
        }
        printf("%d %d\n", ansi, ansd);
    }
    return 0;
}
