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>
#include<cstring>

#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 k=0; k<n; k++ ) {
		
		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 <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cstdio>
#include <cctype>
#include <queue>
#include <cmath>
#include <stack>
using namespace std;
const int inf = 0x3f3f3f3f, N = 20;

int e[N][N];
void floyd(int n)
{
    for(int k = 0; k <= n; k++)
        for(int i = 0; i <= n; i++)
            for(int j = 0; j <= n; j++)
            e[i][j] = min(e[i][k] + e[k][j], e[i][j]);
}
int main()
{
    int m;
    while(cin >> m, m) {
    for(int i = 0; i < 10; i++)
        for(int j = 0; j < 10; j++) {
            if(i == j) e[i][j] = 0;
            else e[i][j] = e[j][i] = inf;
        }
        int Max = 0;
        while(m--) {
            int x, y, l;
            scanf("%d%d%d", &x, &y, &l);
            if(x > Max) Max = x;
            if(y > Max) Max = y;
            e[x][y] = e[y][x] = l;
        }
        floyd(Max);
        int msum = inf, mp;
        int ms = 0;
        for(int i = 0; i <= Max; i++) {
            ms = 0;
            for(int j = 0; j <= Max; j++) {
                ms += e[i][j];
            }
            if(ms < msum) {
                msum = ms;
                mp = i;
            }
        }
        printf("%d %d\n", mp, msum);
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
struct edge{int to;int cost;};
typedef pair<int,int> P;
const int Inf=1e7;
int N;
int A,B,C;
vector<edge>X[10];
int d[10];
int cou;
int main()
{
	while(true){

		int ans1=0,ans2=Inf;
		cou=0;
		scanf("%d",&N);
		if(N==0)break;
		for(int i=0;i<N;i++){
			scanf("%d%d%d",&A,&B,&C);
			edge e1={B,C};
			X[A].push_back(e1);
			edge e2={A,C};
			X[B].push_back(e2);
			cou=max(cou,max(A,B));
		}
		for(int s=0;s<=cou;s++){
			for(int i=0;i<=cou;i++)d[i]=Inf;
			d[s]=0;
			priority_queue<P, vector<P>, greater<P> > que;
			que.push(make_pair(0,s));
			while(!que.empty()){
				P p=que.top();que.pop();
				int v=p.second;
				if(d[v]<p.first)continue;
				for(int i=0;i<X[v].size();i++){
					edge e=X[v][i];
					if(d[e.to]>d[v]+e.cost){
						d[e.to]=d[v]+e.cost;
						que.push(make_pair(d[e.to],e.to));
					}
				}
			}
			//for(int i=0;i<=cou;i++)printf("%d %d %d\n",s,i,d[i]);
			int sum=0;
			for(int i=0;i<=cou;i++)sum+=d[i];
			if(ans2>sum){
				ans2=sum;
				ans1=s;
			}
		}
		printf("%d %d\n",ans1,ans2);
	}
	return 0;
}