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<queue>
#define HOME 10
#define ROAD 45
#define MAX  100000000
using namespace std;

int dis[HOME][HOME];
bool chk[HOME];

class Datum {
public:
	int now;
	int dis;

	Datum(int n, int d) {now = n;dis = d;}
	Datum() {}
};

bool operator<( const Datum& a, const Datum& b ) {
	return a.dis < b.dis;
}

bool operator>( const Datum& a, const Datum& b ) {
	return a.dis > b.dis;
}

int main () {
	while ( true ) {
		int n;
		cin >> n;
		
		if ( n ==  0 ) 
			break;

		for ( int i=0; i<HOME;i ++ ) {
			for ( int j=0; j<HOME; j++ ) {
				dis[i][j] = MAX;
			}
		}

		int find = -1;
		for ( int i=0;i<n; i++ ) {
			int from, to, distance;
			cin >> from >> to >> distance;
			
			if ( find < to )
				find = to;
			if ( find < from )
				find = from;

			dis[from][to] = distance;
			dis[to][from] = distance;

			dis[i][i] = 0;
		}

		n = find+1;

		priority_queue<Datum, vector<Datum>, greater<Datum> > flow;

		while( !flow.empty() ) {
			flow.pop();
		}

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

			while( !flow.empty() ) {
				flow.pop();
			}

			flow.push(Datum(i,0));
			int count = n;

			memset( chk, false, n*sizeof(bool) );

			while(!flow.empty()) {
				Datum now;
				now = flow.top();
				flow.pop();

				for ( int j=0; j<n; j++ ) {
					if ( i != j ) {
						if ( chk[j] )
							continue;

						if ( dis[now.now][j] + now.dis <= dis[i][j] ) {
							dis[i][j] = dis[now.now][j] + now.dis;
							dis[j][i] = dis[now.now][j] + now.dis;

							if ( dis[now.now][j] == MAX )
							continue;

							chk[j] = true;
							count--;
	
							flow.push(Datum(j,dis[i][j]));
							
						}
					}
				}

				if ( count == 1 ) {
					break;
				}
			}
		}



		int maxhome = -1;
		int maxdis = MAX;
		for ( int i=0; i<n; i++ ) {
			int sum = 0;
			
			for ( int j=0; j<n; j++ ) {
				sum += dis[i][j];
			}
			
			if ( maxdis > sum ) {
				maxdis = sum;
				maxhome = i;
			}
		}

		cout << maxhome << ' ' << maxdis << endl;
	}
}

C++: #include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define scd(x) scanf("%d", &x)
#define scdd(x, y) scanf("%d %d", &x, &y)
#define scddd(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define icc ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;

const int MAX = 10 + 1;
const int INF = 1000000;

int n, V;
int mp[MAX][MAX], d[MAX];

void solve() {
    for (int i = 0; i <= V; ++i) mp[i][i] = 0;
    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]);

    memset(d, 0, sizeof(d));
    int num, res = INF;
    for (int i = 0; i <= V; ++i){
        for (int j = 0; j <= V; ++j) d[i] += mp[i][j];
        if (res > d[i]){
            res = d[i];
            num = i;
        }
    }
    printf("%d %d\n", num, res);
    return;
}

int main() {
    int x, y, t;
    while (~scd(n) && n){
        V = 0;
        fill(mp[0], mp[0] + MAX * MAX, INF);
        for (int i = 0; i < n; ++i){
            scddd(x, y, t);
            mp[x][y] = mp[y][x] = t;
            V = max(V, max(x, y));
        }
        solve();
    }
    return 0;
}

C++: #include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

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

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 < dist.size(); ++i)
			dist[i][i] = 0;

		int m = 0;
		for(int i = 0; i < n; ++i) {
			int a, b, c;
			cin >> a >> b >> c;

			chmax(m, max(a, b));

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

		++m;
		for(int k = 0; k < m; ++k)
			for(int i = 0; i < m; ++i)
				for(int j = 0; j < m; ++j)
					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;
				city = i;
			}
		}

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

	return EXIT_SUCCESS;
}

C++: #include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

void exec()
{
	int dist[11][11]={0};
	int n;
	cin >> n;
	if(n==0){
		exit(0);
	}
	int t=0;
	for(int i=0;i<11;i++){
		for(int j=0;j<11;j++){
			dist[i][j]=1<<29;
		}
		dist[i][i]=0;
	}
	for(int i=0;i<n;i++){
		int a,b,c;
		cin >> a >> b >> c;
		dist[b][a]=dist[a][b]=c;
		t=max(t,a);
		t=max(t,b);
	}
	t++;
	for(int i=0;i<t;i++){
		for(int j=0;j<t;j++){
			for(int k=0;k<t;k++){
				dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
				//cout << i << " " << j << " " << k << ": " << dist[j][k] << endl;
			}
		}
	}

	int ret=1<<30;
	int town=0;
	for(int i=0;i<t;i++) {
		int sum=0;
		for(int j=0;j<t;j++) {
			sum+=dist[i][j];
		}
		if(sum<ret){
			ret=sum;
			town=i;
		}
	}

	cout << town << " " << ret << endl;

}
int main() {
	while(true)
		exec();

}