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<algorithm>

using namespace std;

#define MAXV 10
#define INF 100000000
int main(){

	int n;
	int v;
	int a,b,c;
	int d[MAXV][MAXV];
	int sum,ans,ans_i;

	while(1){

		cin>>n;
		if(n==0) break;

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

		v=-1;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			v=max(v,max(a,b));
			d[a][b]=c;
			d[b][a]=c;
		}

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

		ans=INF,ans_i=-1;
		for(int i=0;i<=v;i++){
			sum=0;
			for(int j=0;j<=v;j++){
				if(d[i][j]!=INF) sum+=d[i][j];
			}
			if(ans>sum&&sum!=0){
				ans=sum;
				ans_i=i;
			}
		}

		cout<<ans_i<<" "<<ans<<endl;

	}

}

C++: #include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int MAX_V = 11;
int d[MAX_V][MAX_V];
int V;
int x[MAX_V];

void floyd_warshall()
{
	for(int k = 0; k < V; k++){
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main()
{
	int E;
	while(cin>>E && E){
		memset(d, 0x3f, MAX_V * MAX_V *sizeof(int));
		for(int i = 0; i < MAX_V; i++){
			d[i][i] = 0;
		}
		V = 0;
		for(int i = 0; i < E; i++){
			int u, v, cost;
			cin>>u>>v>>cost;
			d[u][v] = cost;
			d[v][u] = cost;
			V = max(V, max(v, u) + 1);
		}
		floyd_warshall();
		memset(x, 0, V * sizeof(int));
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				x[i] += d[i][j];
			}
		}
		int ans = min_element(x, x + V) - x;
		cout<<ans<<' '<<x[ans]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#define MAX 10
#define INF 9999999

using namespace std;

int v[MAX + 1];
int road[MAX + 1][MAX + 1];
bool visit[MAX + 1];
int n,mn,MN,Max;

int gettotalDistance(int now){ // ダイクストラ法

  fill( v , v + MAX + 1 , INF );
  fill( visit , visit + MAX + 1 , false );

  v[now] = 0;
  
  while(1){
    
    MN = INF;
    for( int i = 0 ; i <= Max ; i++ ){
      if( !visit[i] && v[i] < MN ){
	MN = v[i];
	mn = i;
      }
    }
    
    if( MN == INF ) break;
    visit[mn] = true;
    
    for( int i = 0 ; i <= Max ; i++ ){
      int t = road[mn][i] + v[mn];
      v[i] = min( v[i] , t );
    }
    
  }
  
  int total = 0;
  for( int i = 0 ; i <= Max ; i++ ) 
    total += v[i];
  
  return total;
}

int main(void){

  while( cin >> n , n ){

    for( int i = 0 ; i <= MAX ; i++ )
      for( int j = 0 ; j <= MAX ; j++ )
	road[i][j] = INF;

    int a,b,c; 
    Max = 0;
    for( int i = 0 ; i < n ; i++ ){
      cin >> a >> b >> c;
      road[a][b] = c;
      road[b][a] = c;
      Max = max( Max , max(a,b) );
    } 
    
    int ans = INF;
    int ansnum;
    for( int i = 0 ; i < Max ; i++ ){
      int ANS = gettotalDistance(i);
      if( ans > ANS ){
	ans = ANS;
	ansnum = i;
      }
    }
    cout << ansnum << " " << ans << endl;
    }
  return 0;
}

C++: #include<iostream>
#include<vector>

using namespace std;

struct DATA{
  int x;
  int y;
  int dis;
};

int Calculate(int, int, vector<DATA>);
void Searching(int, int, int, int, vector<int>&);

int main(){
  int i, n, x, y, d, city, ans, sum;
  vector<int> sum_data;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0, city=0; i<n; ++i){
      cin >> x >> y >> d;
      if(x != y){
	if(city < x) city = x;
	if(city < y) city = y;
	_data.x = x;
	_data.y = y;
	_data.dis = d;
	data.push_back(_data);
      }
    }
    ++city;

    for(i=0; i<city; ++i)
      sum_data.push_back(Calculate(i, city, data));

    for(i=1, ans=0, sum=sum_data[0]; i<sum_data.size(); ++i){
      if(sum > sum_data[i]){
	ans = i;
	sum = sum_data[i];
      }
    }

    cout << ans << " " << sum << endl;
    sum_data.clear();
    data.clear();
  }

  return 0;
}

int Calculate(int n, int city, vector<DATA> data){
  int i, j, sum, min, m;
  vector<int> array(city, 0);

  for(i=1, sum=0, m=n; i<city; ++i){
    for(j=0; j<data.size(); ++j){
      Searching(m, data[j].x, data[j].y, data[j].dis, array);
      Searching(m, data[j].y, data[j].x, data[j].dis, array);
    }
    array[n] = 0;

    for(j=0, min=0; j<array.size(); ++j){
      if(array[j] > 0){
	if(min == 0 || (min != 0 && min > array[j])){
	  m = j;
	  min = array[j];
	}
      }
    }
    array[m] = -array[m];
  }

  for(i=0, sum=0; i<array.size(); ++i)
    sum -= array[i];

  return sum;
}

void Searching(int n, int i, int j, int d, vector<int>& array){
  if(i == n){
    if(array[j] == 0){
      array[j] = d - array[n];
    }else if(array[j] != 0 && array[j] > d - array[n]){
      array[j] = d - array[n];
    }
  }
}

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;
			}
		}
        int d[10][10]; // 最短距離
        for(int i=0; i<m; i++){ // 重み配列で初期化
            for(int j=0; j<m; j++){
                d[i][j] = T[i][j];
            }
        }
        for(int k=0; k<m; k++){
            for(int i=0; i<m; i++){
                for(int j=0; j<m; j++){
                    if(d[i][j]>d[i][k]+d[k][j]){
                        d[i][j] = d[i][k]+d[k][j];
                    }
                }
            }
        }
        int twn;
        int min=INF;
        for(int i=0;i<m;i++){
            int sum=0;
            for(int j=0;j<m;j++){
                sum+=d[i][j];
            }
            if(min>sum){
                min=sum;
                twn=i;
            }
        }
        cout<<twn<<' '<<min<<endl;
	}
	return 0;
}