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 <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>

#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

const int INF = 1e+8;

typedef struct edge_def {
	int to;
	int cost;
	edge_def(int _to, int _cost) {to = _to; cost = _cost;}
} edge;

typedef pair<int, int> P;

int V, E;
const int MAX_V = 10;
vector<edge> G[MAX_V];	//[i] : fromを表す
int d[MAX_V];

void dijkstra(int s) {
	int i;
	priority_queue<P, vector<P>, greater<P> > q;

	for (i=0; i<V; i++) d[i] = INF;
	d[s] = 0;
	q.push(P(0, s));

	while (q.size()) {
		P p = q.top();
		q.pop();
		int v = p.second;

		if (d[v] < p.first) continue;

		for (i=0; i<(int)G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int i, j;
	int total;
	int minT;

	while (1) {
		scanf("%d ", &E);
		if (!E) break;

		for (i=0; i<MAX_V; i++)
			G[i].clear();

		V = 0;
		for (i=0; i<E; i++) {
			int ef, et, ec;
			scanf("%d%d%d ", &(ef), &(et), &(ec));
			G[ef].push_back(edge(et, ec));
			G[et].push_back(edge(ef, ec));
			V = max(V, ef);	
			V = max(V, et);	
		}
		V++;

		total = INF;
		minT = INF;
		for (i=0; i<V; i++) {
			dijkstra(i);

			int sum = 0;
			for (j=0; j<V; j++)
				sum += d[j];

			if (sum < total) {
				total = sum;
				minT = i;
			} else if (sum == total && i < minT)
				minT = i;
		}

		printf("%d %d\n", minT, total);
	}	

	return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
const int INF=10000000;
int dp[10][10];
int main(){
  while(true){
    int n;
    scanf("%d",&n);
    if(n==0) break;

    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++) dp[i][j]=INF;

    int a,b,c;
    for(int i=0;i<n;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++){
          dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
        }
      }
    }
    int sum[10]={0};
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        if(i!=j && dp[i][j]!=INF){
          sum[i]+=dp[i][j];
        }
      }
    }
    int ans=INF,ans_i=0;
    for(int i=0;i<10;i++){
      if(ans>sum[i] && sum[i]!=0){
        ans=sum[i];
        ans_i=i;
      }
    }
    printf("%d %d\n",ans_i,ans);
  }
  return 0;
}

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

const int INF=99999999;

int ma[11][11];
int dis[11][11];
int maxx,id,ans;

int slove()
{
    for(int k=0;k<=maxx;k++)
        for(int i=0;i<=maxx;i++)
            for(int j=0;j<=maxx;j++)
            dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
    ans = INF;
    for(int i=0;i<=maxx;i++)
    {
        int sum=0;
        for(int j=0;j<=maxx;j++)
            sum+=dis[i][j];
        if(ans > sum){
            ans = sum;
            id = i;
        }
    }
}

int main()
{
    int t;
    while(scanf("%d",&t)&&t)
    {
        for(int i=0;i<=11;i++)
            for(int j=0;j<=11;j++)
            if(i != j)dis[i][j] = INF;
        maxx=0;
        while(t--)
        {
            int a,b,c;
            scanf("%d %d %d",&a,&b,&c);
            dis[a][b]=c;
            dis[b][a]=c;
            maxx=max(maxx,max(a,b));
        }
        slove();
        cout<<id<<" "<<ans<<endl;
    }
}

C++: #include<cstdio>
#include<cstring>
#define INF 0x3f3f3f

int max(int x,int y)
{
	return x>y?x:y;
 } 
 int min(int x,int y)
 {
 	return x<y?x:y;
 }
int d[110][110];
void floyd(int n)
{
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				d[i][j]=min(d[i][j],(d[i][k]+d[k][j]));
			}
		}
	}
}
void into(int n)
{
	memset(d,INF,sizeof(d));
	for(int i=0;i<n;i++)
		d[i][i]=0;
}
int main()
{
	int n,m;
	int a,b,k;
	while(~scanf("%d",&n),n)
	{
		into(12);
		m=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",&a,&b,&k);
			d[a][b]=d[b][a]=k;
			m=max(max(a,b),m);
		}
		floyd(m+1);
		int minn=INF;
		int kase;
		for(int i=0;i<=m;i++)
		{
			int ans=0;
			for(int j=0;j<=m;j++)
			{
				ans+=d[i][j]; 
			}
			if(ans<minn)
			{
				minn=ans;
				kase=i;
			}
			
		}
		printf("%d %d\n",kase,minn);
	}
	return 0;
}

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

int main(){
	while(1){
		int n;
		long road[10][10];
		scanf(" %d", &n);
		if(n==0) break;
		
		memset(road, -1, sizeof(road));
		for(int i=0; i<10; ++i) road[i][i]=0;
		 
		int city=0; //街の数
		for(int i=0; i<n; ++i){
			int a, b, c;
			scanf(" %d %d %d", &a, &b, &c);	
			road[a][b]=road[b][a]=c;
			if(city<a) city=a;
			if(city<b) city=b;
		}
		
		long ans[10]={0};	
		
		//各街を根としてbfs
		for(int i=0; i<=city; ++i){
			long cost[10]; //その街までの最小コスト
			for(int j=0; j<=city; ++j) cost[j]=1000000000; //とりあえず大きいので初期化
			
			queue<int> que;
			cost[i]=0;
			que.push(i);
			while( !que.empty() ){
				int v=que.front();
				que.pop();
				for(int j=0; j<10; ++j){
					if(v==j) continue;
					
					if(road[v][j]>=0 && cost[v]+road[v][j]<cost[j]){
						cost[j]=cost[v]+road[v][j];
						que.push(j);	
					}	
				}	
			}	
			/*
			printf("city %d to:\n", i);
			for(int j=0; j<=city; ++j) printf(" %d is %ld\n", j, cost[j]);
			*/
			for(int j=0; j<=city; ++j) ans[i]+=cost[j];
		}
		
		int a=0;
		for(int i=1; i<=city; ++i)
			if(ans[a]>ans[i]) a=i;	
			
		printf("%d %ld\n", a, ans[a]);
	}
}