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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

void warshall_floyd(int n, vector<vector<int>> &dist){
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;
        vector<vector<int>> dist(20, vector<int>(20, 1e9));
        for(int i=0; i<20; i++){
            dist[i][i] = 0;
        }

        int town=0;
        for(int i=0; i<n; i++){
            int a, b, c; cin>>a>>b>>c;
            dist[a][b] = c;
            dist[b][a] = c;
            chmax(town, max(a, b));
        }

        warshall_floyd(10, dist);

        int ans=1e9;
        int ansid;
        for(int i=0; i<=town; i++){
            int sum=0;
            for(int j=0; j<=town; j++){
                sum += dist[i][j];
            }

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

        cout << ansid << " " << ans << endl;
    }
}

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

        priority_queue<pair<int,int> , vector<pair<int,int> > , greater<pair<int,int> > > Q;
        m++;
        for(int i=0;i<m;i++){
            for(int j=i+1;j<m;j++){

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

                while(!Q.empty()){
                    int dis = Q.top().first;
                    int where = Q.top().second;
                    Q.pop();

                    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 "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		map<int, int>mp;
		map<int, int>revmp;
		int id = 0;
		vector<vector<int>>diss(10, vector<int>(10, 1e8));
		for (int i = 0; i < N; ++i) {
			int a, b, n; cin >> a >> b >> n;
			if (mp.find(a) == mp.end()) {
				mp[a] = id;
				revmp[id] = a;
				id++;
			}
			if (mp.find(b) == mp.end()) {
				mp[b] = id;
				revmp[id] = b;
				id++;
			}
			diss[mp[a]][mp[b]] = min(diss[mp[a]][mp[b]], n);
			diss[mp[b]][mp[a]] = min(diss[mp[b]][mp[a]], n);
		}
		for (int i = 0; i < id; ++i) {
			diss[i][i] = 0;
		}
		for (int k = 0; k < id; ++k) {
			for (int i = 0; i < id; ++i) {
				for (int j = 0; j < id; ++j) {
					diss[i][j] = min(diss[i][k] + diss[k][j], diss[i][j]);
				}
			}
		}
		pair<int, int>amin(1e9, 1e9);
		for (int s = 0; s < id; ++s) {
			int len = 0;
			for (int t = 0; t < id; ++t) {
				len += diss[s][t];
			}
			if (amin > make_pair(len, revmp[s])) {
				amin = make_pair(len, revmp[s]);
			}
		}
		cout << amin.second << " " << amin.first << endl;
	}
	return 0;
}