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>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int d[105][105];
int main()
{
	int n,m;
	scanf("%d",&m);
	while(m){
		n=0;
		memset(d,0x3f,sizeof d);
		for(int i=1;i<=m;i++){
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			d[a][b]=c;
			d[b][a]=c;
			n=max(n,max(a,b));
		}
		for(int i=0;i<=n;i++)
			d[i][i]=0;
		for(int k=0;k<=n;k++)
			for(int i=0;i<=n;i++)
				for(int j=0;j<=n;j++)
					if(d[i][k]!=1061109567&&d[k][j]!=1061109567)
					d[i][j]=min(d[i][k]+d[k][j],d[i][j]);
		int ans=1<<30,ansi;
		for(int i=0;i<=n;i++){
			int sum=0;
			for(int j=0;j<=n;j++){
				if(d[i][j]==1061109567){
					sum=1<<30;
					break;
				}
				sum+=d[i][j];
			}
			if(sum<ans)
				ans=sum,ansi=i;
		}
		printf("%d %d\n",ansi,ans);
		scanf("%d",&m);
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
const int INF = 9999999;
const int max_e=15;
const int max_v=15;
int d[max_v][max_v];
int V,E;
int read()
{
    int n;
    scanf("%d",&n);
    if(n==0) return 0;
    V=0;
    for(int i=0;i<max_v;i++)
        for(int j=0;j<max_v;j++)
        {
            if(i==j) d[i][j]=0;
            else d[i][j]=INF;
        }
    while(n--)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        a+=1,b+=1;
        V=max(V,max(a,b));
        d[a-1][b-1]=d[b-1][a-1]=c;
    }
    return 1;

}
void floyd_warshall()
{
    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]);
            }
}

int main()
{
    while(read())
    {
        floyd_warshall();
        int cnt=INF,id;
        for(int i=0;i<V;i++)
        {
            int sum=0;
            for(int j=0;j<V;j++)
            {
                sum+=d[i][j];
            }
            if(cnt>sum)
            {
                cnt=sum,id=i;
            }
        }
        printf("%d %d\n",id,cnt);
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int v;
const long long int inf = 999999999999;
int main() {
	int n;
	while(cin>>n){
		int a[n+5],b[n+5],c[n+5];
		int dp[n+5][n+5];
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j)dp[i][j]=0;
				else dp[i][j]=inf;
			}
		}
		
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i]>>c[i];
			dp[a[i]][b[i]]=c[i];
		}
		
		for(int k=0;k<v;k++){
            		for(int i=0;i<v;i++){
            			for(int j=0;j<v;j++){
            				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            			}
            		}
		}			
        
        int sum[n];
        for(int i=0;i<n;i++){
        	sum[i]=0;
        	for(int j=0;j<n;j++){
        		if(dp[i][j]!=inf&&i!=j){
        			sum[i]+=dp[i][j];
        		}
        	}
        }
        
        int ans_i=0;
        for(int i=0;i<n;i++){
        	if(sum[i]<sum[ans_i]&&sum[i]!=0) ans_i=i;
        }
        cout<<ans_i<<" "<<sum[ans_i]<<endl;
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <climits>

const int max_t = 20;
int dist[max_t][max_t];

int main() {
	//freopen("aoj0189.txt", "r", stdin);
	while (1) {
		int n, t = 0;
		scanf("%d", &n);
		if (n == 0) break;
		
		for (int i = 0; i < max_t; i++) {
			std::fill(dist[i], dist[i] + max_t, INT_MAX);
		}
		for (int i = 0; i < n; i++) {
			int from, to, d;
			scanf("%d%d%d", &from, &to, &d);
			t = std::max(t, from);
			t = std::max(t, to);
			dist[from][to] = d;
			dist[to][from] = d;
		}
		for (int i = 0; i <= t; i++) {
			dist[i][i] = 0;
		}

		for (int i = 0; i < t; i++) {
			for (int j = i + 1; j <= t; j++) {
				for (int k = i + 1; k < j; k++) {
					if (dist[i][k] != INT_MAX && dist[k][j] != INT_MAX) {
						dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
						dist[j][i] = dist[i][j];
					}
				}
			}
		}

		int min_len = INT_MAX;
		int start = -1;
		for (int i = 0; i <= t; i++) {
			int len = 0;
			for (int j = 0; j <= t; j++) {
				if (j == i) continue;

				len += dist[i][j];
			}
			if (len < min_len) {
				min_len = len;
				start = i;
			}
		}

		printf("%d %d\n", start, min_len);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#define inf 9999

using namespace std;

bool check(int *label, int n)
{
	for(int i = 0; i < n; i++){
		if(label[i] == 0){
			return true;
		}
	}
	
	return false;
}

int dij(int **a, int n, int s)
{
	int *label, current=s, next, *cost, min;

	cost = (int *)calloc(n, sizeof(int));
	label = (int *)calloc(n, sizeof(int));
	for(int i = 0; i < n; i++){
		cost[i] = a[current][i];
	}
	label[current] = 1;
	
	while(check(label, n)){
		min = inf;
		for(int i = 0; i < n; i++){
			if(min >= cost[i] && label[i] == 0){
				min = cost[i];
				next = i;
			}
		}
		label[next] = 1;
		for(int i = 0; i < n; i++){
			if(label[i] == 0 && cost[i] > a[next][i]+cost[next]){
				cost[i] = a[next][i] + cost[next];
			}
		}
		current = next;
	}
	next = 0;
	for(int i = 0; i < n; i++){
		next += cost[i];
	}
	free(label);
	free(cost);
	
	return next;
}

int main(int argc, char **argv)
{
	int **a, n, s, t, m, u;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (int **)calloc(10, sizeof(int));
		for(int i = 0; i < 10; i++){
			a[i] = (int *)calloc(10, sizeof(int));
		}
		m = 0;
		for(int i = 0; i < n; i++){
			cin >> s >> t >> u;
			a[s][t] = a[t][s] = u;
			if(s > m){
				m = s;
			}
			if(t > m){
				m = t;
			}
		}
		
		for(int i = 0; i <= m; i++){
			for(int j = i+1; j <= m; j++){
				if(a[i][j] == 0){
					a[i][j] = a[j][i] = inf;
				}
			}
		}
		
		t = u = inf;
		for(int i = 0; i <= m; i++){
			s = dij(a, m+1, i);
			if(s < t){
				u = i;
				t = s;
			}
		}
		cout << u << " " << t << endl;
		for(int i = 0; i < 10; i++){
			free(a[i]);
		}
		free(a);
	}
	
	return 0;
}