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 <cstdio>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <functional>
#include <string.h>
using namespace std;
const int INF = 1000000000;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,start,end) for(int i=(start);i<(end);++i)
#define pint(i) printf("%d\n",(i))
#define pint2(i,j) printf("%d %d\n",(i),(j))
#define pint3(i,j,k) printf("%d %d %d\n",(i),(j),(k))
#define gint(i) scanf("%d",&(i))
#define gint2(i,j) scanf("%d %d",&(i),&(j))
#define gint3(i,j,k) scanf("%d %d %d",&(i),&(j),&(k))
#define init(tar,val) memset((tar),(val),sizeof((tar)))
#define show(tar,len) for(int i=0;i<(len);++i) \
	cout<<tar[i]<<' ';\
	cout<<endl;




class bignum{
public:
	bignum(int size = 4) :len(size){
	}
	~bignum(){
	}
	int size()const{
		return len;
	}
	//int get(int id)const{
	//	return num[id];
	//}
	friend ostream &operator<<(ostream &output, const bignum &b){
		bool stu = false;
		for (int i = int(b.len - 1); i >= 0; --i){
			if (stu)
				printf("%09d", b.num[i]);
			else if (b.num[i] > 0){
				printf("%d", b.num[i]);
				stu = true;
			}
		}
		if (stu == false)
			printf("0");
		return output;
	}
	const bignum& operator+=(const bignum&right){
		int add = 0;
		for (int i = 0; i < len; ++i){
			int tmp = 0;
			if (i < right.size()){
				tmp = right.num[i] + num[i] + add;
			}
			else{
				tmp = num[i] + add;
			}
			num[i] = tmp%gap;
			add = tmp / gap;
		}
		return *this;
	}
	const bignum& operator=(const bignum&right){
		for (int i = 0; i < len; ++i){
			num[i] = right.num[i];
		}
		return *this;
	}
	void set(int a){
		for (int i = 0; i < len; ++i){
			num[i] = a%gap;
			a /= gap;
		}
	}
private:
	int  num[4];
	int len;
	static const int gap = 1000000000;
};


//inline int id(int i){
//	return i & 1;
//}
//
//inline int last(int i){
//	return (i - 1) & 1;
//}
//
//void myshow(int i){
//	rep(j, 0, ){
//		cout << dp[id(i)][j] << ' ';
//	}
//	cout << endl;
//}


//#define my_debug

const int MAX_NUM = 15;

int n;
int len[MAX_NUM][MAX_NUM];
//int stu[MAX_NUM];
//set<int> cache;
void myinit(){
	rep(i, 0, MAX_NUM)
		rep(j, 0, MAX_NUM){
		if (i == j)
			len[i][j] = 0;
		else
			len[i][j] = INF;
	}
}


void solve(){
	rep(i, 0, MAX_NUM){
		rep(j, 0, MAX_NUM){
			rep(k, 0, MAX_NUM){
				len[i][j] = min(len[i][j], len[i][k] + len[k][j]);
			}
		}
	}
	int out = INF, t = 0;
	//for (int i : cache){
	//	int tmp = 0;
	//	for (int j : cache){
	//		tmp += len[i][j];
	//	}
	//	if (tmp && tmp < out){
	//		out = tmp;
	//		t = i;
	//	}
	//}
	rep(i, 0, MAX_NUM){
		int tmp = 0;
		rep(j, 0, MAX_NUM){
			if (i!=j && len[i][j] < INF)
				tmp += len[i][j];
		}
		//cout << i << ' ' << tmp << endl;
		if (tmp && tmp < out){
			out = tmp;
			t = i;
		}
	}
	pint2(t, out);
	//cout << t << ' ' << out << endl;
}

int main(){
#ifdef my_debug
	freopen("a.in", "r", stdin);
#endif
	while (gint(n) != EOF){
		if (n == 0)
			break;
		//fill(stu, stu + MAX_NUM, INF);
		myinit();
		//cache.clear();
		int tmp1, tmp2;
		rep(i, 0, n){
			gint2(tmp1, tmp2);
			int tmp;
			gint(tmp);
			len[tmp2][tmp1] = len[tmp1][tmp2] = tmp;
			//cache.insert(tmp1);
			//cache.insert(tmp2);
		}
		solve();
	}
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n;
	while(cin >> n, n){
		int d[15][15];
		rep(i, 15){
			rep(j, 15) d[i][j] = inf;
			d[i][i] = 0;
		}
		int v = -1;
		for(int i=0; i < n; i++){
			int a, b, c;
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
			v = max(v, max(a+1, b+1));
		}
		rep(k, v) rep(i, v)rep(j, v) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

		int m = inf, ret = -1;
		for(int i=0; i < v; i++){
			int sum = 0;
			for(int j=0; j< v; j++) if(d[i][j] != inf) sum += d[i][j];
			if(sum < m){m = sum; ret = i;}
		}
		cout << ret << " " << m << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>

const int TOWN = 10;
const int PATH = 45;
const int INF = 100000000;

using namespace std;

int main() {
	int n;
	int a, b;

	while (cin >> n , n) {
		int num_of_town = 0;
		int g[TOWN][TOWN] = {};
		for (int i = 0; i < TOWN; i++) {
			for (int j = 0; j < TOWN; j++) {
				g[i][j] = 0;
			}
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			cin >> g[a][b];
			g[b][a] = g[a][b];
			num_of_town = max(num_of_town, max(a, b));
		}
		num_of_town++;
		//	cout << "num_of_town = " << num_of_town << "\n";

		int d[TOWN][TOWN];
		for (int i = 0; i < num_of_town; i++) {
			for (int j = 0; j < num_of_town; j++) {
				if (i == j)			d[i][j] = 0;
				else if (g[i][j] != 0) d[i][j] = g[i][j];
				else				d[i][j] = INF;
			}
		}

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

		//cout << "\n";
		//for (int i = 0; i < num_of_town; i++) {
		//	for (int j = 0; j < num_of_town; j++) {
		//		cout << i << " " << j << " " <<  d[i][j] << "\n";
		//	}
		//}
		//cout << "\n";

		int ans_d = INF;
		int ans_t;
		int tmp = 0;
		for (int i = 0; i < num_of_town; i++) {
			for (int j = 0; j < num_of_town; j++) {
				tmp += d[i][j];
			}
			if (ans_d > tmp) {
				ans_d = tmp;
				ans_t = i;
			}
			tmp = 0;
		}
		cout << ans_t << " " << ans_d << "\n";
	}
	
 	return 0;
}