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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:>
 ?????????============================================================
 
 =================================================================
 
 ?§£??¬=============================================================
 
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    ll G[10][10];
    bool used[10];
    while(cin >> n){
        if(n==0) break;
        for(int i = 0; i < 10;i++)for(int j = 0;j < 10;j++) G[i][j] = INF;
        for(int i = 0; i < 10;i++) used[i] = false;
        for(int i = 0; i < n;i++){
            ll a,b,c; cin >> a >> b >> c;
            G[a][b] = min(G[a][b],c);
            G[b][a] = min(G[b][a],c);
            used[a] = used[b] = true;
        }
        for(int i = 0; i < 10;i++){
            for(int j = 0;j <10;j++){
                for(int k = 0;k < 10;k++){
                    G[i][j] = min(G[i][j],G[i][k]+G[k][j]);
                }
            }
        }
        ll id = -1,sum = INF;
        for(int i = 0; i < 10;i++){
            if(used[i] == false)continue;
            ll tmp = 0;
            for(int j = 0; j < 10;j++){
                if(i == j)continue;
                if(used[j] == false)continue;
                tmp += G[i][j];
            }
            if(tmp < sum){
                sum = tmp;
                id = i;
            }
        }
        cout << id << " " << sum << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;

const int MAX_V = 100, INF = 999999;
static int cost[MAX_V][MAX_V];
static int d[MAX_V];

bool used[MAX_V];
static int V;
int E;
void dijkstra(int s) {
	fill(d, d + V, INF);
	fill(used, used + V, false);
	d[s] = 0;

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

		for (int u = 0; u < V; u++) {
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
}

int main() {
	while (1) {
		memset(cost, 999999, sizeof(cost));
		cin >> E;
		if (E == 0) break;
		int v_max = -1;
		for (int i=0 ; i < E; i++) {
			int u, v, cos;
			cin >> u >> v >> cos;
			cost[u][v] = cos;
			cost[v][u] = cos;
			if (v > v_max)v_max = v;
		}
		V = v_max + 1;
		int sum_m = 999999, m_ind = -1;
		for (int i = 0; i < V; i++) {
			dijkstra(i);
			int sum = 0;
			for (int j = 0; j < V; j++) {
				sum += d[j];
			}
			if (sum < sum_m) {
				sum_m = sum;
				m_ind = i;
			}
		}

		cout << m_ind << " " << sum_m << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>

const int TOWN = 10;
const int PATH = 45;
const int INF = 100000000;

using namespace std;

int main() {
	int n;
	int a, b;

	while (cin >> n , n) {
		int num_of_town = 0;
		int g[TOWN][TOWN] = {};
		for (int i = 0; i < TOWN; i++) {
			for (int j = 0; j < TOWN; j++) {
				g[i][j] = 0;
			}
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			cin >> g[a][b];
			g[b][a] = g[a][b];
			num_of_town = max(num_of_town, max(a, b));
		}
		num_of_town++;
		//	cout << "num_of_town = " << num_of_town << "\n";

		int d[TOWN][TOWN];
		for (int i = 0; i < num_of_town; i++) {
			for (int j = 0; j < num_of_town; j++) {
				if (i == j)			d[i][j] = 0;
				else if (g[i][j] != 0) d[i][j] = g[i][j];
				else				d[i][j] = INF;
			}
		}

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

		//cout << "\n";
		//for (int i = 0; i < num_of_town; i++) {
		//	for (int j = 0; j < num_of_town; j++) {
		//		cout << i << " " << j << " " <<  d[i][j] << "\n";
		//	}
		//}
		//cout << "\n";

		int ans_d = INF;
		int ans_t;
		int tmp = 0;
		for (int i = 0; i < num_of_town; i++) {
			for (int j = 0; j < num_of_town; j++) {
				tmp += d[i][j];
			}
			if (ans_d > tmp) {
				ans_d = tmp;
				ans_t = i;
			}
			tmp = 0;
		}
		cout << ans_t << " " << ans_d << "\n";
	}
	
 	return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
int d[10][10];
int V;
void wf()
{
	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()
{
	int n;
	cin>>n;
	while(n){
		int ans=0x3f3f3f3f;
		V=0;
		memset(d,0x3f,sizeof(d));
		for(int i=0;i<n;i++){
			int u,v,cost;
			cin>>u>>v>>cost;
			d[u][v]=cost;
			d[v][u]=cost;
			V=max(V,u);
			V=max(V,v);
		}
		for(int i=0;i<=V;i++){
			d[i][i]=0;
		}
		wf();
		int ff=-1;
		for(int i=0;i<=V;i++){
			int temp=0;
			for(int j=0;j<=V;j++){
				temp+=d[i][j];
			}
			ans=min(temp,ans);
			if(ans==temp)
				ff=i;
		}
		cout<<ff<<" "<<ans<<endl;
		cin>>n;
	}
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>
using namespace std;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
#define _CRT_SECURE_NO_WARNINGS
int N,V=0;
int m[10][10];
int ans = 100000;
int town = 0;
int tmp = 0;
int main() {
	while (true)
	{
		V = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				m[i][j] = 10000;
			}
		}
		scanf("%d", &N);
		if (N==0) {
			break;
		}
		for (int i = 0; i < N; i++) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			m[a][b] = m[b][a] = c;
			V = max(V, max(a, b));
		}

		for (int i = 0; i <= V; i++) {
			for (int j = 0; j <= V; j++) {
				for (int k = 0; k <= V; k++) {
					m[j][i]=m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
				}
			}
		}
		ans = 100000;
		tmp = 0;
		for (int i = 0; i <= V; i++) {
			for (int j = 0; j <= V; j++) {
				if (i != j) {
					tmp += m[i][j];
				}
			}
			if (ans > tmp) {
				ans = tmp;
				tmp = 0;
				town = i;
			}
		}
		printf("%d %d\n", town, ans);
	}
	return 0;
}