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<cstdlib>
#include<math.h>
#include<iostream>
#include<cstring>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<algorithm>
#include<queue>
#include<vector>
#include<time.h>
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
const int INF=1<<30;
typedef long long ll;
const double eps = 1e-8;
const int row=3000;
const int cow=220;
const int MAXN=cow*cow;

int n,m;

int dp[100][100];
bool vis[100];

int main()
{
    //freopen("1","r",stdin);
    int i,j,t;
    while(scanf("%d",&m)!=EOF&&m){
        memset(dp,-1,sizeof(dp));
        memset(vis,false,sizeof(vis));
        n=0;
        for(i=0;i<m;i++){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            dp[a][b]=dp[b][a]=c;
            vis[a]=vis[b]=true;
        }
        for(i=0;i<20;i++)dp[i][i]=0;
        for(i=0;i<20;i++){
            for(j=0;j<20;j++){
                for(t=0;t<20;t++){
                    if(dp[i][j]!=-1&&dp[j][t]!=-1){
                        if(dp[i][t]==-1)dp[i][t]=dp[i][j]+dp[j][t];
                        else dp[i][t]=min(dp[i][t],dp[i][j]+dp[j][t]);
                    }
                }
            }
        }
        int ans=INF,ob=0;
        for(i=0;i<n;i++){
            int tem=0;
            if(!vis[i])continue;
            for(j=0;j<n;j++){
                if(!vis[j])continue;
                tem+=dp[i][j];
            }
            //cout<<tem<<endl;
            if(tem<ans){
                ans=tem;
                ob=i;
            }
        }
        printf("%d %d\n",ob,ans);
    }
    return 0;
}

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

#define min(a,b) ((a<b) ? a : b)

int cost[10][10];

void calcPath(int n)
{
    int s,i,j,k,d;

    for (s = 0 ; s < 45 ; s++) {
        for (i = 0 ; i <= n ; i++) {
            for (j = 0 ; j <= n ; j++) {
                d = cost[i][j];
                for (k = 0 ; k <= n ; k++) {
                    if ( (cost[i][k] < 0) || (cost[k][j] < 0) ) continue;
                    d = (d >= 0) ? min(d,cost[i][k]+cost[k][j]) : cost[i][k]+cost[k][j];
                }
                cost[i][j] = d;
            }
        }
    }
}

// ----------------------------------------------------------------
int main(void)
{
    int i,j,len, minpath,n, townA, townB, t, townLast, bestTownNo;

    while(cin >> n) {
        if (n <= 0) break;
        // Initialize variables
        memset(cost,-1,sizeof(cost));
        townLast = -1;
        // read & set data
        for (i = 0 ; i < n ; i++) {
            cin >> townA;
            cin >> townB;
            cin >> t;  // time A->B
            cost[townA][townA] = 0;
            cost[townB][townB] = 0;
            cost[townA][townB] = t;
            cost[townB][townA] = t;
            if (townA > townLast) townLast = townA;
            if (townB > townLast) townLast = townB;
        }
        // calculate minimum path
        calcPath(townLast);
        // find best solution
        bestTownNo = -1;
        minpath = -1;
        for (i = 0 ; i <= townLast ; i++) {
            len = 0;
            for (j = 0 ; j <= townLast ; j++) {
                if(cost[i][j] > 0) len += cost[i][j];
            }
            if ((minpath < 0) || (len < minpath)) {
                minpath = len;
                bestTownNo = i;
            }
        }
        cout << bestTownNo << " " << minpath << endl;
    }

    return 0;
}

C++: #include<stdio.h>  
#include<string.h>  
#include<algorithm>  
#define INF 0xfffffff  
using namespace std;  
int map[1100][1100];  
int main()  
{  
    int n,m,k,i,j,a,b,c,sum1;  
    while(scanf("%d",&n),n)  
    {  
        for(i=0;i<1100;i++)  
        for(j=0;j<1100;j++)  
        {  
            map[i][j]=INF;  
            map[i][i]=0;  
        }  
        int Max=0;  
        for(i=0;i<n;i++)  
        {  
            scanf("%d%d%d",&a,&b,&c);  
            Max=max(Max,a);  
            Max=max(Max,b);  
            map[a][b]=c;  
            map[b][a]=c;  
        }  
        for(k=0;k<=Max;k++)  
        for(i=0;i<=Max;i++)  
        for(j=0;j<=Max;j++)  
        {  
            if(map[i][j]>map[i][k]+map[k][j])  
            map[i][j]=map[i][k]+map[k][j];  
        }  
        int sum=INF;  
        int ans=0;  
        for(i=0;i<=Max;i++)  
        {  
            sum1=0;  
            for(j=0;j<=Max;j++)  
            {  
               sum1+=map[i][j];  
            }  
            if(sum1<sum)  
            {  
                sum=sum1;  
                ans=i;  
            }  
        }  
        printf("%d %d\n",ans,sum);  
    }  
    return 0;  
}

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

int main(){
    //n...道の数
    while(true){
        int n;
        cin >> n;

        if(n==0){
            return 0;
        }

        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] = 10000;
                }
            }
        }

        int m = 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>m){
                m = a+1;
            }
            if(b+1>m){
                m = b+1;
            }
        }

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


        int mintime = 10000;
        int town = 0;

        for(int i=0;i<m;i++){
            int sumtime = 0;
            for(int j=0;j<m;j++){
                sumtime += time[i][j];
            }
            if(mintime>sumtime){
                mintime = sumtime;
                town = i;
            }
        }

        cout << town << " " << mintime << endl;
    }
    
}