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 <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;
const int MAX_E = 45;
const int MAX_V = 10;
const int INF = 1024 * 1024 * 1024;
struct edge {int to, cost; };
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);
        }

        int dps[max_v + 1];
        for(int i = 0; i <= max_v; i++) {
            int d[max_v + 1] = {0};
            for(int k = 0; k <= max_v; k++) {
                d[k] = INF;
            }
            priority_queue<pair<int, int>> que;
            d[i] = 0;
            que.push(pair<int, int>(0, i));
            while(!que.empty()) {
                pair<int, int> p = que.top();
                que.pop();
                if(p.first > d[p.second]) continue;
                for(int j = 0; j < G[p.second].size(); j++) {
                    edge e1 = G[p.second][j];
                    if(d[e1.to] > d[p.second] + e1.cost) {
                        d[e1.to] = min(d[e1.to], d[p.second] + e1.cost);
                        que.push(pair<int, int>(d[e1.to], e1.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 <queue>
#include <vector>
#include <utility>
#define INF 10000000
using namespace std;
typedef pair<int,int> p;
struct edge{
  int to,cost;
};
vector<edge> V[10];
int d[10];

void dijkstra(int s) {
  priority_queue< p,vector<p>,greater<p> > que;
  for(int i=0;i<10;i++) {
    d[i] = INF;
  }
  d[s] = 0;
  que.push(p(0,s));

  while(!que.empty()) {
    p v = que.top();que.pop();
    int x = v.second;
    if(d[x] < v.first) continue;
    for(unsigned int i=0;i<V[x].size();i++) {
      edge e = V[x][i];
      if(d[e.to] > d[x] + e.cost) {
	d[e.to] = d[x] + e.cost;
	que.push(p(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int n,sum=0;

  while(cin >> n) {
    if(n == 0) break;
    for(int i=0;i<10;i++) {
      V[i].clear();
    }
    for(int i=0;i<n;i++) {
      int a,b,c;
      edge es;
      cin >> a >> b >> c;
      es.to = b;
      es.cost = c;
      V[a].push_back(es);
      es.to = a;
      V[b].push_back(es);
    }
    int top = INF,topnum = 0;
    for(int i=0;i<10;i++) {
      dijkstra(i);
      for(int j=0;j<10;j++) {
	if(d[j] != INF) {
	  sum += d[j];
	}
      }
   
      if(sum != 0 && sum < top) {
	top = sum;
	topnum = i;
      }
      sum = 0;
    }
    cout << topnum << " " << top << endl;
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, a, b, c, dp[111][111], eki, an[3], ans;
	while (1) {
		eki = 0;
		cin >> n;
		if (n == 0) {
			goto a;
		}
		for (int i = 0; i <= 11; i++) {
			for (int z = 0; z <= 11; z++) {
				dp[i][z] = 999;
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> a >> b >> c;
			dp[a][b] = c;
			dp[b][a] = c;
			eki = max(eki, max(a, b));
		}
		for (int i = 0; i <= eki; i++) {
			dp[i][i] = 0;
		}
		for (int i = 0; i <= eki; i++) {
			for (int z = 0; z <= eki; z++) {
				for (int m = 0; m <= eki; m++) {
					dp[i][z] = min(dp[i][z], dp[i][m] + dp[m][z]);
				}
			}
		}
		ans = 0;
		an[2] = 9999999;
		for (int i = eki; i >= 0; i--) {
			ans = 0;
			for (int z = 0; z <= eki; z++) {
					ans += dp[i][z];
			}
			if (an[2] >= ans) {
				an[2] = ans;
				an[1] = i;
			}
		}
		cout << an[1] << " " << an[2] << endl;
	}
a:;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXC 12
int N,dis[MAXC][MAXC];
int main()
{
	int m;
	while(~scanf("%d",&N)&&N)
	{
		for(int i=0;i<=9;i++)
			for(int j=0;j<=9;j++)
				if(i==j)
					dis[i][j]=0;
				else
					dis[i][j]=0x3FFFFFFF;
		m=0;
		for(int i=1,a,b,c;i<=N;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			m=max(m,max(a,b));
			dis[a][b]=dis[b][a]=c;
		}
		for(int k=0;k<=m;k++)
			for(int i=0;i<=m;i++)
				for(int j=0;j<=m;j++)
					dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
		int mn=0x3FFFFFFF,id,sum;
		for(int i=0;i<=m;i++)
		{
			sum=0;
			for(int j=0;j<=m;j++)
				sum+=dis[i][j];
			if(mn>sum)
			{mn=sum;id=i;}
		}
		printf("%d %d\n",id,mn);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 15, INF = 0x3f3f3f3f;
int a[N][N], n, m;
int main() {
    // freopen("in.txt", "r", stdin);
    int x, y, w;
    while(scanf("%d", &m) && m) {
        n = 0;
        for(int i = 0; i < N; i++)
            for(int j = 0; j < N; j++)
                if(i == j)  a[i][j] = 0;
                else    a[i][j] = INF;
        for(int i = 0; i < m; i++) {
            scanf("%d %d %d", &x, &y, &w);
            n = max({x, y, n});
            a[x][y] = a[y][x] = min(a[x][y],w);
        }
        for(int k = 0; k <= n; k++)
            for(int i = 0; i <= n; i++)
                for(int j = 0; j <= n; j++)
                    if(a[i][j] > a[i][k] + a[k][j])
                        a[i][j] = a[i][k] + a[k][j];
        ll ans = INF, pos;
        for(int i = 0; i <= n; i++) {
            ll sum = 0;
            for(int j = 0; j <= n; j++)
                sum += a[i][j];
            if(sum < ans) {
                ans = sum;
                pos = i;
            }
        }
        printf("%lld %lld\n", pos, ans);
    }
    return 0;
}