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>
using namespace std;
static const int MAX_V = 10;
static const int MAX_E = 45;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX_V][MAX_V];

int dijkstra(int s){
	int mincost;
	int d[MAX_V], color[MAX_V];

	for(int i = 0; i < MAX_V; i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[s] = 0;
	color[s] = GRAY;
	while(true){
		int u;
		mincost = INFTY;
		for(int i = 0; i < MAX_V; i++){
			if(mincost > d[i] && color[i] != BLACK){
				u = i;
				mincost = d[i];
			}
		}

		if(mincost == INFTY) break;

		color[u] = BLACK;

		for(int v = 0; v < MAX_V; v++){
			if(color[v] != BLACK && M[u][v] != INFTY){
				if(d[v] > d[u] + M[u][v]){
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}
	int sum_d = 0;
	for(int i = 0; i < MAX_V; i++){
		if(d[i] != INFTY){
			sum_d += d[i];
		}
	}
	return sum_d;
}

int main(void){
	while(true){
		scanf("%d", &n);
		if(n == 0) break;

		for(int i = 0; i < MAX_V; i++){
			for(int j = 0; j < MAX_V; j++){
				M[i][j] = INFTY;
			}
		}

		for(int i = 1; i <= n; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			M[a][b] = M[b][a] = c;
		}

		int min_v, min_d = INFTY;
		for(int i = 0; i < MAX_V; i++){
			int dist = dijkstra(i);
			//printf("%d %d\n", i, dist);
			if(dist < min_d && dist != 0){
				min_d = dist;
				min_v = i;
			}
		}

		printf("%d %d", min_v, min_d);
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
#include <unordered_map> //???????????\??¢??°

using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
//#define TEST //*******************************************************************************************************************************************

//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
#ifdef TEST
    #define dout cout
#else
    stringstream dummy; //???????????°??????dout?????????????????????????????????
    #define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
    //???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif


#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << (A) << " "
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl









////////////////////////////////////////
//AIZU
//Convenient Location
//
//??????????????????
//
//
////////////////////////////////////////

const int INF = 1e9-1;

int main(void) {
    
    int N = 10; //????????°????????§??§???10
    int M; //?????°
    int a, b, c;
    
    int d[N][N]; //0~9??????????????????
    int sumTotalCost[N]; //sumTotalCost[i] = i????????§?????????????????????????????????????????¢?????????????????????????????????????°???????ans??¨??????
    
    
    while(1) {
        cin >> M;
        if( M== 0 ) break;
        
        //initialization
        rep(i,0,N) {
            rep(j,0,N) {
                d[i][j] = (i==j ? 0 : INF);
            }
        }
        
        rep(i,0,N) {
            sumTotalCost[i] = 0;
        }
        
        
        rep(i,0,M) {
            cin >> a >> b >> c; //??????a??????b?????§????????????t
            
            d[a][b] = d[b][a] = c;
        }
        
        //test display
        rep(i,0,N) {
            disP(i);
            dispAll(d[i], N);
        }
        dout << endl;
        
        //Warshall Floyd Algorithm
        rep(i,0,N) {
            rep(j,0,N) {
                rep(k,0,N) {
                    d[i][j] = min( d[i][j], d[i][k] + d[k][j] );
                }
            }
        }
        
        //test display
        rep(i,0,N) {
            disP(i);
            dispAll(d[i], N);
        }
        dout << endl;
        
        
        //??????????????????????????????????????????????±???????
        rep(i,0,N) {
            rep(j,0,N) {
                sumTotalCost[i] += ( d[i][j]==INF ? 0 : d[i][j] ); //INF???????????????INF??\????????°???????¶?????????????
            }
        }
        
        //test display
        dispAll(sumTotalCost, N);
        dout << endl;
        
        
        //????????????????????????????°???¨?????????????±???????
        int ans = INF;
        int ans_Origin = 0;
        rep(i,0,N) {
            if( ans > sumTotalCost[i] && sumTotalCost[i] != 0 ) { //???????????¨????????????i???sumTotal???0????????§???0?????????????????????
                ans = sumTotalCost[i];
                ans_Origin = i;
            }
        }
        
        disp(ans_Origin);
        dout << "??????????????¨??????????????????????????????????°???¨???????????????????????????????????????\n";
        disp(ans);
        dout << "??¨?????????\n";
        
        cout << ans_Origin << " " << ans << endl;
        
    }
    
    return 0;
}

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

using namespace std;

const int INF = 10000000;

int main(void)
{
	int m,n;
	int city[11][11];
	int dist[11][11];
	n = 0;

	while( cin >> m && m ){
		n = 0;

		for( int i = 0;i < 11;i++ ){
			for( int j = 0;j < 11;j++ ){
				city[i][j] = INF;
				dist[i][j] = INF;
			}
		}

		for( int i = 0;i < 11;i++ ){
			city[i][i] = 0;
			dist[i][i] = 0;
		}

		for( int i = 0;i < m;i++ ){
			int a,b,cost;

			cin >> a >> b >> cost;
			n = max( n, a );
			n = max( n, b );
			city[a][b] = cost;
			city[b][a] = cost;
		}

		for( int k = 0;k <= n;k++ ){
			for( int j = 0;j <= n;j++ ){
				for( int i = 0;i <= n;i++ ){
					dist[k][i] = min( dist[k][i], dist[k][j] + city[j][i] );
				}
			}
		}

		int answer = 0;
		int sum;
		int answer_sum = INF;
		for( int i = 0;i <= n;i++ ){
			sum = 0;
			for( int j = 0;j <= n;j++ ){
				sum += dist[i][j];
			}
			if( answer_sum > sum ){
				answer_sum = sum;
				answer = i;
			}
		}


		cout << answer << " " << answer_sum << endl;
	}

	return 0;
}