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 <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n;
    while(cin >> n, n){
        auto v = make_v(10, 10, INF<int>);
        for (int i = 0; i < 10; ++i) {
            v[i][i] = 0;
        }
        int mx = 0;
        for (int i = 0; i < n; ++i) {
            int a, b, c;
            scanf("%d %d %d", &a, &b, &c);
            chmin(v[a][b], c);
            chmin(v[b][a], c);
            chmax(mx, max(a, b)+1);
        }
        for (int k = 0; k < mx; ++k) {
            for (int i = 0; i < mx; ++i) {
                for (int j = 0; j < mx; ++j) {
                    chmin(v[i][j], v[i][k]+v[k][j]);
                }
            }
        }
        vector<int> s(mx, 0);
        for (int i = 0; i < mx; ++i) {
            for (int j = 0; j < mx; ++j) {
                s[i] += v[i][j];
            }
        }
        auto a = min_element(s.begin(),s.end());
        printf("%ld %d\n", a-s.begin(), *a);
    }

    return 0;
}

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

int main() {
	for (;;)
	{
		int edge[11][11];
		int city = 0;
		for (int i = 0;i < 11;i++) 
		{
			for (int j = 0;j < 11;j++)
			{
				if(i == j)
				{
					edge[i][i] = 0;
					continue;
				}
				edge[i][j] = INF;
			}
		}
		int n;
		cin >> n;
		if (n == 0) break;
		for (int i = 0;i < n;i++)
		{
			int a,b,c;
			cin >> a >> b >> c;
			edge[a][b] = c;
			edge[b][a] = c;
 			city = max (max(a,b)+1,city);
		}
		for (int i = 0;i < city;i++)
		{
			for (int j = 0;j < city;j++)
			{
				for (int k = 0;k < city;k++)
				{
					edge[i][k] = min(edge[i][k],edge[i][j]+edge[j][k]);
				}
			}
		}
		//??????????????§edge?????????????????¢?????\??£?????????(??????????????§?????????)
		int min = INF;
		int minCity;
		for (int i = 0;i < city;i++)
		{
			int sum = 0;
			for (int j = 0;j < city;j++)
			{
				if (i == j) continue;
				sum += edge[i][j];
			}
			if (sum < min)
			{
				min  = sum;
				minCity = i;
			}
		}
		cout << minCity << " " << min << endl;
	}
	return 0;
}

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

using namespace std;
static const int INF = 999999999;
struct SEdge
{
	unsigned long long int From;
	unsigned long long int To;
	unsigned long long int Cost;
};
unsigned long long int V;
vector<int> d;
vector<SEdge> Edge;

void Bellman_Ford(int s)
{
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	bool update = true;
	while(update)
	{
		update = false;
		int n = Edge.size();
		for(int i = 0; i < n; ++i)
		{
			SEdge e = Edge[i];
			if(d[e.From] != INF && d[e.To] > d[e.From] + e.Cost)
			{
				d[e.To] = d[e.From] + e.Cost;
				update = true;
			}
		}
	}
}

void solve()
{
	int E;
	while(cin >> E, E)
	{
		V = 0;
		Edge.clear();
		Edge.resize(2 * E);
		for(int i = 0; i < E; ++i)
		{
			unsigned long long int From, To, Cost;
			cin >> From >> To >> Cost;
			V = max(V, max(From, To));
			Edge[2 * i + 1].To = Edge[2 * i].From = From;
			Edge[2 * i + 1].From = Edge[2 * i].To = To;
			Edge[2 * i + 1].Cost = Edge[2 * i].Cost = Cost;
		}
		++V;
		d.clear();
		d.resize(V);
		unsigned long long int Min = INF;
		int pos = 0;
		for(int i = 0; i < V; ++i)
		{
			Bellman_Ford(i);
			unsigned long long int sum = 0;
			for(int j = 0; j < V; ++j)
			{
				sum += d[j];
			}
			if(Min > sum)
			{
				Min = sum;
				pos = i;
			}
		}
		cout << pos << " " << Min << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <cstdio>
#include <iostream>
#include <cstring>
#include <set>
#include <algorithm>
#define FOREVER for (;;)
#define FOR(i,a,b) \
for (int (i)=(a);(i)<(b);(i)++)
#define REP(i,a,b) \
for (int (i)=(a);(i)<=(b);(i)++)
#define log(exp) \
printf(#exp" = %d\n", exp)
#define INF 100000000
using namespace std;

const int maxn = 10+3;
int graph[maxn][maxn];
set<int> Set;

int main(void) {
    int N;
    while (cin>>N && N) {
        FOR(i,0, maxn) FOR(j, 0, maxn) graph[i][j] = INF;
        //?????´??°??? fill
        FOR(i,0,10) graph[i][i] = 0;
        
        REP(i,1,N) {//rep N ??????6
            int u,v,d;
            cin>>u>>v>>d;
            graph[u][v] = graph[v][u] = d;
            Set.insert(u);
            Set.insert(v);
        }
        
        FOR(k,0,10)
            FOR(i,0,10)
                FOR(j,0,10)
        graph[i][j] = min(graph[i][j], graph[i][k]+graph[k][j]);
        
        int ans = INF, ansNode = 0;
        set<int>::iterator it;
        for (it = Set.begin(); it!=Set.end(); it++) {
            int node = *it;
            int res = 0;
            set<int>::iterator anotherIt;
            for (anotherIt = Set.begin(); anotherIt!=Set.end(); anotherIt++)
                res+=graph[node][*anotherIt];
            if (res<ans) ans = res, ansNode = node;
        }
        
        printf("%d %d\n", ansNode, ans);
        //clear
        Set.clear();
    }
    
    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<<z<<" "<<a<<endl;
	}

	return 0;
}