#include<iostream>
using namespace std;
const int INF = 10000;

int n;
int d[10];
int D[10];

struct edge {
    int u, v, cost;
    edge() {}
    edge(int uu, int vv, int cc) : 
         u(uu), v(vv), cost(cc) {}
};

edge edges[45];

int main() {
    while (cin>>n) {
    if (n == 0) break;
    int a, b, c;
    int m = 0;
    for (int i = 0; i < n; i++) {
        cin >> a; cin >> b; cin >> c;
        edges[i].u = a;
        edges[i].v = b;
        m = max(a,m); m = max(b,m);
        edges[i].cost = c;
    }
    m++;
    fill(D,D+m,0);
    int res = 0;
    //m 町の数 n道の数
    for (int k = 0; k < m; k++) {
        fill(d,d+m,INF);
        d[k] = 0;
        bool updated = true;
        while (updated) {
            updated = false;
            for (int i = 0; i < n; i++) {
                edge e = edges[i];
                if (d[e.u] != INF && d[e.u] + e.cost < d[e.v]) {
                    updated = true;
                    d[e.v] = d[e.u] + e.cost;
                }
                swap(e.u,e.v);
                if (d[e.u] != INF && d[e.u] + e.cost < d[e.v]) {
                    updated = true;
                    d[e.v] = d[e.u] + e.cost;
                }  
            }
        }
        for (int i = 0; i < m; i++) {
            D[k] += d[i];
        }
    }
    int mm = 0, md = INF;
    for (int i = 0; i < m; i++) {
        if (D[i] < md) {
            mm = i;
            md = D[i];
        }
    }
    cout << mm << " " << md << "\n";
    }
}
