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>
#define INF (1 << 25)
using namespace std;

int main(){
  int cost[64][64];
  int n,a,b,c;
  while(cin >> n,n){
    int maxi = 0;
    fill_n(cost[0],64*64,INF);
    while(n--){
      cin >> a >> b >> c;
      cost[a][b] = cost[b][a] = c;
      cost[a][a] = cost[b][b] = 0;
      maxi = max(max(a,b),maxi);
    }
    for(int i=0;i<=maxi;i++){
      for(int j=0;j<=maxi;j++){
	for(int k=0;k<=maxi;k++){
	  cost[j][k] = min(cost[j][k],cost[j][i]+cost[i][k]);
	}
      }
    }
    int m_num,m_sum = INF;
    for(int i=0;i<=maxi;i++){
      int sum = 0;
      for(int j=0;j<=maxi;j++) sum += cost[i][j];
      if(m_sum > sum){
	m_sum = sum;
	m_num = i;
      }
    }
    cout << m_num << " " << m_sum << endl;
  }
}

C++: #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int mapp[11000][11000];
int inf=99999;
int main()
{
    int n;
    for(int i=0; i<=9; i++)
        for(int j=0; j<=9; j++)
        {
            if(i==j)
                mapp[i][j]=0;
            else
                mapp[i][j]=inf;
        }
    while(scanf("%d",&n)&&n)
    {
        int t=n;
        int s,si;
        while(t--)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            s=max(max(s,a),b);
            si=min(min(si,a),b);
            mapp[a][b]=mapp[b][a]=c;
        }
        for(int k=si; k<=s; k++)
            for(int i=si; i<=s; i++)
                for(int j=si; j<=s; j++)
                    if(mapp[i][j]<mapp[i][k]+mapp[k][j])
                        mapp[i][j]=mapp[i][k]+mapp[k][j];
        int sum=0,min=inf,k;
        for(int i=si; i<=s; i++)
        {
            for(int j=si; j<=s; j++)
                sum+=mapp[i][j];
            if(min>sum)
            {
                min=sum;
                k=i;
            }
        }
        printf("%d %d\n",k,min);
    }

    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 ;
  long long int costtime ,cost;
  while(1){
    road[MAX_N][MAX_N] ={};
    d[MAX_N][MAX_N] ={};
      cin >> n;
    if(n == 0) break;
    city = mincity = 0; costtime ;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2>>temp3;
      if(road[temp1][temp2] != 0 ){
        if(road[temp1][temp2] > temp3) {
          road[temp1][temp2] = temp3;
          road[temp2][temp1] = temp3;
        }
      }
      else
      {
        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[i][k] !=INFINITY && 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(i == 0) costtime = cost;
      if (costtime > cost) {costtime = cost;mincity = i;}
    }
    cout<< mincity << " "<<costtime<<endl;

  }


  return 0;
}