Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

const INF = 0x7FFFFFFF

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		matrix := make([][]int, 10)
		for i := range matrix {
			matrix[i] = make([]int, 10)
		}
		for i := range matrix {
			for j := range matrix[i] {
				if i == j {
					matrix[i][j] = 0
				} else {
					matrix[i][j] = INF
				}
			}
		}
		num := 0
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			from, _ := strconv.Atoi(buf[0])
			to, _ := strconv.Atoi(buf[1])
			cost, _ := strconv.Atoi(buf[2])
			if num < from {
				num = from
			}
			if num < to {
				num = to
			}
			matrix[from][to] = cost
			matrix[to][from] = cost
		}
		num++
		for i := 0; i < num; i++ {
			for j := 0; j < num; j++ {
				for k := 0; k < num; k++ {
					if matrix[j][i]+matrix[i][k] < matrix[j][k] {
						matrix[j][k] = matrix[j][i]+matrix[i][k]
					}
				}
			}
		}
		ans, sum := 0, INF
		for i := 0; i < num; i++ {
			now := 0
			for j := 0; j < num; j++ {
				now += matrix[i][j]
			}
			if sum > now {
				sum = now
				ans = i
			}
		}
		fmt.Println(ans, sum)
	}
}

C++: #include<stdio.h>
int g[10][10];
int main(){
	int a;
	while(scanf("%d",&a),a){
		
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				if(i==j)g[i][j]=0;
				else g[i][j]=999999999;
		int t=0;
		for(int i=0;i<a;i++){
			int c,d,e;
			scanf("%d%d%d",&c,&d,&e);
			if(t<c)t=c;
			if(t<d)t=d;
			g[c][d]=e;
			g[d][c]=e;
		}
		t++;
		for(int k=0;k<t;k++){
			for(int i=0;i<t;i++){
				for(int j=0;j<t;j++){
					if(g[i][k]+g[k][j]<g[i][j])g[i][j]=g[i][k]+g[k][j];
				}
			}
		}
		int n=0;
		long long int ans=999999999;
		for(int i=0;i<t;i++){
			long long int now=0;
			for(int j=0;j<t;j++)now+=g[i][j];
			if(ans>now){
				ans=now;
				n=i;
			}
		}
		printf("%d %lld\n",n,ans);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>

typedef long long LL;

using namespace std;
bool book[15];
int e[15][15];
int e1[15];
int dis[15];
int inf=0x3f3f3f3f;
int ss;
void Dijkstra(int n,int n1)
{
    int i,j,k,minn,u;
    for(i=n1; i<=n; i++)
    {
        minn=inf;
        for(j=n1; j<=n; j++)
            if(dis[j]<minn && book[j]==0)
                minn=dis[j],u=j;
        book[u]=1;
        for(k=n1; k<=n; k++)
        {
            if(e[u][k]<inf)
            {
                if(dis[k]>dis[u]+e[u][k])
                    dis[k]=dis[u]+e[u][k];
            }
        }
    }
}

int main()
{
    int n;
    while(scanf("%d",&n) && n!=0)
    {
        memset(e,0,sizeof(e));
        memset(e1,0,sizeof(e1));
        int i,j,maxx=0,min1=inf;
        for(i=0; i<=9; i++)
            for(j=0; j<=9; j++)
            {
                if(i==j)e[i][j]=0;
                else e[i][j]=inf;
            }
        for(i=0; i<n; i++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            if(a>maxx)maxx=a;
            if(b>maxx)maxx=b;
            if(min1>a)min1=a;
            if(min1>b)min1=b;
            if(e[a][b]==inf)
                e[a][b]=e[b][a]=c;
        }
        int minn=inf,t;
        for(j=min1; j<=maxx; j++)
        {
            ss=0;
            for(i=min1; i<=maxx; i++)
            {
                dis[i]=e[j][i];
                book[i]=0;
            }
            book[j]=1;
            Dijkstra(maxx,min1);
            int sum=0;
            for(i=min1; i<=maxx; i++)
            {
                sum=sum+dis[i];
            }
            if(minn>sum)minn=sum,t=j;
        }

        printf("%d %d\n",t,minn);
    }
    return 0;
}

C++: #include <cstdio>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <functional>
#include <string.h>
using namespace std;
const int INF = 1000000000;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,start,end) for(int i=(start);i<(end);++i)
#define pint(i) printf("%d\n",(i))
#define pint2(i,j) printf("%d %d\n",(i),(j))
#define pint3(i,j,k) printf("%d %d %d\n",(i),(j),(k))
#define gint(i) scanf("%d",&(i))
#define gint2(i,j) scanf("%d %d",&(i),&(j))
#define gint3(i,j,k) scanf("%d %d %d",&(i),&(j),&(k))
#define init(tar,val) memset((tar),(val),sizeof((tar)))
#define show(tar,len) for(int i=0;i<(len);++i) \
	cout<<tar[i]<<' ';\
	cout<<endl;




class bignum{
public:
	bignum(int size = 4) :len(size){
	}
	~bignum(){
	}
	int size()const{
		return len;
	}
	//int get(int id)const{
	//	return num[id];
	//}
	friend ostream &operator<<(ostream &output, const bignum &b){
		bool stu = false;
		for (int i = int(b.len - 1); i >= 0; --i){
			if (stu)
				printf("%09d", b.num[i]);
			else if (b.num[i] > 0){
				printf("%d", b.num[i]);
				stu = true;
			}
		}
		if (stu == false)
			printf("0");
		return output;
	}
	const bignum& operator+=(const bignum&right){
		int add = 0;
		for (int i = 0; i < len; ++i){
			int tmp = 0;
			if (i < right.size()){
				tmp = right.num[i] + num[i] + add;
			}
			else{
				tmp = num[i] + add;
			}
			num[i] = tmp%gap;
			add = tmp / gap;
		}
		return *this;
	}
	const bignum& operator=(const bignum&right){
		for (int i = 0; i < len; ++i){
			num[i] = right.num[i];
		}
		return *this;
	}
	void set(int a){
		for (int i = 0; i < len; ++i){
			num[i] = a%gap;
			a /= gap;
		}
	}
private:
	int  num[4];
	int len;
	static const int gap = 1000000000;
};


//inline int id(int i){
//	return i & 1;
//}
//
//inline int last(int i){
//	return (i - 1) & 1;
//}
//
//void myshow(int i){
//	rep(j, 0, ){
//		cout << dp[id(i)][j] << ' ';
//	}
//	cout << endl;
//}


//#define my_debug

const int MAX_NUM = 15;

int n;
int len[MAX_NUM][MAX_NUM];
int stu[MAX_NUM];
set<int> cache;
void myinit(){
	rep(i, 0, MAX_NUM)
		rep(j, 0, MAX_NUM){
		if (i == j)
			len[i][j] = 0;
		else
			len[i][j] = INF;
	}
}


void solve(){
	rep(i, 0, MAX_NUM){
		rep(j, 0, MAX_NUM){
			rep(k, 0, MAX_NUM){
				len[i][j] = min(len[i][j], len[i][k] + len[k][j]);
			}
		}
	}
	int out = INF, t = 0;
	for (int i : cache){
		int tmp = 0;
		for (int j : cache){
			tmp += len[i][j];
		}
		if (tmp && tmp < out){
			out = tmp;
			t = i;
		}
	}
	pint2(t, out);
	//cout << t << ' ' << out << endl;
}

int main(){
#ifdef my_debug
	freopen("a.in", "r", stdin);
#endif
	while (gint(n) != EOF){
		if (n == 0)
			break;
		fill(stu, stu + MAX_NUM, INF);
		myinit();
		cache.clear();
		int tmp1, tmp2;
		rep(i, 0, n){
			gint2(tmp1, tmp2);
			int tmp;
			gint(tmp);
			len[tmp2][tmp1] = len[tmp1][tmp2] = tmp;
			cache.insert(tmp1);
			cache.insert(tmp2);
		}
		solve();
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int n, m, a, b, c, _end;
int x[10][10];

int bfs(int p, int a) {
	int s[10], minx = 114514, sum;
	sum = 0;
	memset(s, 127, sizeof(s));
	s[a] = 0;
	for (int l = 0; l < p; l++) {
		for (int o = 0; o < p; o++) {
			if (s[o] < 114514) {
				for (int q = 0; q < p; q++) {
					if (x[o][q] < 114514) {
						s[q] = min(s[q], s[o] + x[o][q]);
					}
				}
			}
		}
	}
	for (int l = 0; l < p; l++) {
		sum += s[l];
	}
	minx = min(minx, sum);
}

int search(int p) {
	int t[10], maxn = 114514, maxid;
	for (int k = 0; k < p; k++) {
		t[k] = bfs(p, k);
	}
	for (int k = 0; k < p; k++) {
		if (maxn > t[k]) {
			maxn = t[k];
			maxid = k;
		}
	}
	return maxn * 100 + maxid;
}

void _cin() {
	memset(x, 51, sizeof(x));
	n = 0;
	_end = 0;
	cin >> m;
	if (m == 0) { _end = 1; return; }
	for (int i = 0; i < m; i++) {
		cin >> a >> b >> c;
		n = max(n, max(a, b));
		x[a][b] = c;
		x[b][a] = c;
	}
	n += 1;
}

int main() {
	while (true) {
		_cin();
		if (_end == 1) { break; }
		cout << search(n) % 10 << ' ' << search(n) / 10 << endl;
	}
}