#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int sum(const vi& a)
{
	return accumulate(allof(a),0);
}

int main()
{
	for(int m;cin>>m,m;){
		int n;
		vvi dist;
		{
			vi a(m),b(m),w(m);
			rep(i,m) cin>>a[i]>>b[i]>>w[i];
			n=max(*max_element(allof(a)),*max_element(allof(b)))+1;
			dist.assign(n,vi(n,1<<29));
			rep(i,m)
				dist[a[i]][b[i]]=dist[b[i]][a[i]]=w[i];
			rep(i,n)
				dist[i][i]=0;
		}
		
		rep(k,n) rep(i,n) rep(j,n)
			dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		
		int res=0;
		rep(i,n)
			if(sum(dist[i])<sum(dist[res]))
				res=i;
		cout<<res<<" "<<sum(dist[res])<<endl;
	}
	
	return 0;
}