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 <vector>  
#include<algorithm>
using namespace std; 

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d; // グラフの距離を格納した2次元配列（隣接行列）
          // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
  int n;
  int ans_min = 100000;
  int ans[10];

  for(int i=0; i<10; i++){
      ans[i] = 0;
  }

  d = Matrix(10, vector<int>(10, INF));
  for (int i = 0; i < 10; i++) d[i][i] = 0;
  
  cin >> n;
  for (int i = 0; i < n; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;
    d[from][to] = cost;
    d[to][from] = cost;
  }
  
  warshall_floyd(10);
  
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (i != j && d[i][j] != INF)
        //cout << i << "から" << j << "へのコスト: " << d[i][j] << endl;
        ans[i] += d[i][j];
    }
    //cout<< ans[i]<<endl;
    if(ans_min>ans[i] &&ans[i] !=0){
        ans_min=ans[i];
    }
  }

  cout<<ans_min<<endl;
  return 0;
}

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

#define MAX_V 11
int d[MAX_V][MAX_V];//&#26435;&#20540;
int V;//定点数
int x[MAX_V];//x[i]表示以i&#20026;起点&#26102;最短路径之和
#define forn(i,n) for(int i=0;i<(int)n;++i)

void floyd_warshall(){
	forn(k, V)
		forn(i, V)
		forn(j, V)
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
int main(){
	int E;
	while (cin >> E, E){
		memset(d, 0x3f, MAX_V*MAX_V*sizeof(int));
		forn(i, MAX_V)
			d[i][i] = 0;
		V = 0;
		forn(i, E){
			int u, v, cost;
			cin >> u >> v >> cost;
			d[u][v] = cost;
			d[v][u] = cost;
			V = max(V, max(v, u) + 1);
		}
		floyd_warshall();
		memset(x, 0, V*sizeof(int));
		forn(i, V)
			forn(j, V)
			x[i] += d[i][j];
		int ans = min_element(x, x + V) - x;
		cout << ans << " " << x[ans] << "\n";
	}
	return 0;
}

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

const int MAX_N=10;
const int INF=0x3f3f3f3f;
int dist[MAX_N][MAX_N];

int main(){

    int N;
    while((cin>>N)&&N>0){
        memset(dist, 0x3f, sizeof(dist));
        int u,v,w;
        for(int i=0; i<MAX_N; i++) dist[i][i]=0;
        int max_n=0;
        for(int i=0; i<N; i++){
            scanf("%d %d %d", &u, &v, &w);
            dist[u][v]=dist[v][u]=w;
            max_n=max(max_n, max(u,v)+1);
        }
        for(int i=0; i<max_n; i++){
            for(int j=0; j<max_n; j++){
                for(int k=0; k<max_n; k++)
                    dist[j][k]=min(dist[j][k], dist[j][i]+dist[i][k]);
            }
        }
        int res=INF;
        int min_ele=0;
        for(int i=0; i<max_n; i++){
            int tmp=0;
            for(int j=0; j<max_n; j++)
                tmp+=dist[i][j];
            if(tmp<res){
				res=tmp;
				min_ele=i;
			}
        }
        cout<<min_ele<<" "<<res<<endl;
    }

}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <iterator>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<28

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

struct edge
{
	int to;
	int cost;

	edge(int to,int cost) : to(to),cost(cost) {}
};

vector<edge> G[10];
ll d[10];

void dijkstra(int s,int n)
{
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+n,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty())
	{
		P p = que.top();
		que.pop();

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

		rep(i,G[v].size())
		{
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main()
{
	int n;
	
	while(cin >> n && n)
	{
		vector<int> t;
		rep(i,10)
		{
			G[i].clear();
		}
		rep(i,n)
		{
			int a,b,c;
			cin >> a >> b >> c;

			G[a].push_back(edge(b,c));
			G[b].push_back(edge(a,c));

			vector<int>::iterator ite = find(t.begin(),t.end(),a);
			if(ite == t.end())
			{
				t.push_back(a);
			}

			ite = find(t.begin(),t.end(),b);
			if(ite == t.end())
			{
				t.push_back(b);
			}

		}

		pair<int,ll> ans;
		ans.first = t[0];
		ans.second = INF;
		
		rep(i,t.size())
		{
			dijkstra(t[i],10);

			ll sum = 0;

			rep(j,t.size()) 
			{
				sum += d[t[j]];
			}
			
			if(ans.second == sum)
			{
				if(ans.first > t[i])
				{
					ans.first = t[i];
				}
			}

			if(ans.second > sum)
			{
				ans.first = t[i];
				ans.second = sum;
			}	
		}
		cout << ans.first << " " << ans.second << endl;
	}

	return 0;
	
}