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>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll d[11][11];
int main() {
	int n;
	while (cin >> n, n) {
		memset(d, 0x3f, sizeof(d));
		int Max = 1;
		rep(i, n) {
			int a, b, c; scanf("%d%d%d", &a, &b, &c);
			d[a][b] = c; d[b][a] = c;
			Max = max(Max, max(a, b) + 1);
		}
		rep(k, Max)rep(i, Max)rep(j,Max)
			d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		int index;
		ll Min = LLONG_MAX;
		rep(i, Max) {
			ll cnt = 0;
			rep(j, Max) {
				if (i == j)continue;
				cnt += d[i][j];
			}
			if (cnt < Min) {
				Min = cnt;
				index = i;
			}
		}
		cout << index << ' ' << Min << endl;
	}
}

C++: #include <cstdio>
#include <cstring>

#define MAXN 100000000
int mins(int a,int b){
  if(a<0)return b;
  else if(b<0 || a<b)return a;
  else return b;
}
int main(void){
  int i=0,j=0,k=0;
  int e=0;
  scanf("%d",&e);

  while(e!=0){

 
    int gl[10][10]={0};
    int ma=0;
    for(i=0;i<10;i++){
      for(j=0;j<10;j++){
	gl[i][j]=MAXN;
      }
    }
    //memset(gl,MAXN,sizeof(gl));
    for(i=0;i<e;i++){
      scanf("%d%d",&j,&k);
      if(ma<j || ma<k)ma=(j<k)?k:j;
      scanf("%d",&(gl[j][k]));
      gl[k][j]=gl[j][k];
    }
    for(i=0;i<=ma;i++){
      gl[i][i]=0;
    }
    //printf("%d\n",ma);
    for(k=0;k<=ma;k++){
      for(i=0;i<=ma;i++){
	for(j=0;j<=ma;j++){
	  gl[i][j]=mins(gl[i][j],gl[i][k]+gl[k][j]);
	  //printf("%d\x0020%d%d\n",gl[i][j],i,j);
	}
      }
    }
    int sum=0;
    int summem=-1;
    int mn=0;
    for(i=0;i<=ma;i++){
      for(j=0;j<=ma;j++){
	sum+=gl[i][j];
      }
      if(summem==-1 || sum < summem){
	summem=sum;
	mn=i;
      }
      sum=0;
    }

    printf("%d\x0020%d\n",mn,summem);

    scanf("%d",&e);
  }
  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int n;
int pass[20][20];

int main(){
    while(cin>>n){
        if(n==0)break;
        
        int m=-1;
        rep(i,20)rep(j,20)pass[i][j]=999999999;
        rep(i,20)pass[i][i]=0;
        rep(i,n){
            int a,b,c;
            cin>>a>>b>>c;
            pass[a][b]=c;
            pass[b][a]=c;
            m=max(m,max(a,b));
        }
        m++;
        
        rep(k,m){
            rep(i,m){
                rep(j,m){
                    pass[i][j] = min(pass[i][j],pass[i][k]+pass[k][j]);
                }
            }
        }
        
        
        int num=-1;
        int val = 999999999;
        rep(i,m){
            int sum=0;
            rep(j,m){
                sum+=pass[i][j];
            }
            if(val>sum){
                num=i;
                val=sum;
            }
        }
        cout<<num<<" "<<val<<endl;
        
    }
}

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

int main(){
  int n;
  int a,b,c;
  int at[10][10];
  int cost,max,minn;
  int min;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	if(i==j)at[i][j] = 0;
	else at[i][j] = -1;
      }
    }
    max = 0;
    for(int k=0;k<n;k++){
      cin >> a >> b >> c;
      if(max < a)max = a;
      if(max < b)max = b;
      for(int j=0;j<=max;j++){
	if(at[j][a] >= 0){
	  if( (at[j][b] < 0) || ( at[j][a] + c < at[j][b]) ){
	    at[j][b] = c + at[j][a];
	    at[b][j] = c + at[j][a];
	  }
	}
	if(at[j][b] >= 0){
	  if( (at[j][a] < 0) || ( at[j][b] + c < at[j][a]) ){
	    at[j][a] = c + at[j][b];
	    at[a][j] = c + at[j][b];
	  }
	}
      }
    }

    min = 2000000000;
    for(int i=0;i<=max;i++){
      cost = 0;
      for(int j=0;j<=max;j++)cost += at[i][j];
      if(min > cost){
	min = cost;
	minn = i;
      }
    }
    cout << minn << " " << min << endl;
  }
}

C++: #include <iostream>
#include <math.h>
#include <climits>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

#define INF (INT_MAX - 1) / 2

#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;
typedef pair<int, int> P;

const int N = 10;

int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };

int dx8[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy8[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{
	int n;
	while (true) {
		cin >> n;
		if (!n) break;
		int dp[N][N];
		REP(i,N){
			REP(j, N) {
				dp[i][j] = INF;
			}
		}
		int a, b, c;
		while (n--) {
			cin >> a >> b >> c;
			dp[a][b] = c;
			dp[b][a] = c;
		}
		REP(k, N) {
			REP(i, N) {
				REP(j, N) {
					if (dp[i][j] > dp[i][k] + dp[k][j])
						dp[i][j] = dp[i][k] + dp[k][j];
				}
			}
		}
		int time[N];
		REP(i, N) {
			time[N] = 0;
			REP(j, N) {
				if (i != j && dp[i][j] != INF) {
					time[i] += dp[i][j];
				}
			}
		}
		int mini = 0;
		REP(i, N) {
			if (time[i] < time[mini] && time[i] != 0)
				mini = i;
		}
		cout << mini << " " << time[mini] << endl;
	}
	

    return 0;
}

C++: // Warshall-floyd
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 114514

int n, a, b, c, v, d[11][11];// v: num of nodes

void init()
{
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            if(i==j)// If not exist cost, cost=INF
                d[i][j] = 0;
            else
                d[i][j] = INF;
        }
    }

}

int main(void)
{
    ios::sync_with_stdio(false);
    while(cin >> n, n) {
        if(n == 0) break;
        init();

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

        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 city, dist = INF;
        for(int i=0; i<v; i++) {
            int sum = 0;
            for(int j=0; j<v; j++) {
                sum += d[i][j];
            }
            if(dist > sum) {
                dist = sum;
                city = i;
            }
        }
        cout << city << " " << dist << endl;
    }

    return 0;
}