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>
using namespace std;
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x>y?y:x)
#define INF 1000000000
typedef long long ll;
typedef pair<int,ll> P;

ll cost[15][15];

int main()
{
	int n,max;
	ll sum,min;
	vector<P> vec;
	P min_p;

	while(cin>>n,n){
		min=INF;
		max=0;
		vec.clear();
		
		for(int i=0;i<15;i++){
			for(int j=0;j<15;j++){
				cost[i][j]=(i==j?0:INF);
			}
		}
		
		for(int i=0;i<n;++i){
			int a,b;
			ll c;
			cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
			if(max<MAX(a,b))max=MAX(a,b);

		}
		
		for(int i=0;i<=max;i++){
			for(int j=0;j<=max;j++){
				for(int k=0;k<=max;k++){
					cost[i][j]=MIN(cost[i][j],cost[i][k]+cost[k][j]);
				}
			}
		}
		
		for(int i=0;i<=max;i++){
			sum=0;
			for(int j=0;j<=max;j++){
				sum+=cost[i][j];
			}
			vec.push_back(P(i,sum));
		}

		for(vector<P>::iterator it=vec.begin();it!=vec.end();++it){
			if(min>(*it).second){
				min=(*it).second;
				min_p=*it;
			}
		}
		cout<<min_p.first<<" "<<min_p.second<<endl;
	}
	return 0;
}

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

int n, m; // 道の数，街の数
int edges[10][10];

int dijkstra(int from, int to) {
    bool visited[m];
    fill(visited, visited + m, false);
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
    que.push(make_pair(0, from));
    visited[0] = true;
    while (!que.empty()) {
        pair<int, int> current = que.top();
        que.pop();
        
        const int dist = current.first;
        const int pos = current.second;
        
        if (pos == to) {
            return dist;
        }
        
        for (int i = 0; i < m; i++) {
            if (!visited[i] && edges[pos][i] != 0x7f7f7f7f) {
                visited[i] = true;
                que.push(make_pair(dist + edges[pos][i], i));
            }
        }
    }
    return -1;
}

int main() {
    while (cin >> n, n) {
        memset(edges, 0x7f, sizeof(edges));
        
        for (int i = 0; i < n; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            edges[a][b] = edges[b][a] = c;
            m = max(a, max(b, m));
        }
        m++;
        
        int res, res_time = 0x7fffffff;
        for (int i = 0; i < m; i++) {
            int total = 0;
            for (int j = 0; j < m; j++) {
                total += dijkstra(i, j);
            }
            if (total < res_time) {
                res_time = total;
                res = i;
            }
        }
        
        cout << res << ' ' << res_time << endl;
    }
    
    return 0;
}x

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

int main(void){
	const int INF = INT_MAX/4;
	int machi, miti;
	int time[10][10];

	while(true){
		// init
		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;
			}
		}

		cin >> miti;
		if( miti==0 )
			break;
		machi = 0;
		for(int i=0; i<miti; i++){
			int from, to, t;
			cin >> from >> to >> t;
		
			machi = max(from, machi);
			machi = max(to, machi);
		
			time[from][to] = t;
			time[to][from] = t;
		}
		machi++;


		for(int k=0; k<machi; k++){
			for(int i=0; i<machi; i++){
				for(int j=0; j<machi; j++){
					time[i][j] = min(time[i][j], time[i][k]+time[k][j]);
				}
			}
		}

		int maxTime = INF, maxMachi = -1;
		for(int i=0; i<machi; i++){
			int temp = 0;
			for(int j=0; j<machi; j++)
				temp += time[i][j];
			if( temp < maxTime ){	
				maxTime = temp;
				maxMachi = i;
			}
		}

		cout << maxMachi << " " << maxTime << endl;
	}

	return 0;
}

C++: #include <iostream>
#define INFINITY 1000000
int main (){
    int minArr[50],minIndexArr[50];
    int count = 0;
    while (1)
    {
            
        int n = 0,m = 0;
        std::cin >> n;
        if(n == 0)break;

        int table[100][100];
        for (size_t i = 0; i < 100; i++)
        {
            for (size_t j = 0; j < 100; j++)
            {
                if(i==j){
                    table[i][j] = 0;
                }else{
                    table[i][j] = INFINITY;
                }
            }
            
        }
        
        for (size_t i = 0; i < n; i++)
        {
            int a,b,c;
            std::cin >> a >> b >> c;
            m = std::max(m,std::max(a+1,b+1));
            table[a][b] = c;
            table[b][a] = c;

        }

        for (size_t i = 0; i < m; i++)
        {
            for (size_t j = 0; j < m; j++)
            { 
                for (size_t k = 0; k < m; k++)
                {
                    table[i][j] = std::min(table[i][k] + table[k][j], table[i][j]);
                }
            }
        }
    
        int sum[100];
        for (size_t i = 0; i < m; i++)
        {
            for (size_t j = 0; j < m; j++)
            {
                sum[i] = 0; 
            }
        }
        for (size_t i = 0; i < m; i++)
        {
            for (size_t j = 0; j < m; j++)
            {
                sum[i] += table[i][j]; 
            }
        }
        int min = INFINITY,minIndex = 0;
        for (size_t i = 0; i < m; i++)
        {
            if(min>sum[i]){
                min = sum[i];
                minIndex = i;
            }
        }
        
        minIndexArr[count] = minIndex;
        minArr[count] = min;
        count++;
    }
    for (size_t i = 0; i < count; i++)
    {
        std::cout << minIndexArr[i] << " " << minArr[i] << std::endl;
    }
    
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

#define INF 999999

int n;
int d[10][10];
int a, b, c;

signed main()
{
	while (true)
	{
		cin >> n;
		if (n == 0) break;

		rep(i,10) rep(j,10) d[i][j] = INF;

		int machi_kazu = 0;
		rep(i,n)
		{
			cin >> a >> b >> c;
			if (machi_kazu < a) machi_kazu = a;
			if (machi_kazu < b) machi_kazu = b;
			d[a][b] = c;
			d[b][a] = c;
		}

		rep(i,10) d[i][i] = 0;

		rep(k,10) rep(i,10) rep(j,10) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

		/*
		rep(i,10)
		{
			rep(j,10)
			{
				printf("% 3d ", d[i][j]);
			}
			printf("\n");
		}
		*/

		int machi_ans = 0;
		int ans_min_souwa = INF;
		for (int i=0; i<=machi_kazu; i++)
		{
			int souwa = 0;
			for (int j=0; j<=machi_kazu; j++)
			{
				souwa += d[i][j];
			}

			if (souwa < ans_min_souwa)
			{
				machi_ans = i;
				ans_min_souwa = souwa;
			}
		}

		printf("%d %d\n", machi_ans, ans_min_souwa);
	}
}