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 <vector>
#include <queue>
#include<algorithm>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define ALL(a) a.begin(),a.end()
#define B1 1000000007
#define B2 100000007
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, w,n,r,l;
int main() {
    int n,a,b,c,m,o; 
    while (cin >> n, n) {
        m = 0;
        vector<vector<int>> G(10, vector<int>(10, 1e9));
        rep(i, 10) G[i][i] = 0;
        rep(i, n) {
            cin >> a >> b >> c;
            G[a][b] = G[b][a] = c;
            m = max(m, max(a, b));
        }m++;
        vector<vector<int>> dp;
        int ans = 1e9+7;
        rep(j, m) {
            rep(k, m) {
                rep(l, m) {
                    G[k][l] = min(G[k][l], G[k][j] + G[j][l]);
                }
            }
        }
        rep(i, m) {
            int sum = 0;
            rep(j, m) {
                sum += G[i][j];
            }
            if (sum < ans) {
                o = i; ans = sum;
            }
        }
        cout << o << " " << ans << endl;
    }
}

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

#define INF 1000000

int E, V;
int cost[50][50];
int d[100];

int main(){

    while(cin >> E, E){
        V = 0;
        int minCost = 1000000;
        fill(d, d+100, 0);
        for(int i=0; i < 50; i++){
            cost[i][i] = 0;
            for(int j=0; j < 50; j++){
                if(i != j)cost[i][j] = INF;
            }
        }
        for(int i=0; i < E; i++){
            int a, b, c;
            cin >> a >> b >> c;
            cost[a][b] = c;
            cost[b][a] = c;
            V = max(V, max(a, b));
        }
        for(int k=0; k <= V; k++){
            for(int i=0; i <= V; i++){
                for(int j=0; j <= V; j++){
                    cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
                }
            }
        }

        for(int i=0; i <= V; i++){
            for(int j=0; j <= V; j++){
                d[i] += cost[i][j];
            }
            if(d[i] != 0) minCost = min(minCost, d[i]);
        }

        for(int i=0; i <= V; i++){
            if(minCost == d[i]) cout << i << " " << d[i] << endl;
        }
    }
}

C++: // Warshall-floyd
#include <iostream>
#include <algorithm>
using namespace std;
#define INF (1<<20) 

int n, a, b, c, v, d[11][11];// v: num of nodes

/*
void init()
{
}
//*/

int main(void)
{
    ios::sync_with_stdio(false);
    while(1) {
        cin >> n;
        if(n == 0) break;
        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                if(i==j)// If not exist cost, cost=INF
                    d[i][j] = 0;
                else
                    d[i][j] = INF;
            }
        }
        //init();

        v = -1;
        for(int i=0; i<n; i++) {
            cin >> a >> b >> c;
            d[a][b] = c; d[b][a] = c;
            v = max(max(v, a), b);
        }
        v++;

        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 city, dist = INF;
        for(int i=0; i<v; i++) {
            int sum = 0;
            for(int j=0; j<v; j++) {
                sum += d[i][j];
            }
            if(sum < dist) {
                dist = sum;
                city = i;
            }
        }
        cout << city << " " << dist << endl;
    }

    return 0;
}

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

const int INF = 1000000000;

int main()
{
	int T[10][10];
	int z=0;
	int a=0;
	int p[10];
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}
		for(int i=0;i<m;i++){
			p[i]=0;
			for(int j=0;j<m;j++){
				p[i]=p[i]+T[i][j];
			}
		}
		z=p[0];
		for(int i=0;i<m;i++){
				if(z>p[i]){
					z=p[i];
				 a=i;
				}
		}
		
		cout<<a<<" "<<z<<endl;
	}

	return 0;
}

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

int main(){
	while(1){
		int n;
		long road[10][10];
		scanf(" %d", &n);
		if(n==0) break;
		
		memset(road, -1, sizeof(road));
		for(int i=0; i<10; ++i) road[i][i]=0;
		 
		int city=0; //街の数
		for(int i=0; i<n; ++i){
			int a, b, c;
			scanf(" %d %d %d", &a, &b, &c);	
			road[a][b]=road[b][a]=c;
			if(city<a) city=a;
			if(city<b) city=b;
		}
		
		long ans[10]={0};	
		
		//各街を根としてbfs
		for(int i=0; i<=city; ++i){
			long cost[10]; //その街までの最小コスト
			for(int j=0; j<=city; ++j) cost[j]=1000000000; //とりあえず大きいので初期化
			
			queue<int> que;
			cost[i]=0;
			que.push(i);
			while( !que.empty() ){
				int v=que.front();
				que.pop();
				for(int j=0; j<10; ++j){
					if(v==j) continue;
					
					if(road[v][j]>=0 && cost[v]+road[v][j]<cost[j]){
						cost[j]=cost[v]+road[v][j];
						que.push(j);	
					}	
				}	
			}	
			/*
			printf("city %d to:\n", i);
			for(int j=0; j<=city; ++j) printf(" %d is %ld\n", j, cost[j]);
			*/
			for(int j=0; j<=city; ++j) ans[i]+=cost[j];
		}
		
		int a=0;
		for(int i=1; i<=city; ++i)
			if(ans[a]>ans[i]) a=i;	
			
		printf("%d %ld\n", a, ans[a]);
	}
}