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<queue>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define MAX_N	50
#define INF		100000000


struct edge
{
	int from , to , cost;
};

struct P
{
	int from , to;
};

edge input[MAX_N];


long long int dp[MAX_N][MAX_N];



int n;


int main(void)
{
	while (cin >> n && n != 0){

		int map_max = 0;

		long long int min = 999999999999;
		int index = 0;

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				dp[i][j] = INF;
			}
		}

		for (int i = 0; i < n; i++){
			cin >> input[i].from >> input[i].to >> input[i].cost;
		
			dp[input[i].from][input[i].to] = input[i].cost;
			dp[input[i].to][input[i].from] = input[i].cost;

			map_max = std::max(map_max , std::max(input[i].from , input[i].to));
		}

		

		for (int i = 0; i <= map_max; i++){
			dp[i][i] = 0;
			for (int j = 0; j <= map_max; j++){
				for (int k = 0; k <= map_max; k++){
					dp[j][k] = std::min(dp[j][k] , dp[j][i] + dp[i][k]);
				}
			}
		}

		for (int i = 0; i <= map_max; i++){
			long long int now = 0;
			for (int j = 0; j <= map_max; j++){
				now += dp[i][j];
			}

			if (now < min){
				min = now;
				index = i;
			}
		}

		cout << index << " " << min << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;
const int MAX_E = 45;
const int MAX_V = 10;
const int INF = INT32_MAX;
struct edge {int to, cost; };
typedef pair<int, int> P;
vector<edge> G[MAX_V];
vector<string> result;

int main() {
    int n;
    while(1) {
        cin >> n;
        if (n == 0) break;
        int max_v = -1;
        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            edge e, e1;
            e.to = to;
            e.cost = cost;
            G[from].push_back(e);
            e1.to = from;
            e1.cost = cost;
            G[to].push_back(e1);
            max_v = max(max(max_v, from), to);
        }
        max_v++;

        int dps[max_v];
        for(int i = 0; i < max_v; i++) {
            int d[max_v];
            fill(d, d + max_v, INF);
            priority_queue<P, vector<P>, greater<P>> que;
            d[i] = 0;
            que.push(P(0, i));
            while(!que.empty()) {
                P p = que.top();
                que.pop();
                int v = p.second;
                if(p.first > d[v]) continue;
                for(int j = 0; j < G[v].size(); j++) {
                    edge e = G[v][j];
                    if(d[e.to] > d[v] + e.cost) {
                        d[e.to] = d[v] + e.cost;
                        que.push(P(d[e.to], e.to));
                    }
                }
            }


            int sum = 0;
            for(int j = 0; j < max_v; j++) {
                sum += d[j];
            }

            dps[i] = sum;
        }

        int min_i = 0;
        for(int i = 1; i < max_v; i++) {
            if(dps[min_i] > dps[i]) {
                min_i = i;
            }
        }

        result.push_back(to_string(min_i) + " " + to_string(dps[min_i]));
    }

    for(int i = 0; i < result.size(); i++) {
        cout << result[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#define INF 100000000
typedef long long int lli;
using namespace std;

struct edge{int from1,to1,from2,to2,cost;};
int shortest_path(int s,int V,int E,vector<int> d,vector<edge> es){
	int result=0;
	for(int i=0; i<V; ++i) d[i]=INF;
	d[s]=0;
	while(true){
		bool update = false;
		for(int i=0; i<E; ++i){
			edge e=es[i];
			if(d[e.from1]!=INF&&d[e.to1]>d[e.from1]+e.cost){
				d[e.to1]=d[e.from1]+e.cost;
				update=true;
			}
			if(d[e.from2]!=INF&&d[e.to2]>d[e.from2]+e.cost){
				d[e.to2]=d[e.from2]+e.cost;
				update=true;
			}
		}
		if(!update) break;
	}
	for(int i=0; i<V; ++i){
		result+=d[i];
	}
	return result;
}

int main(){
	int n;
	while(cin>>n&&n){
		vector<edge> es(n);
		int m=0;
		for(int i=0; i<n; ++i){
			int a,b,c;
			cin >> a >> b >> c;
			m=max(a,max(b,m));
			es[i].from1=a;
			es[i].to1=b;
			es[i].from2=b;
			es[i].to2=a;
			es[i].cost=c;
		}
		vector<int> d(m+1);
		int ans_d=INF;
		int ans_s;
		for(int i=m; i>=0; --i){
			int tmp=shortest_path(i,m+1,n,d,es);
			//cout << tmp << "\n";
			if(ans_d>=tmp){
				ans_d=tmp;
				ans_s=i;
			}
		}
		cout << ans_s << " " << ans_d << "\n";
	}
	return 0;
}

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

#define INF 100000
int mat[10][10];
int tn;

int main(){
	int n, a, b, c;
	while (cin >> n && n != 0) {
		tn = 0;
		for (int i = 0; i < 10; i++) {
			fill(mat[i], mat[i] + n, INF);
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			mat[a][b] = mat[b][a] = c;
			tn = max(tn, max(a, b));
		}
		for (int i = 0; i <= tn; i++) {
			mat[i][i] = 0;
		}
		for (int k = 0; k <= tn; k++) {
			for (int i = 0; i <= tn; i++) {
				for (int j = 0; j <= tn; j++) {
					if (mat[i][j] > mat[i][k] + mat[k][j]) {
						mat[i][j] = mat[i][k] + mat[k][j];
					}
				}
			}
		}
		int l = 0, sum, ans = INF;
		for (int i = 0; i <= tn; i++) {
			sum = 0;
			for (int j = 0; j <= tn; j++) {
				sum += mat[i][j];
			}
			if (ans > sum) {
				ans = sum;
				l = i;
			}
		}
		cout << l << " " << ans << endl;
	}

	return 0;
}