#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

const int MAXV = 11, INF = 10000;

struct edge{int to, cost;};

typedef pair<int ,int> pp;

int d[MAXV];
int n, a, b, c, t, anst, ansc, minc;

int main()
{
    while(cin >> n && n)
    {
        anst = MAXV;
        ansc = INF;
        t = 0;
        vector<edge> g[MAXV];
        

        REP(n)
        {
            cin >> a >> b >> c;
            g[a].push_back((edge){b, c});
            g[b].push_back((edge){a, c});

            t = max(t, a+1);
            t = max(t, b+1);
        }

        rep(k,t)
        {
            memset(d, INF, sizeof(d));
            d[k] = 0;
            priority_queue<pp, vector<pp>, greater<pp> > que;
            que.push(pp(0, k));

            while(!que.empty())
            {
                pp p = que.top(); que.pop();
                int v = p.second;
                if(d[v] < p.first ) continue;

                rep(i,g[v].size())
                {
                    edge e = g[v][i];
                    if(d[e.to] > d[v] + e.cost)
                    {
                        d[e.to] = d[v] + e.cost;
                        que.push(pp(d[e.to], e.to));
                    }
                }
            }
            minc = 0;
            REP(t) minc += d[i];
            if(minc < ansc) {anst = k; ansc = minc;}
        }
        cout << anst << " " << ansc << endl;
    }

    return 0;
}