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

template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

map<int, int> convert_table, reverse_table;

int convert(int x) {
	if(convert_table.count(x))
		return convert_table[x];

	convert_table.insert(make_pair(x, convert_table.size()));
	reverse_table.insert(make_pair(convert_table.size() - 1, x));
	return convert_table.size() - 1;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	const int INF = 0xfffffff;

	for(int n; cin >> n, n;) {
		vector<vector<int> > dist(10, vector<int>(10, INF));
		for(int i = 0; i < 10; ++i)
			dist[i][i] = 0;

		convert_table.clear();
		reverse_table.clear();
		for(int i = 0; i < n; ++i) {
			int a, b, c;
			cin >> a >> b >> c;

			a = convert(a);
			b = convert(b);

			dist[a][b] = dist[b][a] = c;
		}

		int m = convert_table.size();
		for(int i = 0; i < m; ++i)
			for(int j = 0; j < m; ++j)
				for(int k = 0; k < m; ++k)
					chmin(dist[i][j], dist[i][k] + dist[k][j]);

		int city = INT_MAX, ans = INT_MAX;
		for(int i = 0; i < m; ++i) {
			int sum = 0;
			for(int j = 0; j < m; ++j)
				sum += dist[i][j];

			if(ans > sum || (ans == sum && reverse_table[i] < city)) {
				ans = sum;
				city = i;
			}
		}

		cout << city << " " << ans << endl;
	}

	return EXIT_SUCCESS;
}

C++: #include <bits/stdc++.h>

using namespace std;

const int maxn = 10;
const int inf = (INT_MAX>>1) - 10;
int cost[maxn][maxn];
int ct,x,y,z;
map<int,bool> has;

void solve(){

    has.clear();
    for(int i=0;i<maxn;i++){
        fill(cost[i],cost[i]+maxn,inf);
        cost[i][i] = 0;
    }
    while(ct--){
        cin>>x>>y>>z;
        cost[x][y] = cost[y][x] = z;
        has[x] = has[y] = true;
    }
    for(int k=0;k<maxn;k++)
        for(int i=0;i<maxn;i++)
            for(int j=0;j<maxn;j++)
                cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);

    pair<int,int> res = make_pair(-1,INT_MAX);
    int ct;
    for(auto p = has.begin(); p != has.end(); p++){
        ct = 0;
        for(auto x = has.begin(); x != has.end(); x++) ct += cost[(*p).first][(*x).first];
        cout<<ct<<endl;
        if(ct < res.second) res = make_pair((*p).first,ct);
    }
    cout<<res.first<<' '<<res.second<<endl;
}
int main(){

    while(cin>>ct and ct) solve();

//    system("pause");
    return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 10000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
struct edge{int to,cost;};
int N;
ll d[100];
bool f[100];
vector<edge> G[100];
void dijkstra(int s){
      REP(i,N)d[i]=-1;
      d[s]=0;
      priority_queue<P,vector<P>,greater<P> > Q;
      Q.push(P(0,s));
      while(!Q.empty()){
            P p=Q.top();Q.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]==-1||d[e.to]>d[v]+e.cost){
                        d[e.to]=d[v]+e.cost;
                        Q.push(P(d[e.to],e.to));
                  }
            }
      }
}
int main(){
      while(cin>>N&&N){
            int city=-1;
            memset(f,false,sizeof(f));
            REP(i,N){
                  int a,b,c;
                  cin>>a>>b>>c;
                  G[a].PB((edge){b,c});
                  G[b].PB((edge){a,c});
                  f[a]=f[b]=true;
                  city=max(city,max(a,b));
            }
            ll ans=-1,pos=-1;
            REP(i,city+1){
                  if(!f[i])continue;
                  ll sum=0;
                  dijkstra(i);
                  REP(j,city+1)if(f[j])sum+=d[j];
                  if(ans==-1||ans>sum){
                        ans=sum;
                        pos=i;
                  }
            }
            cout<<pos<<" "<<ans<<endl;
      }
}

C++: #include <iostream>
#define INFINITY (1 << 30)

#define MAX_N 10

using namespace std;

int n,road[MAX_N][MAX_N] = {},d[MAX_N][MAX_N] = {};
int main() {
  int temp1,temp2,temp3,city ,alt,mincity ;
  long long int costtime ,cost;
  while(1){
    road[MAX_N][MAX_N] ={};
    d[MAX_N][MAX_N] ={};
      cin >> n;
    if(n == 0) break;
    city = mincity = 0; costtime ;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2>>temp3;
      if(road[temp1][temp2] != 0 ){
        if(road[temp1][temp2] > temp3) {
          road[temp1][temp2] = temp3;
          road[temp2][temp1] = temp3;
        }
      }
      else
      {
        road[temp1][temp2] = temp3;
        road[temp2][temp1] = temp3;
      }
      if(city < temp1|| city < temp2)  {city = (temp1 > temp2)?  temp1: temp2; }
    }
    //cout << city <<endl;
    city++;

    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j < city; ++j) {
        if(i != j ) d[i][j] = INFINITY;
        if (road [i][j] !=0) d[i][j] =road[i][j];
      }
    }


    for (int l = 0; l < 2; ++l) {
      for (int i = 0; i <city ; ++i) {
        for (int j = 0; j <city ; ++j) {
          for (int k = 0; k < city; ++k) {
            if(d[i][k] !=INFINITY && d[k][j] != INFINITY){
              alt = d[i][k]+ d[k][j];
              if (alt < d[i][j]) d[i][j] = alt;
            }
          }
        }
      }
    }

    for (int i = 0; i < city; ++i) {
        cost =0;
      for (int j = 0; j < city ; ++j) {
        cost += d[i][j];
        cout << d[i][j]<<" ";
      }
      cout<<endl;
      if(i == 0) costtime = cost;
      if (costtime > cost) {costtime = cost;mincity = i;}
    }
    cout<< mincity << " "<<costtime<<endl;

  }


  return 0;
}