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 <algorithm>
using namespace std;
#define MAX 10
#define INF 9999999

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

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


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;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = c;
            r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
        }

        int mx = INF, e;
        for(int i = 0 ; i <= maxnum ; i++){

            if(dijkstra(i) < mx){
                mx = dijkstra(i);
                e = i;
            }
        }
        cout << e << ' ' << mx << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;

#define N 150
int inf=99999999;
int e[N][N];
int mark[N];
int m;
void init(int n)
{
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
        {
            if(i==j)e[i][j]=0;
            else
                e[i][j]=inf;
        }
}

void floyd(int n)
{
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
            for(int k=0; k<=n; k++)
            {
                    if(e[j][k]>e[j][i]+e[i][k])
                    {
                        e[j][k]=e[j][i]+e[i][k];
                    }
            }
}

int main()
{
    while(scanf("%d",&m),m!=0)
    {
        int n=-1;
        int a,b,c;
        init(150);
        memset(mark,0,sizeof(mark));
        while(m--)
        {
            scanf("%d%d%d",&a,&b,&c);
            e[a][b]=e[b][a]=c;
            if(a>n)n=a;
            if(b>n)n=b;
            mark[a]=1;
            mark[b]=1;
        }

        floyd(n);
        int ans1,ans2;
        ans1=ans2=inf;
        for(int i=0; i<=n; i++)
        {
            int sum=0;
            if(mark[i]==1)
            {

                for(int j=0; j<=n; j++)
                {
                    if(mark[j]==1&&e[i][j]!=inf)
                    {
                        sum+=e[i][j];
                    }
                }
            }
            if(sum<ans2)
            {
                ans2=sum;
                ans1=i;
            }
        }
        printf("%d %d\n",ans1,ans2);
    }
    return 0;
}