#include <bits/stdc++.h>

#define rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << x << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

const int INF = 10000000;

int main()
{
    int n;
    while (n = in()){
        int town[16][16];
        rep(i, 16) rep(j, 16) town[i][j] = INF;
        rep(i, 16) town[i][i] = 0;
        int maxi = 0;
        rep(i, n){
            int f, t, c;
            f = in();
            t = in();
            c = in();
            maxi = max(maxi, f);
            maxi = max(maxi, t);
            town[t][f] = town[f][t] = c;
        }
        n = maxi + 1;
        rep(k, n) rep(i, n) rep(j, n) town[i][j] = min(town[i][j], town[i][k] + town[k][j]);
        vector<pair<int, int> > costs;
        rep(i, n){
            int cost = 0;
            rep(j, n){
                cost += town[i][j];
            }
            costs.push_back(make_pair(cost, i));
        }
        sort(costs.begin(), costs.end());
        printf("%d %d\n", costs[0].second, costs[0].first);
    }
    return (0);
}