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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d; // グラフの距離を格納した2次元配列（隣接行列）
          // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
	
	while(1){
	
  int n=0, m;

  d = Matrix(10, vector<int>(10, INF));
  for (int i = 0; i < 10; i++) d[i][i] = 0;
  
  
  	
	cin >> m;
	if(m == 0) break;
  
	  for (int i = 0; i < m; i++) {
	    int from, to, cost;
	    cin >> from >> to >> cost;
		if(n<from) n = from;
		if(n<to) n = to;
	    d[from][to] = cost;
	  }
	  
	  n++;
	  
	  warshall_floyd(n);
	  
	
	  
	  int sum[100]  ; 
	  int a ;
	  
	  for (int i = 0; i < n ; i++) {
	  	sum[i] = 0;
	    for (int j = 0; j < n; j++) {
			
			
			if(j > i )	sum[i] +=  d[i][j];
			
			else sum[i] +=  d[j][i];
	    }
	  }
	  
	  int ans = sum[0];
	  int num = 0;
	  
	  for(int i = 0; i<n-1 ; i++){
	  	if(sum[i] > sum[i+1]){
			ans = sum[i+1];
			num = i+1;
	  	}
	  }
	  
	  cout << num << " " << ans << endl;
  
  }
  
    
  
  
  return 0;
}

C++: #include <iostream>

using namespace std;

const int INF = 1<<29;
const int N = 10;

int main(){
    int n;
    while(true){
        cin >> n;
        if(!n) break;

        int dp[N][N];
        for(int i=0;i<N;i++)
        for(int j=0;j<N;j++) dp[i][j] = INF;

        int a,b,c;
        while(n--){
            cin >> a >> b >> c;
            dp[a][b] = c;
            dp[b][a] = c;
        }

        for(int k=0;k<N;++k){
            for(int i=0;i<N;++i){
                for(int j=0;j<N;++j){
                    if(dp[i][j] > dp[i][k] + dp[k][j])
                        dp[i][j] = dp[i][k] + dp[k][j];
                }
            }
        }

    int sum[N];
    for(int i=0;i<N;i++){
        sum[i] = 0;
        for(int j=0;j<N;j++){
            if(i != j && dp[i][j]!=INF){
                sum[i] += dp[i][j];
            }
        }
    }

    int ans_i = 0;
    for(int i=0;i<N;i++){
        if(sum[i] < sum[ans_i] && sum[i] != 0){
            ans_i = i;
        }
    }

    cout << ans_i << " " << sum[ans_i] << endl;

    }

}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<string.h>
#include<cstring>
const long long INF=0x3f3f3f3f;
using namespace std;
long long ans;
long long n;
int  e[1001][1001];
//int ee[1001][1001];
int main()
{
    int n;
    while(scanf("%d",&n)&&n!=0)
    {
        int sum=0;
        int ssum=INF;
      //  int min=INF;
        int u,v,r;
        int falg;
        memset(e,INF,sizeof(e));
        int Max=0;
        for(int i=0;i<n;i++)
        {
            cin>>u>>v>>r;
            if(e[u][v]>r)
            e[u][v]=r;
            e[v][u]=r;
           Max=max(Max,max(u,v));
        }
        for(int i=0;i<=Max;i++)
        {
            e[i][i]=0;
        }

        for(int i=0;i<=Max;i++)
        {
            for(int j=0;j<=Max;j++)
            {
               for(int k=0;k<=Max;k++)
                if(e[k][i]>e[k][j]+e[j][i])
                {
                   //  sum+=ee[1][i];
                    e[k][i]=e[k][j]+e[j][i];
                    e[i][k]=e[k][j]+e[j][i];
                }
            }
        }
          for(int i=0;i<=Max;i++)
        {
            sum=0;
            for(int j=0;j<=Max;j++)
            {
            if(e[i][j]!=INF)
            sum+=e[i][j];
            }

            if(sum<ssum)
            {
                ssum=sum;
                falg=i;
            }
        }

        cout<<falg<<" "<<ssum<<endl;
    }
    return 0;
}