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 <stdio.h>

#define TEST 0
int weakdist(int tc[10][10],int town,int from,int to)
{
    if(from ==to)
        return 0;
    if(tc[from][to] >= 0)
        return tc[from][to];
    return -1;
}

int dist(int tc[10][10],int town,int from,int to)
{
    if(from ==to)
        return 0;
    if(tc[from][to] >= 0)
        return tc[from][to];
    int mindist=-1;
    for(int via=0;via<town;via++)
    {
        if(via == from || via ==to)
            continue;
        if(tc[from][via] == -1 || tc[via][to]==-1)
            continue;
        int sumdist=dist(tc,town,from,via)
        +dist(tc,town,via,to);
        if(mindist < 0 || mindist > sumdist)
            mindist=sumdist;
    }
    tc[from][to]=mindist;
    tc[to][from]=mindist;
    return mindist;
}
void dump(int tc[10][10])
{
    
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++)
            {
                printf("%d ",tc[i][j]);
            }
            puts("");
        }
}

int main(void)
{
    int n;
    int tc[10][10];//connections between towns
    while(scanf("%d",&n) == 1 && n != 0)
    {
        int town=0;
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++)
            {
                tc[i][j]=-1;
            }
            tc[i][i]=0;
        }
        for(int k=0;k<n;k++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            if(a==b)
                continue;
            tc[a][b]=c;
            tc[b][a]=c;
            if(town <a+1)town=a+1;
            if(town <b+1)town=b+1;
        }
#if TEST
        printf("town.num=%d\n",town);
#endif
        int minsum=-1;
        int minnum=-1;
        for(int cnt=0;cnt <45;cnt++)
        {
            for(int i=0;i<town;i++)
            {   
                for(int j=0;j<town;j++)
                {
                    dist(tc,town,i,j);
                }
            }
        }//try calculating for setting the map.
        for(int i=0;i<town;i++)
        {
            int sum=0;
            for(int j=0;j<town;j++)
            {
                sum+=dist(tc,town,i,j);
            }
            if(minsum<0 || minsum >sum)
            {
                minsum=sum;
                minnum=i;
            }
        }
#if TEST
        dump(tc);
#endif
        printf("%d %d\n",minnum,minsum);
    }
    return 0;

}

C++: #include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810

int n, town;
int g[15][15];int d[15][15];


int main()
{
	while(cin>>n, n)
	{
		town = 0;
		REP(i,15)REP(j,15)
		{
			g[i][j] = INF;
			if(i==j) g[i][j] = 0;
		}
		REP(i,n)
		{
			int a,b,c;
			cin >> a >> b >> c;
			if(town < max(a,b)) town = max(a,b);
			g[a][b] = c;
			g[b][a] = c;
		}

		town++;

		REP(k,town)REP(i,town)REP(j,town)
		{
			g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
		}
		int ans = INF;
		int anstown;
		REP(i,town)
		{
			int a = 0;
			REP(j,town)
			{
				a += g[i][j];
			}
			if(a < ans)
			{
				ans = a;
				anstown = i;
			}
		}
		cout << anstown <<" "<< ans <<endl;
	}

}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX 50
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];

int dijkstra(int s,int g){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = minnum ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = minnum ; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            if(t < v[i]) v[i] = t;
        }
    }
    
    return v[g];
}


int main(){
    int a,b,c;
    
    for(int i = 0 ; i < MAX ; i++)
        for(int j = 0 ; j < MAX ; j++)
            r[i][j] = INF;

    while(cin >> n,n){
        maxnum = 0;
        minnum = INF;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = c;
            r[b][a] = c;
            r[a][a] = 0;
            r[b][b] = 0;
            maxnum = max(maxnum,max(a,b));
            minnum = min(minnum,min(a,b));
        }

        int mx = INF, num = 0;
        for(int i = minnum ; i <= maxnum ; i++){
            int sum = 0;
            for(int j = minnum ; j <= maxnum ; j++){
                if(i == j) continue;
                if(dijkstra(i,j)!=INF) sum += dijkstra(i,j);
            }
            if(sum < mx){
                mx = sum;
                num = i;
            }
        }
        cout << num << ' ' << mx << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n,a,b,c,house,sum,mins;
	while (cin >> n, n) {
		vector< vector<int> > road(10, vector<int>(10, 10001));
		for (int i = 0; i < 10; i++)
			road[i][i] = 0;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			road[a][b] = road[b][a] = c;
		}
		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					if (road[i][k] != 10001 && road[k][j] != 10001)
						if (road[i][j] > road[i][k] + road[k][j]) road[i][j] = road[i][k] + road[k][j];
				}
			}
		}
		house = 0;
		mins = 100001;
		for (int i = 0; i < 10; i++) {
			sum = 0;
			for (int j = 0; j < 10; j++) {
				if(road[i][j] != 10001)
					sum += road[i][j];
			}
			if (sum != 0 && mins > sum) {
				mins = sum;
				house = i;
			}
		}
		cout << house << " " << mins << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

const int LIMIT = 1000000000;

int main()
{
	int n;

	while( cin >> n && n ){
		int wf[ 10 ][ 10 ] = {0};
		for( int i = 0; i < 10; ++i ){
			for( int j = 0; j < 10; ++j ){
				if( i != j ) wf[ i ][ j ] = LIMIT;
			}
		}
		int m = 0;
		for( int i = 0; i < n; ++i ){
			int s, e, d;
			cin >> s >> e >> d;
			if( m < s ) m = s;
			if( m < e ) m = e;
			wf[ s ][ e ] = wf[ e ][ s ] = d;
		}
		m += 1;
		for( int k = 0; k < m; ++k ){
			for( int i = 0; i < m; ++i ){
				for( int j = 0; j < m; ++j ){
					wf[ i ][ j ] = min( wf[ i ][ j ], wf[ i ][ k ] + wf[ k ][ j ] );
				}
			}
		}
		int ansP = 0;
		int ansD = LIMIT;
		for( int i = 0; i < m; ++i ){
			int sum = 0;
			for( int j = 0; j < m; ++j ){
				sum += wf[ j ][ i ];
			}
			if( ansD > sum ){
				ansP = i;
				ansD = sum;
			}
		}
		cout << ansP << " " << ansD << endl;
	}


	return 0;
}