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 <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<stdio.h>
#include<string.h>
int min(int x,int y)
{
	return x>y?y:x;
}
int max(int x,int y)
{
	return x>y?x:y;
}
int main()
{
	int n,m,t,a[501][501],z,x,y,maxx;
	while(scanf("%d",&t)&&t)
	{
		memset(a,0,sizeof(a));
		maxx=0;
		for(int i=0;i<t;i++)
		{
			scanf("%d %d %d",&x,&y,&z);
			a[x][y]=z;
			a[y][x]=z;
			a[i][i]=0;
			maxx=max(maxx,max(x,y));
		}
		for(int i=0;i<=maxx;i++)
		{
			for(int j=0;j<=maxx;j++)
			{
				for(int r=0;r<=maxx;r++)
				{
					if(a[i][j]>0&&a[j][r]>0&&a[i][r]==0)
					{
						a[i][r]=a[i][j]+a[j][r];
						a[r][i]=a[i][r];
					}
					else
					a[i][r]=min(a[i][r],a[i][j]+a[j][r]);
				}
			}
		}
		for(int i=0;i<=maxx;i++)
		{
			a[i][i]=0;
			for(int j=0;j<=maxx;j++)
			{
				a[i][j]=max(a[i][j],a[j][i]);
				a[j][i]=a[i][j];
			}
		}
		int ans=999999,pos;
		for(int i=0;i<=maxx;i++)
		{
			int k=0;
			for(int j=0;j<=maxx;j++)
			k+=a[i][j];
			if(k<ans)
			{
				ans=k;
				pos=i;
			}
		}
		printf("%d %d\n",pos,ans);
	}
	return 0;
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int edges[20][20];
int dist[20][20];

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N==0)break;

        int m = 0;

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            edges[x][y] = edges[y][x] = c;

            m = max(m,max(x,y));

        }

        for(int i=0;i<=m;++i)
            for(int j=0;j<=m;++j){
                if(i==j)
                    dist[i][j]=0;
                else if(edges[i][j]==0)
                    dist[i][j]=100000000;
                else
                    dist[i][j]=edges[i][j];
            }

        for(int k=0;k<=m;++k){
            for(int i=0;i<=m;++i)
                for(int j=0;j<=m;++j)
                    dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
        }

        int ans  = 0;
        int msum = 10000000;

        for(int i=0;i<=m;++i){

            int sum = 0;
            for(int j=0;j<=m;++j)
                sum += dist[i][j];

            if(sum<msum){
                ans  = i;
                msum = sum;
            }

        }

        cout << ans << " " << msum << endl;


    }

    return 0;

}

C++: #include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>
using namespace std;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
#define _CRT_SECURE_NO_WARNINGS
int N,V=0;
int m[10][10];
int ans = 100000;
int town = 0;
int tmp = 0;
int main() {
	while (true)
	{
		V = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				m[i][j] = 10000;
			}
		}
		scanf("%d", &N);
		if (N==0) {
			break;
		}
		for (int i = 0; i < N; i++) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			m[a][b] = m[b][a] = c;
			V = max(V, max(a, b));
		}

		for (int i = 0; i <= V; i++) {
			for (int j = 0; j <= V; j++) {
				for (int k = 0; k <= V; k++) {
					m[j][i]=m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
				}
			}
		}
		ans = 100000;
		tmp = 0;
		for (int i = 0; i <= V; i++) {
			for (int j = 0; j <= V; j++) {
				if (i != j) {
					tmp += m[i][j];
				}
			}
			if (ans > tmp) {
				ans = tmp;
				tmp = 0;
				town = i;
			}
		}
		printf("%d %d\n", town, ans);
	}
	return 0;
}