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>
#define INF 123456789
using namespace std;

int main() {
	// AOJ0189 Bellman-Ford
	for (;;)
	{
		struct edge {int from,to,cost;};
		int city = 0;//?????¨???????????????????°????(0~7?????§????????????city == 8??§??????)
		int n;
		cin >> n;
		edge es[2*n];
		if (n == 0) break;
		for (int i = 0;i < n;i++)
		{
			int a,b,c;
			cin >> a >> b >> c;
			es[2*i].from = a;
			es[2*i].to = b;
			es[2*i].cost = c;
			es[2*i+1].from = b;
			es[2*i+1].to = a;
			es[2*i+1].cost = c;
 			city = max (max(a,b)+1,city);
		}
		int min = INF;
		int mincity;
		for (int target_city = 0;target_city < city;target_city++)
		{
			//target_city?????????????°???????????¨??????????????????????
			int d[city];
			for (int i = 0;i < city;i++)
			{
				d[i] = INF;
			}
			d[target_city] = 0;
			for (;;)
			{
				bool update = false;
				for (int i = 0;i < 2 * n;i++)
				{
					//???????????????????????????
					if (d[es[i].from] != INF && d[es[i].from] + es[i].cost < d[es[i].to])
					{
						update = true;
						d[es[i].to] = d[es[i].from] + es[i].cost;
					}
				}
				if(!update) break;
			}
			int sum = 0;
			for (int i = 0;i < city;i++)
			{
				sum += d[i];
			}
			if (sum < min)
			{
				min = sum;
				mincity = target_city;
			}
		}
		cout << mincity << " " << min << endl;
	}
	return 0;
}

C++: #include <iostream>
#define INFINITY (1 << 30)
#define MAX_N 10

using namespace std;

int n,road[MAX_N][MAX_N] = {},d[MAX_N][MAX_N] = {};
int main() {
  int temp1,temp2,temp3,city ,alt,mincity ,costtime= INFINITY ,cost ;

  while(1){
      cin >> n;
    if(n == 0) break;
    city = mincity = 0;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2>>temp3;
      road[temp1][temp2] = temp3;
      road[temp2][temp1] = temp3;
      if(city < temp1|| city < temp2)  {city = (temp1 > temp2)?  temp1: temp2; }
    }
    //cout << city <<endl;
    city++;

    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j < city; ++j) {
        if(i != j ) d[i][j] = INFINITY;
        if (road [i][j] !=0) d[i][j] =road[i][j];
      }
    }




    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j <city ; ++j) {
        for (int k = 0; k < city; ++k) {
          if(d[k][j] != INFINITY){
            alt = d[i][k]+ d[k][j];
            if (alt < d[i][j]) d[i][j] = alt;
          }

        }

      }
    }

    for (int i = 0; i < city; ++i) {
        cost =0;
      for (int j = 0; j < city ; ++j) {
        cost += d[i][j];
        //cout << d[i][j]<<" ";
      }
      //cout<<endl;
      if (costtime > cost) {costtime = cost;mincity = i;}
    }
    cout<< mincity << " "<<costtime<<endl;
  }


  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
const int MAX_V = 15;
const int MAX_E = 50;
const int INF = 100000000;
int V, E;
int d[MAX_V][MAX_V];  //各町間の通勤時間
int main(int argc, const char * argv[])
{
    while (true) {
        scanf("%d", &E);  //道の数
        if (E == 0) break;
        V = 0;
        //d[][]の初期化
        for (int i = 0; i < MAX_V; i++) {
            for (int j = 0; j < MAX_V; j++) d[i][j] = INF;
        }
        
        for (int i = 0; i < E; i++) {
            int a, b, c;
            scanf("%d %d %d", &a, &b, &c);
            V = max(V,max(a,b));  //0~最大の番号までが町の番号
            d[a][b] = min(d[a][b], c);
            d[b][a] = d[a][b];
        }
        
        for (int i = 0; i <= V; i++) d[i][i] = 0;
        
        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 town = 0;  //とりあえず、0にセット
        int dist = 0;
        for (int i = 0; i <= V; i++) dist += d[0][i];
        for (int i = 1; i <= V; i++) {
            int total = 0;
            for (int j = 0; j <= V; j++) {
                total += d[i][j];
            }
            if (total < dist) {
                town = i;
                dist = total;
            }
        }
        printf("%d %d\n", town, dist);
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define SIZE 100005
#define MAX_V 100001
#define INF (1e9 + 1)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int g[10][10];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(i==j)g[i][j]=0;
				else g[i][j]=999999999;
			}
		}
		int t=0;
		for(int i=0;i<a;i++){
			int c,d,e;
			scanf("%d%d%d",&c,&d,&e);
			if(t<c)t=c;
			if(t<d)t=d;
			g[c][d]=e;
			g[d][c]=e;
		}
		t++;
		for(int k=0;k<t;k++){
			for(int i=0;i<t;i++){
				for(int j=0;j<t;j++){
					if(g[i][k]+g[k][j]<g[i][j]) g[i][j]=g[i][k]+g[k][j];
				}
			}
		}
		int n=0;
		ll ans = 9999999999;
		for(int i=0;i<t;i++){
			ll now=0;
			for(int j=0;j<t;j++) now+=g[i][j];
			if(ans>now){
				ans=now;
				n=i;
			}
		}
		printf("%d %lld\n",n,ans);
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
const int inf=1e9;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int in[11][11];
    rep(i,11)rep(j,11)in[i][j]=inf;
    int maax=0;
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      in[a][b]=c;
      in[b][a]=c;
      maax=max(maax,a);
      maax=max(maax,b);
    }
    n=maax+1;
    int mini=inf;
    int out;
    rep(i,n){
      int sum=0;
      rep(j,n){
	if(i==j)continue;
	vector<vector<int> >tmp(n,vector<int>(n));
	rep(a,n)rep(b,n)tmp[a][b]=in[a][b];
	rep(k,n)rep(a,n)rep(b,n)tmp[a][b]=min(tmp[a][b],tmp[a][k]+tmp[k][b]);
	sum+=tmp[i][j];
	//cout<<" "<<i<<" "<<j<<" "<<sum<<endl;
      }
      if(mini>sum){
	mini=sum;
	out=i;
      }
      //cout<<i<<" ! "<<sum<<endl;
    }
    cout<<out<<" "<<mini<<endl;
  }
}