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 <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  int n;
  int a, b, c;
  int d[10][10];
  int max_t = -1;
  int min_d = 10000;
  int sum_d;
  int min_ind = -1;
  while (true) {
    cin >> n;
    if (n==0) {
      break;
    }
    max_t = -1;
    min_d = 10000;
    min_ind = -1;
    for (int i=0;i<10;i++) {
    for (int j=0;j<10;j++) {
      d[i][j] = 10000;
    }
    d[i][i] = 0;
  }
  
  for (int i=0;i<n;i++) {
    cin >> a >> b >> c;
    d[a][b] = c;
    d[b][a] = c;
    if (a > max_t) {
	max_t = a;
      }
      if (b > max_t) {
	max_t = b;
      }

  }
  for (int k=0;k<(max_t+1);k++) {
    for (int i=0;i<(max_t+1);i++) {
      for (int j=0;j<(max_t+1);j++) {
	if (d[i][k] + d[k][j] < d[i][j]) {
	  d[i][j] = d[i][k] + d[k][j];
	}
      }
    }
  }

  for (int i=0;i<(max_t+1);i++) {
    sum_d = 0;
    for (int j=0;j<(max_t+1);j++) {
      sum_d += d[i][j];
    }
    if (min_d > sum_d) {
      min_d = sum_d;
      min_ind = i;
    }
  }
  cout << min_ind << " " << min_d << endl;
}
}

C++: #include <iostream>
#include <algorithm>
int cost[11][11];
#define INF 1e9

using namespace std;

int main(void){
	int n,a,b,d;
	int cmax;
	int t,rmin,tmin;
	while(cin >> n,n){
		tmin=INF;
		cmax=0;
		for(int i=0;i<11;i++)
				for(int j=0;j<11;j++)
					cost[i][j]=INF;
					
		for(int i=0;i<11;i++)
			cost[i][i]=0;
			
		for(int i=0;i<n;i++){
			cin >> a >> b >> d;
			if(cmax<a)
				cmax=a;
			if(cmax<b)
				cmax=b;
			cost[a][b]=cost[b][a]=d;
		}
		for(int i=0;i<=cmax;i++)
			for(int j=0;j<=cmax;j++)
				for(int k=0;k<=cmax;k++)
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
		
		for(int i=0;i<=cmax;i++){
			t=0;
			for(int j=0;j<=cmax;j++)
					t+=cost[i][j];
			if(t<tmin)
				tmin=t,rmin=i;
		}
		cout << rmin << ' ' << tmin << endl;
	}
	return 0;
}

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

const int INF = 1000000;
const int town_max = 10;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int T[town_max][town_max];
		for(int i=0;i<town_max;i++){
			for(int j=0;j<town_max;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;	//町の番号は0から
			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 i=0;i<m;i++){
			for(int j=0;j<m;j++){
				for(int k=0;k<m;k++){
					if(T[j][k]>T[j][i]+T[i][k])
						T[j][k] = T[j][i]+T[i][k];
				}
			}
		}


		int T_min = INF;    //時間の総和の最小値
		int town_min = -1;  //最小になる町の番号
		for(int i=0;i<m;i++){
			int T_sum = 0;
			for(int j=0;j<m;j++){
				T_sum += T[i][j];   //総和を計算
			}
			if(T_sum<T_min){    //最小なら
				T_min = T_sum;  //それを最小値に
				town_min = i;   //そのときの町の番号
			}
		}

		cout << town_min << " " << T_min << endl;
	}
}

C++: #include "cstdio"
#include "vector"
#include "queue"
using namespace std;

const int maxm=100;
struct edge{int to,w;};
edge edges[maxm];
vector<int>g[maxm];

int n,m,p;
int vis[maxm],dis[maxm];

int max(int a,int b){return a>b?a:b;}

void add(int u,int v,int w)
{
	edges[++p].to=v;
	edges[p].w=w;
	g[u].push_back(p);
}

void spfa(int s)
{
	for(int i=0;i<=50;i++)
		dis[i]=0x3f3f3f3f,vis[i]=0;
	
	queue<int>qn;
	qn.push(s);
	dis[s]=0;
	vis[s]=1;
	
	while(!qn.empty())
	{
		int nn=qn.front();qn.pop();
		vis[nn]=0;
		for(int i=0,d=g[nn].size();i<d;i++)
		{
			edge &e=edges[g[nn][i]];
			if(dis[e.to]>dis[nn]+e.w)
			{
				dis[e.to]=dis[nn]+e.w;
				if(!vis[e.to])
				{
					qn.push(e.to);
					vis[e.to]=1;
				}
			} 
		}
	}
	
}

int main()
{
	//freopen("r.txt","r",stdin);
	while(~scanf("%d",&m))
	{
		if(m==0)break;
		for(int i=0;i<=12;i++)
			g[i].clear();
		n=p=0;
		int u,v,w;
		for(int i=0;i<m;i++)
		{
			scanf("%d%d%d",&u,&v,&w);
			add(u,v,w);
			add(v,u,w);
			n=max(max(n,v),u);
		}
		
		int tot=0,ans=0x3f3f3f3f;
		for(int i=0;i<=n;i++)
		{
			spfa(i);
			int res=0;
			for(int j=0;j<=n;j++)
				res+=dis[j];
			if(res<ans)
			{
				ans=res;
				tot=i;
			}
		}
			
		printf("%d %d\n",tot,ans);
	}
	return 0;
}

C++: 
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=15;
int dp[N][N];
int m,a,b,c;

int main()
{
    while (true) {
        scanf("%d",&m);
        if (m==0) break;
        memset(dp,INF,sizeof(dp));
        for (int i=1;i<=m;i++) {
            scanf("%d%d%d",&a,&b,&c);
            dp[a][b]=dp[b][a]=c;
        }
        for (int k=0;k<10;k++) {
            for (int i=0;i<10;i++) {
                for (int j=0;j<10;j++) {
                    if (k!=i&&k!=j&&i!=j) {
                        if (dp[i][k]!=INF&&dp[k][j]!=INF)
                            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
                    }
                }
            }
        }
        int val=INF,idx=-1;
        for (int i=0;i<10;i++) {
            int tmp=0;
            for (int j=0;j<10;j++) {
                if (dp[i][j]!=INF) tmp+=dp[i][j];
            }
            if (tmp>0) {
                if (tmp<val) {
                    idx=i;
                    val=tmp;
                }
            }
        }
        printf("%d %d\n",idx,val);
    }
}