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>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

#define  N 15
int n;
int dis[N],maps[N][N];
int main()
{
    int i,a,b,c,j,k;
    while(scanf("%d",&n),n)
    {
        for(i=0;i<N;i++)
        {
            for(j=0;j<N;j++)
            {
                maps[i][j]=(i==j)?0:INF;
            }
        }

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

        for(k=0;k<=m;k++)
        {
            for(i=0;i<=m;i++)
            {
                for(j=0;j<=m;j++)
                {
                    if(maps[i][j]>maps[i][k]+maps[k][j])
                        maps[i][j]=maps[i][k]+maps[k][j];
                }
            }
        }

        int  Min=INF;
        int index=-1;
        memset(dis,0,sizeof(dis));
        for(i=0;i<=m;i++)
        {
            for(j=0;j<=m;j++)
            {
                dis[i]=dis[i]+maps[i][j];
            }
            if(Min>dis[i])
            {
                index=i;
                Min=dis[i];
            }
        }
        printf("%d %d\n",index,Min);
    }
    return 0;
}

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

const int INF = 1<<30;
const int MAX_V = 10;
const int MAX_E = 45;

int d[MAX_V][MAX_V];
int n;
int V;

void show_d() {
    cout << "===" << endl;
    for(int i = 0; i < V; i++) {
        for(int j = 0; j < V; j++) {
            printf("%3d ", d[i][j]);
        }
        cout << endl;
    }
}

void warshall_floyd() {
    for(int k = 0; k < V; k++) {
        for(int i = 0; i < V; i++) {
            for(int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
        // show_d(); // debug
    }
}

int main() {
    while(true) {
        cin >> n;
        if(!n) break;
        int f, t, c;
        V = 0;
        for(int i = 0; i < MAX_V; i++) {
            for(int j = 0; j < MAX_V; j++) {
                d[i][j] = INF;
                if(i == j) d[i][j] = 0;
            }
        }
        for(int i = 0; i < n; i++) {
            cin >> f >> t >> c;
            d[f][t] = c;
            d[t][f] = c;
            V = max(V, f+1);
            V = max(V, t+1);
        }

        warshall_floyd();

        int ix = 0, s = INF;
        for(int i = 0; i < V; i++) {
            int tmp = 0;
            for(int j = 0; j < V; j++) {
                tmp += d[i][j];
            }
            if(tmp < s) {
                ix = i;
                s = tmp;
            }
        }

        cout << ix << " " << s << endl;

    }
    return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int n,a,b,time,distance[10][10],min_value,min_index;
	int D[10],P[10],tmp_min,tmp_min_index,tmp_sum,count,max_number;

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

		for(int i = 0; i < 10; i++){
			for(int k = 0; k < 10; k++)distance[i][k] = 2000000000;
		}

		max_number = -1;
		for(int i = 0; i < n; i++){
			scanf("%d %d %d",&a,&b,&time);
			distance[a][b] = time;
			distance[b][a] = time;
			max_number = max(max_number,max(a,b));
		}

		min_value = 2000000000;

		for(int town = 0; town <= max_number; town++){
			for(int i = 0; i <= max_number; i++){
				P[i] = 0;
				D[i] = 2000000000;
			}

			for(int i = 0; i <= max_number; i++){
				if(distance[town][i] >= 0){
					D[i] = distance[town][i];
				}
			}

			count = 1;
			P[town] = 1;
			D[town] = 0;

			while(count <= max_number){
				tmp_min = 2000000000;
				for(int i = 0; i <= max_number; i++){
					if(D[i] >= 0 && P[i] == 0 && D[i] < tmp_min){
						tmp_min = D[i];
						tmp_min_index = i;
					}
				}

				if(tmp_min == 2000000000)break;

				P[tmp_min_index] = 1;
				count++;

				for(int k = 0; k <= max_number; k++){
					if(D[k] > D[tmp_min_index] + distance[tmp_min_index][k]){
						D[k] = D[tmp_min_index] + distance[tmp_min_index][k];
					}
				}
			}

			tmp_sum = 0;

			for(int i = 0; i <= max_number; i++){
				tmp_sum += D[i];
			}

			if(tmp_sum < min_value){
				min_value = tmp_sum;
				min_index = town;
			}else if(tmp_sum == min_value && town < min_index){
				min_index = town;
			}
		}

		printf("%d %d\n",min_index,min_value);

	}

    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 200000000
int main()
{
	int e;
	while(cin >> e,e)
	{
		int i,j,k,s=INF,v=0,ans=INF;
		cin >> e;
		if(e==0)break;
		int d[11][11];
		int cost_count[11] = {0};
		for(i=0;i<11;i++)
		{
			for(j=0;j<11;j++)
			{
				d[i][j] = INF;
				if(i==j)
				{
					d[i][j] = 0;
				}
			}
		}
		for(i=0;i<e;i++)
		{
			scanf("%d %d %d",&i,&j,&k);
			v = max(v,max(i,j));
			d[i][j] = k;
			d[j][i] = k;
		}
		for(k=0;k<v;k++)
		{
			for(i=0;i<v;i++)
			{
				for(j=0;j<v;j++)
				{
					d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		for(i=0;i<v;i++)
		{
			int cost = 0;
			for(j=0;j<v;j++)
			{
				cost += d[i][j];
			}
			cost_count[i] = cost;
			ans=min(ans,cost_count[i]);

		}
		for(i=0;i<v;i++)
		{
			if(cost_count[i]==ans)
			{
				printf("%d %d\n",i,ans);
				break;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#define INF 10000000;
using namespace std;

int main() {
	int towns[10][10]; 
	int n;
	while (1) {
		cin >> n;
		if (!n)break;

		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				towns[i][j] = INF;
			}
		}
		for (int i = 0; i < 10; i++) {
			towns[i][i] = 0;
		}
		int biggest_town = 0;
		int a, b, c;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			if (biggest_town < a)biggest_town = a;
			if (biggest_town < b)biggest_town = b;
			towns[a][b] = c;
			towns[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 (towns[i][j] > towns[i][k] + towns[k][j]) {
						towns[i][j] = towns[i][k] + towns[k][j];
					}
				}
			}
		}
		int start, total_time = 100000;
		for (int i = 0; i <= biggest_town; i++) {
			int tmp = 0;
			for (int j = 0; j <= biggest_town; j++) {
				if (towns[i][j] != 10000000)tmp += towns[i][j];
			}
			if (total_time > tmp) {
				total_time = tmp;
				start = i;
			}
		}
		cout << start << ' ' << total_time << endl;
	}
}