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 <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                             it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

const int NO = 1000000000;
int main(){
    while(true){
        // miti kazu
        int n;
        cin >> n;
        if(n eq 0) break;
        // miti
        vector<vector<int> > R(10,vector<int>(10,NO));
        // distance
        vector<vector<int> > D(10,vector<int>(10,NO));

        int m = -1;
        for(int i=0;i<n;i++){
            int a,b,c;
            cin >> a >> b >> c;
            R[a][b] = R[b][a] = c;
            m = max(m,max(a,b));
        }

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


        m++;
        for(int i=0;i<m;i++){
            for(int j=i+1;j<m;j++){

                // distance where
                priority_queue<pair<int,int> , vector<pair<int,int> > , greater<pair<int,int> > > Q;
                Q.push(mp(0,i));
                vector<char> A(10,false);

                while(!Q.empty()){
                    int dis = Q.top().first;
                    int where = Q.top().second;
                    Q.pop();
                    if(A[where]) continue;
                    A[where] = true;


                    if(where eq j){
                        D[i][j] = D[j][i] = dis;
                        break;
                    }
                    for(int k=0;k<10;k++){
                        if(where eq k) continue;
                        if(R[where][k] not_eq NO){
                            Q.push(mp(R[where][k] + dis,k));
                        }
                    }
                }
            }
        }


        int index_i = -1;
        int sum = NO;
        for(int i=0;i<m;i++){
            int s = 0;
            for(int j = 0;j<m;j++){
                s += D[i][j];
            }
            if(sum > s){
                sum = s;
                index_i = i;
            }
        }

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

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<bits//stdc++.h>
#include<functional>
using namespace std;
struct P{
	long long cost,pos;
};
struct B{
	long long cost,to;
};
bool operator<(P a,P b){
	return a.cost<b.cost;
}
bool operator>(P a,P b){
	return a.cost>b.cost;
}
vector<B>e[10];
int main() {
	int n;
	while(cin>>n&&n!=0){
		long long a,b,c,ma=0;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			e[a].push_back(B{c,b});
			e[b].push_back(B{c,a});
			ma=max(a,max(b,ma));
		}
		P sum;
		sum.cost=1000000;
		for(int i=0;i<=ma;i++){
			priority_queue<P, vector<P>, greater<P>>p;
			long long b[10];
			for(int j=0;j<10;j++) b[j]=1000000;
			b[i]=0;
			p.push(P{0,i});
			while(!p.empty()){
				P t=p.top();p.pop();
				for(int j=0;j<(int)e[t.pos].size();j++){
					if(b[t.pos]+e[t.pos][j].cost<b[e[t.pos][j].to]){
						b[e[t.pos][j].to]=b[t.pos]+e[t.pos][j].cost;
						p.push(P{b[e[t.pos][j].to],e[t.pos][j].to});
					}
				}
			}
			long long sum2=0;
			for(int j=0;j<=ma;j++){
				sum2+=b[j];
			}
			if(sum.cost>sum2){
				sum.cost=sum2;
				sum.pos=i;
			}
		}
		cout<<sum.pos<<" "<<sum.cost<<endl;
	}
}

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<n;k++){
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}
//????°???????????????¢???
		int town;//????????????
		int x=100010;//????????????
		for(int i=0;i<n;i++){
			int r=0;//i?????§???????????????
			for(int j=0;j<n;j++){
				r=r+T[i][j];
			}
			if(r<x){
				x=r;
				town=i;
			}
		}
		cout<<town<<' '<<x<<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;
			}
		}

		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 ans=0;
    int anstime=INF;
    int timee;

    for(int i=0;i<m;i++){
      timee=0;
      for(int j=0;j<m;j++){
        timee+=T[i][j];
      }
      if(anstime>timee){
        anstime=timee;
        ans=i;
      }
    }

    cout << ans << " " << anstime << endl;

  }
  return 0;
}