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;
int main(){
    
    vector<int> x(10);
    x[0] = 0;
    x[1] = 1;
    for(int i = 0; i < 9; i++){
        x[i+1] = x[i] * 2 + 1;
    }
    int y = x[9] * 2 + 1;

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

        vector<int> r(y, -1);
        vector<int> t(10, 0);
        int ans;
        int anst;
        
        for(int i = 0; i < 10; i++)
            r[ x[i]+x[i] ] = 0;
        
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            r[ x[a]+x[b] ] = c;
        }
        
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                if( r[x[i]+x[j]] == -1 )
                    continue;
                for(int k = 0; k < 10; k++){
                    if( r[x[i]+x[k]] == -1 )
                        continue;
                    if( r[x[j]+x[k]] == -1 || r[x[j]+x[k]] > r[x[i]+x[j]] + r[x[i]+x[k]] )
                        r[x[j]+x[k]] = r[x[i]+x[j]] + r[x[i]+x[k]];
                }
            }
        }
        
        for(int i = 0; i < 10; i++){
            
            for(int j = 0; j < 10; j++){
                if( r[x[i]+x[j]] == -1 ){
                    continue;
                }
                else{
                    t[i] += r[x[i]+x[j]];
                }
            }
            
            if( i == 0 ){
                ans = i;
                anst = t[i];
            }
            else if( t[i] < anst && t[i] > 0 ){
                ans = i;
                anst = t[i];
            }
        }
        
        cout << ans << " " << anst <<endl;
        
    }
}

C++: #include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

int INF=1e4;
int dist[15][15];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  while(cin>>n,n){
    fill(dist[0],dist[0]+15*15,INF);
    int m=0,a,b,d;
    rep(i,n){
      cin>>a>>b>>d;
      dist[a][b]=dist[b][a]=min(dist[a][b],d);
      m=max({m,a,b});
    }
    ++m;
    rep(i,m) dist[i][i]=0;
    rep(k,m) rep(i,m) rep(j,m)
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

    pii re=pii(INF,-1);
    rep(i,m){
      int sum=0;
      rep(j,m) sum+=dist[i][j];
      re=min(re,pii(sum,i));
    }
    //rep(i,m){rep(j,m)cout<<dist[i][j]<<",";cout<<endl;}
    cout<<re.Y<<" "<<re.X<<endl;
  }
  return 0;
}

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

const int INF = 1 << 28;

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

    int m = 0;
    vector<vector<int> > dp(10, vector<int>(10, INF));
    for (int i = 0; i < n; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      dp[a][b] = dp[b][a] = c;
      m = max(m, max(a, b));
    }
    ++m;

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

    for (int k = 0; k < m; ++k) {
      for (int i = 0; i < m; ++i) {
	for (int j = 0; j < m; ++j)
	  dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
      }
    }

    int index = 0, sum = INF;
    for (int i = 0; i < m; ++i) {
      int tmp = 0;
      for (int j = 0; j < m; ++j)
	tmp += dp[i][j];

      if (sum > tmp) {
	sum = tmp;
	index = i;
      }
    }

    cout << index << " " << sum << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#define N 11
#define inf 10000000
using namespace std;
int d[N][N],V;
void warshall_floyd(void)
{
	for(int k=0;k<=V;k++)
	{
		for(int i=0;i<=V;i++)
		{
			for(int j=0;j<=V;j++)
			d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		}
	}
	return ;
}
void init(void)
{
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(i==j)
			d[i][j]=0;
			else
			d[i][j]=d[j][i]=inf;
		}
	}
	return ;
}
int main(void)
{
	int n;
	while(scanf("%d",&n)==1)
	{
		if(n==0)
		break;
		init();
		int s,e,c;
		V=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",&s,&e,&c);
			d[s][e]=d[e][s]=c;
			V=max(s,e);
		}
		warshall_floyd();
		int ans=inf;
		int sum=0;
		int id=0;
		for(int i=0;i<=V;i++)
		{
			sum=0;
			for(int j=0;j<=V;j++)
			sum+=d[i][j];
			if(sum<ans)
			{
				ans=sum;
				id=i;
			}
		}
		printf("%d %d\n",id,ans);
	}
	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;
			}
		}

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

		for(int i=0; i<m; i++){
			int a=0;
			for(int j=0; j<m; j++){
				a=a+d[i][j];
			}
			if(min>a){
				min=a;
				num=i;
			}
		}
		cout<<num<<" "<<min<<endl;
  }

	return 0;
}