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 <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;
ll dp[15][15];
const ll INF = 1e18;

int main() {
    while(1) {
        cin >> n;
        if(n == 0) break;
        for(int i = 0; i < 10; ++i) {
            for(int j = 0; j < 10; ++j) {
                if(i == j) dp[i][j] = 0;
                else dp[i][j] = INF;
            }
        }
        set<int> town;
        for(int i = 0; i < n; ++i) {
            int a, b; ll c; cin >> a >> b >> c;
            town.insert(a); town.insert(b);
            dp[a][b] = c; dp[b][a] = c;
        }
        for(int k = 0; k < 10; ++k) {
            for(int i = 0; i < 10; ++i) {
                for(int j = 0; j < 10; ++j) {
                    chmin(dp[i][j], dp[i][k]+dp[k][j]);
                }
            }
        }

        ll ans = INF;
        int anstown = 0;
        for(auto x : town) {
            ll sum = 0;
            for(auto y : town) sum += dp[x][y];
            if(ans > sum) {
                ans = sum;
                anstown = x;
            }
        }
        cout << anstown << " " << ans << endl;
    }
}

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

#define INF int(100100)

int main(){
    while(1){
        int n;
        cin >> n;
        
        if(n==0)  break;          //終了の判断

        int time[10][10];

        for(int i=0;i<10;i++){           //配列の初期化
            for(int j=0;j<10;j++){
                if(i==j)
                    time[i][j] = 0;
                else
                    time[i][j] = INF;
            }
        }

        int count(0);
        for(int i=0;i<n;i++){           //配列の設定
            int a,b,c;
            cin >> a >> b >> c;
            time[a][b] = time[b][a] = c;
            if(a+1>count)   count = a+1;
            if(b+1>count)   count = b+1;
        }

        for(int k=0;k<count;k++){           //最短距離に書き換え
            for(int i=0;i<count;i++){
                for(int j=0;j<count;j++){
                    if(time[i][j]>(time[i][k]+time[k][j]))
                        time[i][j] = time[i][k]+time[k][j];
                }
            }
        }

        int v(0),atotal(INF);
        for(int i=0;i<count;i++){
            int total(0);
            for(int j=0;j<count;j++){
                total += time[i][j];
            }
            if(total<atotal){
                v = i;
                atotal = total;
            }
        }
        cout << v << " " << atotal << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<climits>
#include<algorithm>
#define LL long long
using namespace std;

int n,m,d[15][15],sum[15];

int main(void)
{
    while(scanf("%d",&m) && m)
    {
        memset(d,0x3f,sizeof(d));
        int i,j,k;
        for(i=0; i<10; i++)
            d[i][i]=0;
        n=-1;
        while(m--)
        {
            int a,b,c;
            scanf("%d %d %d",&a,&b,&c);
            d[a][b]=min(d[a][b],c);
            d[b][a]=d[a][b];
            n=max(n,max(a,b));
        }
        n++;
        for(k=0; k<n; k++)
        {
            for(i=0; i<n; i++)
            {
                for(j=0; j<n; j++)
                {
                    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                    d[j][i]=d[i][j];
                }
            }
        }
        memset(sum,0,sizeof(sum));
        for(i=0; i<n; i++)
        {
            for(j=0; j<n; j++)
            {
                sum[i]+=d[i][j];
            }
        }
        int id=0,dis=sum[0];
        for(i=1; i<n; i++)
        {
            if(sum[i]<dis)
            {
                dis=sum[i];
                id=i;
            }
        }
        printf("%d %d\n",id,dis);
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<stdlib.h>


using namespace std;
typedef long long LL;
const int INF=1e9;
const int MOD=1e9+7;
const int MAXSIZE=1e6+5;
const double eps=0.0000000001;


int n;
int maps[20][20];
int dis[20];
void Floy(int maxpos)
{
    for(int k=1; k<=maxpos; ++k)
        for(int i=0; i<=maxpos; ++i)
            for(int j=0; j<=maxpos; ++j)
                if(maps[i][j]>maps[i][k]+maps[k][j])
                {
                    maps[i][j]=maps[i][k]+maps[k][j];
                }
}
int sum(int s,int maxpos)
{
    int ans=0;
    for(int i=0;i<=maxpos;i++)
    {
        if(s==i) continue;

        if(maps[s][i]!=INF) ans+=maps[s][i];
        else return INF;
    }
    return ans;
}
//void pr(int maxpos)
//{
//    for(int i=0;i<=maxpos;i++)
//    {
//        for(int j=0;j<=maxpos;j++)
//        {
//            printf("%d\t",maps[i][j]);
//        }
//        printf("\n");
//    }
//}
int main()
{
    while(cin>>n)
    {
        if(n==0) return 0;
        int maxpos=0;
        for(int i=0; i<20; i++)
            for(int j=0; j<20; j++)
                maps[i][j]=INF;
        for(int i=0; i<n; i++)
        {
            int s,t,val;
            scanf("%d%d%d",&s,&t,&val);
            maps[s][t]=val;
            maps[t][s]=val;
            maxpos=max(maxpos,max(s,t));
        }
        Floy(maxpos);
       // pr(maxpos);
        int minn=INF,pos=0;
        for(int i=0;i<=maxpos;i++)
        {
            int ss=sum(i,maxpos);
            if(ss<minn)
            {
                minn=ss;
                pos=i;
            }
        }
        printf("%d %d\n",pos,minn);
    }
    return 0;
}


/**************************************************/
/**             Copyright Notice                 **/
/**  writer: wurong                              **/
/**  school: nyist                               **/
/**  blog  : http://blog.csdn.net/wr_technology  **/
/**************************************************/