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 <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
#define MAX_V 10
using namespace std;
int E, V;
int dp[MAX_V][MAX_V];

void warshall_floyd(){
	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 main(){
	while(~scanf("%d", &E) && E){
		V = 0;
		memset(dp, 0x3f, sizeof(dp));
		for(int i = 0; i < E; i++){
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			dp[a][b] = dp[b][a] = min(dp[a][b], c);
			V = max(V, max(a, b));
		}
		++V;
		for(int i = 0; i < V; i++) dp[i][i] = 0;
		warshall_floyd();
		int idx, minsum = INF;
		for(int i = 0; i < V; i++){
			int sum = 0;
			for(int j = 0; j < V; j++) sum += dp[i][j];
			if(sum < minsum) minsum = sum, idx = i;
		}
		printf("%d %d\n", idx, minsum);
	}
	return 0;
}

C++: #include <iostream>

// int inf = 1 << 28;
int inf = 1000000000;

int dijk(int n,int s, int **g) {
	int sum = 0;
	bool *used = new bool[n];
	int *d = new int[n];

	// std::cout << "n = " << n << " " << "s = " << s << std::endl;

	for(int j=0;j<n;j++){
		for(int i=0;i<n;i++){
			std::cout << g[j][i] << ",";
		}
		std::cout << std::endl;
	}

	for(int i = 0; i < n; i++)
		d[i] = inf;
	d[s] = 0;

	while(true) {
		int u = -1;
		for(int v = 0; v < n; v++)
			if(!used[v] && (u == -1 || d[v] < d[u]))
				u = v;

		// std::cout << "u = " << u << std::endl;

		if(u == -1) break;
		used[u] = true;

		for(int v = 0; v < n; v++)
			if(d[v] > d[u] + g[u][v])
				d[v] = d[u] + g[u][v];
	}

	for(int i = 0; i < n; i++) {
		sum += d[i];
	}

	// for(int i = 0; i < n; i++) {
	// std::cout << d[i] << std::endl;
	// }

	return sum;
}

int main() {
	do {
		int **g; // adjacency matrix, ?
		int *d;
		int *a, *b, *c;
		int edge = 0, min = 0, max = 0;
		int tmp = 0;

		std::cin >> edge;
		if(!edge) break;

		a = new int[edge];
		b = new int[edge];
		c = new int[edge];

		for(int i = 0;i < edge;i++) {
			std::cin >> a[i];
			std::cin >> b[i];
			std::cin >> c[i];
		}

		for(int i = 0; i < edge; i++) {
			if(max < a[i])
				max = a[i];
		}
		for(int i = 0; i < edge; i++) {
			if(max < b[i])
				max = b[i];
		}
		max++;

		g = new int*[max];
		d = new int[max];

		for(int i = 0; i < max; i++) {
			g[i] = new int[max];
		}

		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				g[i][j] = inf;

		for(int i = 0; i < edge; i++)
			g[b[i]][a[i]] = g[a[i]][b[i]] = c[i];

		for(int i=0;i<max;i++){
			g[i][i]=0;
		}

		
		for(int k=0;k<max;k++){
			for(int j=0;j<max;j++){
				for(int i=0;i<max;i++){
					if(g[i][k]+g[k][j]<g[i][j]){
						g[i][j]=g[i][k]+g[k][j];
					}
				}
			}
		}
		

		for(int i = 0; i < max; i++)
			d[i] = dijk(max, i, g);

/*
		for(int i = 0; i < max; i++){
			d[i]=0;
			for(int j=0;j<max;j++){
				d[i] += g[i][j];
			}
		}
*/

		min = d[0];
		for(int i = 1; i < max; i++) {
			if(min > d[i]) {
				min = d[i];
				tmp = i;
			}
		}

		std::cout << tmp << " " << min << std::endl;
		for(int i = 0; i < max; i++)
			delete[] g[i];
		delete[] g;
		delete[] a;
		delete[] b;
		delete[] c;
		delete[] d;

	}while(true);
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <limits>
#include <queue>
#include <vector>
using namespace std;

int d[10][10];

int main() {
	for (;;) {
		int n; scanf("%d", &n);
		if (n == 0) break;
		for (int u = 0; u < 10; u++)
			for (int v = 0; v < 10; v++)
				d[u][v] = (u == v) ? 0 : (INT_MAX / 2);
		int N = 0;
		for (; n > 0; n--) {
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			d[a][b] = c;
			d[b][a] = c;
			N = max(N, max(a + 1, b + 1));
		}
		for (int k = 0; k < N; k++)
			for (int u = 0; u < N; u++)
				for (int v = 0; v < N; v++)
					d[u][v] = min(d[u][v], d[u][k] + d[k][v]);
		int umin = 0, dmin = INT_MAX;
		for (int u = 0; u < N; u++) {
			int dsum = 0;
			for (int v = 0; v < N; v++)
				dsum += d[u][v];
			if (dsum < dmin) {
				umin = u;
				dmin = dsum;
			}
		}
		printf("%d %d\n", umin, dmin);
	}
}

C++: //2013/11/15(Fri)

#include <iostream>
using namespace std;
int main()
{
	
	while(true){
		int n;
		int a,b,c;
		int INF = 12001;
		int time[10][10];
		int m=0;
		int sam=0;
		int min=12000,imin=0;
		cin >> n;
		if(n==0)
			break;
		for(int i=0; i<10; i++)
			for(int j=0; j<10; j++){
				if(i==j)
					time[i][j] = 0;
		
				else
					time[i][j] = INF;
			}

		for(int i=0; i<n; i++){
			cin >> a >> b >> c;
			time[a][b] = c;
			time[b][a] = c;
			if(m<a)
				m=a;
			if(m<b)
				m=b;
		}


		for(int h=0; h<m+1; h++)
			for(int i=0; i<m+1; i++)
				for(int j=0; j<m+1; j++)
					if(time[i][h]==INF||time[h][j]==INF)
                        continue;
                    else if(time[i][j]==INF)
                        time[i][j] = time[i][h]+time[h][j];
                    else if(time[i][j]>time[i][h]+time[h][j])
                        time[i][j] = time[i][h]+time[h][j];

									
		
		for(int i=0; i<m+1; i++)
			sam += time[0][i];


		for(int i=1; i<m+1; i++){
            int sum = 0;
            for(int j=0; j<m+1; j++)
                sum += time[i][j];
            if(sum<min){
                imin = i;
                min = sum;
            }
        }

			cout << imin << ' ' << min << endl;
	}
	return 0;
	
}