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;
 
int main(){
    while (true){
        int array[10][10], a, b, c, i, j, k, m = 0, n, ans_map = 0, ans_cost = 1 << 25;
        scanf("%d", &n);
        if (!n){
            return 0;
        }
        for (i = 0; i < 10; i++){
            for (j = 0; j < 10; j++){
                if (i == j){
                    array[i][j] = 0;
                }
                else{
                    array[i][j] = 1 << 25;
                }
            }
        }
        for (i = 0; i < n; i++){
            scanf("%d %d %d", &a, &b, &c);
            array[a][b] = array[b][a] = c;
            m = max(m, b);
        }
        m++;
        for (i = 0; i < m; i++){
            for (j = 0; j < m; j++){
                for (k = 0; k < m; k++){
                    array[j][k] = array[k][j] = min(array[j][k], array[j][i] + array[i][k]);
                }
            }
        }
        for (i = 0; i < m; i++){
            int cost = 0;
            for (j = 0; j < m; j++){
                cost += array[i][j];
            }
            if (cost < ans_cost){
                ans_cost = cost;
                ans_map = i;
            }
        }
        printf("%d %d\n", ans_map, ans_cost);
    }
}

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[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++){
				if(T[i][j]>T[i][k]+T[k][j]){
					T[i][j]=T[i][k]+T[k][j];
				}
			}
		}
	}

	int town;
	int ti=INF;
	for(int i=m;i>=0;i--){
		int t=0;
		for(int j=0;j<m;j++){
			t+=T[i][j];
		}
		if(ti>=t){
			ti=t;
			town=i;
		}
	}
	cout<<town<<" "<<ti<<endl;
	

	}

	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const int MAX_N = 10;
const int INF = 100000000;
int N;//N是道路的数量，不是点的数量 
int dp[MAX_N][MAX_N];
bool input(){
	fill(dp[0],dp[0]+MAX_N*MAX_N,INF);
	scanf("%d",&N);
	if(N == 0) return false;
	int a,b,c;
	int max_N = 0;
	for(int i = 0;i < N;++i){
		scanf("%d%d%d",&a,&b,&c);
		dp[a][b] = dp[b][a] = c;
		max_N = (max(a,b) > max_N ? max(a,b) : max_N);
	}
	N = max_N + 1;//N变为点的数量 
	for(int i = 0;i < N;++i) dp[i][i] = 0;
	return true;
}

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

int main(){
	while(input()){
		shortest_path();
		int street, res = INF;
		for(int i = 0;i < N;++i){
			int tmp = 0;
			for(int j = 0;j < N;++j) tmp += dp[i][j];
			if(tmp < res){
				res = tmp;
				street = i;
			}
		}
		cout << street << " " << res << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX 50
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];

int dijkstra(int s,int g){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = minnum ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = minnum ; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            if(t < v[i]) v[i] = t;
        }
    }
    
    return v[g];
}


int main(){
    int a,b,c;
    
    for(int i = 0 ; i < MAX ; i++)
        for(int j = 0 ; j < MAX ; j++)
            r[i][j] = INF;

    while(cin >> n,n){
        maxnum = 0;
        minnum = INF;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = c;
            r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
            minnum = min(minnum,min(a,b));
        }

        int mx = INF, num = 0;
        for(int i = minnum ; i <= maxnum ; i++){
            int sum = 0;
            for(int j = minnum ; j <= maxnum ; j++){
                if(i == j) continue;
                if(dijkstra(i,j)!=INF) sum += dijkstra(i,j);
            }
            if(sum < mx){
                mx = sum;
                num = i;
            }
        }
        cout << num << ' ' << mx << endl;
    }
    
    return 0;
}

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;
		n = max(n,from);
		n = max(n,to);
	    d[from][to] = cost;
		d[to][from] = 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++) {
			
			
			sum[i] +=  d[i][j];
			
	    }
	  }
	  
	  int ans = sum[0];
	  int num = 0;
	  
	  for(int i = 0; i<n-1 ; i++){
	  	if(ans > sum[i+1]){
			ans = sum[i+1];
			num = i+1;
	  	}
	  }
	  
	  cout << num << " " << ans << endl;
  
  }
  
    
  
  
  return 0;
}