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>
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;     //How many towns are there?

		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[10][10];
		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 dis=INF,name=-1,tmp;
		for(int i=0;i<m;i++){
			tmp = 0;
			for(int j=0;j<m;j++){
				tmp += d[i][j];
			}
			if(dis>tmp){
				dis=tmp;
				name=i;
			}
		}
		cout << name << " " << dis << endl;


	}

	return 0;
}

C++: #include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
    os<<'[';
    rep(i,a.size()) os<<(i?" ":"")<<a[i];
    return os<<']';
}

int G[10][10];

int dp[10][10];
int V;

void warshall_floyd() {
    rep(k, V) rep(i, V) rep(j, V) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}


int main() {
    for(int n; cin >> n, n != 0;) {
        int m = 0;
        rep(i, 10) rep(j, 10) G[i][j] = INF;
        rep(i, 10) G[i][i] = 0;
        rep(i, n) {
            int a, b, c; cin >> a >> b >> c;
            G[a][b] = G[b][a] = c;
            m = max(m, max(a, b));
        }
        m++;
        V = m;
        rep(i, m) rep(j, m) dp[i][j] = G[i][j];
        warshall_floyd();
        int ans = INF;
        int p;
        rep(i, m) {
            int sum = 0;
            rep(j, m) sum += dp[i][j];
            if (ans > sum) {
                p = i;
                ans = sum;
            }
        }
        cout << p << ' ' << ans << endl;
    }

    return 0;
}

C++: # include<iostream>
#include<vector>
#include<queue>
#include<functional>
#define INF 2e6

using P = std::pair < int, int > ;

# define MAX_E 45
# define MAX_V 10

int V, E;

struct edge{
	int to, cost;
	edge() = default;
	edge(const edge &)= default;
	edge& operator = (const edge&) = default;
	edge(int _t, int _c) : to(_t), cost(_c) {}
};

std::vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
	std::priority_queue<P, std::vector<P>, std::greater<P>> Q;
	std::fill(d, d + V+1, INF);
	d[s] = 0;
	Q.push(P(0, s));
	while (!Q.empty()){
		P p = Q.top(); Q.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); ++i){
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				Q.push(P(d[e.to], e.to));
			}
		}
	}
}

P solve(){
	int min = INF, minv;
	for (int i = 0; i <= V; ++i){
		int sum = 0;
		dijkstra(i);
		for (int j = 0; j <= V; ++j){
			sum += d[j];
		}
		if (min > sum)min = sum, minv = i;
	}
	return P(minv, min);
}

int main(){
	while (1){
		std::cin >> E;
		if (E == 0)
			break;
		for (int i = 0; i <= V; i++)G[i].clear();
		V = 0;
		int f, t, c;
		for (int i = 0; i < E; ++i){
			std::cin >> f >> t >> c;
			G[f].push_back(edge(t, c));
			G[t].push_back(edge(f, c));
			if (V < t)
				V = t;
		}
		std::cout << solve().first<<' '<< solve().second << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;
int mp[50][50],n,a,b,c;
bool flag[10];
#define INF 10000000
int main()
{
    int Min;
    cin >> n;
    while(n)
    { 
        int V = 10;
        Min = INF;
        memset(flag,0,sizeof(flag));
    for(int i=0;i<50;i++)
        for(int j = 0;j<50;j++)
        {
          if(i==j)
              mp[i][j] = 0;
         else
          mp[i][j] = INF;

        }
     
    for(int i=1;i<=n;i++)
    {
         cin >> a >> b >> c;
         mp[a][b] = mp[b][a] = c;
         flag[a] = flag[b] = true;
    }
    for(int k=0;k<V;k++)
        for(int i=0;i<V;i++)
            for(int j=0;j<V;j++)
                mp[i][j]= min(mp[i][j],mp[i][k]+mp[k][j]);
   
   int MinN[11];
   memset(MinN,0,sizeof(MinN));
   for(int i=0;i<V;i++){
   	for(int j=0;j<V;j++)
   	   if(flag[j]==true)
   	  MinN[i] += mp[i][j];
   }
   
    cout << min_element(MinN,MinN+V) - MinN <<" "<<*min_element(MinN,MinN+V) <<endl;
    
    cin >> n;
    }
    return 0;
}