#include <iostream>
#include <set>
#include "procpn.hpp"

using namespace std;
using namespace procon;

int main(){
    int e;
    set<int> v;
    int d[MAX_V][MAX_V];
    while(cin >> e,e){
        fill((int*)d,(int*)d + MAX_V * MAX_V,INF);
        FOR(i,0,e){
            int f,t,p;
            cin >> f >> t >> p;
            d[f][t] = p;
            v.insert(f); v.insert(t);
        }
        FORI(i,v) d[*i][*i] = 0;

        warshall_floyed(MAX_V,d);
        int town = 0;
        int m = INF;
       FORI(i,v){
            int t = 0;
            FORI(j,v){
                t += d[*i][*j];
            }
            if(m < t) continue;
            m = t;
            town = *i;
        }
        cout << town << " " << m << endl;
    }
    return 0;
}