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<algorithm>

using namespace std;

#define MAXV 10
#define INF 100000000
int main(){

	int n;
	int v;
	int a,b,c;
	int d[MAXV][MAXV];
	int sum,ans,ans_i;

	while(1){

		cin>>n;
		if(n==0) break;

		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j) d[i][j]=0;
				else d[i][j]=INF;
			}
		}

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

		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]);
				}
			}
		}

		ans=INF,ans_i=-1;
		for(int i=0;i<=v;i++){
			sum=0;
			for(int j=0;j<=v;j++){
				if(d[i][j]!=INF) sum+=d[i][j];
			}
			if(ans>sum&&sum!=0){
				ans=sum;
				ans_i=i;
			}
		}

		cout<<ans_i<<" "<<ans<<endl;

	}

}

C++: #include<iostream>
#include<algorithm>
#define N 10
#define M 10000

using namespace std;

int data[N][N];

void Init(){
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      if(i == j) data[i][j] = 0;
      else data[i][j] = M;
    }
  }
}

void WarshallFloyd(int& n){
  for(int k=0; k<n; ++k){
    for(int i=0; i<n; ++i){
      for(int j=0; j<n; ++j){
	data[i][j] = min(data[i][j], data[i][k] + data[k][j]);
      }
    }
  }
}

void PrintMinTime(int& n){
  int i, j, m, m_, t;
  m = N*M;
  for(i=0, m=N*M; i<n; ++i){
    for(j=0, m_=0; j<n; ++j) m_ += data[i][j];
    if(m > m_){
      t = i;
      m = m_;
    }
  }
  cout << t << " " << m << endl;
}

int main(){
  int i, n, m, a, b, c;

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

    Init();
    for(i=0, m=0; i<n; ++i){
      cin >> a >> b >> c;
      data[a][b] = c;
      data[b][a] = c;
      m = max(m, a);
      m = max(m, b);
    }
    ++m;
    WarshallFloyd(m);
    PrintMinTime(m);
  }
  return 0;
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

#define INF 100000000

int edges[20][20];
int dist[20][20];

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N == 0) break;

        memset(edges,0,sizeof(edges));

        int ids[20];
        int nids = 0;

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            int ix=-1;
            int iy=-1;

            for(int l=0;l<nids;++l){
                if(ids[l]==x) ix = l;
                if(ids[l]==y) iy = l;
            }

            if(ix<0){ ix = nids; ids[nids++]=x; }
            if(iy<0){ iy = nids; ids[nids++]=y; }

            edges[ix][iy] = edges[iy][ix] = c;

        }

        for(int i=0;i<nids;++i){
            for(int j=0;j<nids;++j){
                if(i==j)
                    dist[i][j] = 0;
                else if(edges[i][j]>0)
                    dist[i][j] = edges[i][j];
                else
                    dist[i][j] = INF;
            }
        }

        for(int k=0;k<nids;++k)
            for(int i=0;i<nids;++i)
                for(int j=0;j<nids;++j)
                    dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);

        int ans  = 0;
        int msum = INF;

        for(int i=0;i<nids;++i){

            int sum = 0;
            for(int j=0;j<nids;++j){
               if(dist[i][j]==INF)continue;
               sum += dist[i][j];
            }

            if(sum<=msum){

                if(sum==msum && ids[i]<ids[ans])
                    ans = i;
                else
                    ans = i;

                msum = sum;

            }

        }

        cout << ids[ans] << " " << msum << endl;

    }

    return 0;

}

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

#define REP(i,n) for(int i = 0; i < (int)n; ++i)
const int INF = (int)1e9;

int main() {
    for(int N; cin >> N, N; ) {
        static int D[10][10];
        REP(i,10) REP(j,10) D[i][j] = INF;
        REP(i,10) D[i][i] = 0;
        set<int> town;
        REP(i,N) {
            int a, b, c; cin >> a >> b >> c;
            town.insert(a);
            town.insert(b);
            D[a][b] = c;
            D[b][a] = c;
        }
        REP(k,10) REP(i,10) REP(j,10) D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
        int t = -1;
        int d = INF;
        for(auto it : town) {
            int ds = 0;
            for(auto it2 : town) {
                ds += D[it][it2];
            }
            if(ds < d) {
                t = it;
                d = ds;
            }
        }
        cout << t << ' ' << d << endl;
    }
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

#define INF 1000000000

long long edges[20][20];
long long dist[20][20];

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N==0)break;

        int m = 0;

        memset(edges,0,sizeof(edges));

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            edges[x][y] = edges[y][x] = c;

            m = max(m,max(x,y));

        }

        for(int i=0;i<=m;++i)
            for(int j=0;j<=m;++j){
                if(i==j)
                    dist[i][j]=0;
                else if(edges[i][j]==0)
                    dist[i][j]=INF;
                else
                    dist[i][j]=edges[i][j];
            }

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

        int ans  = 0;
        long long msum = INF;

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

            long long sum = 0;
            for(int j=0;j<=m;++j){

                if(dist[i][j]==INF)continue;
                sum += dist[i][j];
            }

            if(sum<msum){
                ans  = i;
                msum = sum;
            }

        }

        cout << ans << " " << msum << endl;


    }

    return 0;

}