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 <stdio.h>
#define INF 10000
using namespace std;

struct edge {
    int from, to, cost;
};

edge es[100];
int d[11];
int n,maxV=0;

int shortest_path(int s){
    int sum=0;
    for(int i=0;i<maxV+1;i++){
        d[i] = INF;
    }
    d[s] = 0;
    while(1){
        bool update = false;
        for(int i=0;i<2*n;i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
            }
        }
        if(!update){
            break;
        }
    }
    for(int i=0;i<maxV+1;i++){
        if(d[i] != INF){
        	// cout << i << " " << d[i] << endl;
            sum += d[i];
        }
    }
    return sum;
}

int main(void){
    
    while(cin >> n && n){
    	maxV = 0;
        int a, b, c, tmp, min,sum2=100000;
        for(int i=0;i<n;i++){
            cin >> a >> b >> c;
            es[i].from = a;
            es[i].to = b;
            es[i].cost = c;

            es[i+n].from = b;
            es[i+n].to = a;
            es[i+n].cost = c;
            
            if(maxV < b){
           		maxV = b;
           	}
           	
        }
        //??????????????°?????????
        for(int i=0;i<maxV+1;i++){
            int tmp = shortest_path(i);
            // cout << tmp << endl;
            if(sum2 > tmp){
                sum2 = tmp;
                min = i;
            }
        }
        cout << min << " " << sum2 << endl;
    }
    return 0;
}

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

using namespace std;

int main ( void )
{
	const int INF = (1 << 15);
	int n;
	int cost[10][10];

	while ( cin >> n , n )
	{
		for (int i = 0; i < 10; ++i)
		{
			for (int j = 0; j < 10; ++j)
				cost[i][j] = INF;
			cost[i][i] = 0;
		}

		int a, b, c, V = 0;
		for (int i = 0; i < n; ++i)
		{
			cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
			V = max(V, max(a, b));
		}

		for (int k = 0; k <= V; ++k)
			for (int i = 0; i <= V; ++i)
				for (int j = 0; j <= V; ++j)
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);

		int from = -1, minCost = INF;
		for (int i = 0; i <= V; ++i) {
			int sum = 0;
			for (int j = 0; j <= V; ++j)
				sum += cost[i][j];
			if ( sum < minCost ) {
				from = i;
				minCost = sum;
			}
		}

		cout << from << ' ' << minCost << endl;

	}
	return 0;
}

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[m][m];
    for(int i=0; i<m; i++){
      for(int j=0; j<m; j++){
        d[i][j] = T[i][j];
      }
    }

    for(int h=0; h<m; h++){
      for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
          if(d[i][j] > d[i][h]+d[h][j]){
            d[i][j] = d[i][h]+d[h][j];
          }
        }
      }
    }

    int ttl=0;
    int min=0;
    for(int i=0; i<m; i++){
      int t=0;
      for(int j=0; j<m; j++){
        t += d[i][j];
      }
      if(ttl==0 || ttl>t){
        ttl=t;
        min=i;
      }
    }

    cout << min << " " << ttl << '\n';
	}

	return 0;
}

C++: // 2014/06/16 Tazoe

#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 min_town_n;
    int min_town_time;
    for(int k=0;k<m;k++){
      int sub;
      for(int i=0;i<m;i++){
        sub += T[k][i];
      }
      if(min_town_time > sub){
        min_town_time = sub;
        min_town_time_n;
      }
    }
    cout << min_town_n << ' ' << min_town_time << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 200000000
int main()
{
	int e;
	while(cin >> e,e)
	{
		int i,j,k,s=INF,v=0,ans=INF;
		if(e==0)break;
		int d[11][11];
		int cost_count[11] = {0};
		for(i=0;i<11;i++)
		{
			for(j=0;j<11;j++)
			{
				d[i][j] = INF;
				if(i==j)
				{
					d[i][j] = 0;
				}
			}
		}
		for(i=0;i<e;i++)
		{
			scanf("%d %d %d",&i,&j,&k);
			v = max(v,max(i,j));
			d[i][j] = k;
			d[j][i] = k;
		}
		for(k=0;k<v;k++)
		{
			for(i=0;i<v;i++)
			{
				for(j=0;j<v;j++)
				{
					d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		for(i=0;i<v;i++)
		{
			int cost = 0;
			for(j=0;j<v;j++)
			{
				cost += d[i][j];
			}
			cost_count[i] = cost;
			ans=min(ans,cost_count[i]);

		}
		for(i=0;i<v;i++)
		{
			if(cost_count[i]==ans)
			{
				printf("%d %d\n",i,ans);
				break;
			}
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const double PI=acos(-1.0);
int floyd[50][50],w[50][50];
bool exist[50];
int main()
{
	int n;
	while( cin>>n && n )
	{
		memset(w,INF,sizeof(w));
		memset(floyd,INF,sizeof(floyd));
		memset(exist,false,sizeof(exist));
		for(int i=0;i<n;i++)
		{
			int x,y,z;
			cin>>x>>y>>z;
			w[x][y]=w[y][x]=z;
			floyd[x][y]=floyd[y][x]=z;
			floyd[x][x]=floyd[y][y]=w[x][x]=w[y][y]=0;
			exist[x]=exist[y]=true;
		}
		for(int k=0;k<10;k++)
			if( exist[k] )
				for(int i=0;i<10;i++)
					if( exist[i] )
						for(int j=0;j<10;j++)
							if( exist[j] )
								floyd[i][j]=min(floyd[i][j],floyd[i][k]+w[k][j]);
		int minn=INF,ans=0;
		for(int i=0;i<10;i++)
			if( exist[i] )
			{
				int temp=0;
				for(int j=0;j<10;j++)
					if( exist[j] )
						temp+=floyd[i][j];
				if( temp<minn )
				{
					minn=temp;
					ans=i;
				}
			}
		cout<<ans<<" "<<minn<<endl;
	}
}