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>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int map[10][10];
		int m = 0;
		for(int i = 0 ;i < 10; i++){
			for(int j = 0; j < 10; j++){
				if(i == j) map[i][j] = 0;
				else map[i][j] = 10000000;
			}
		}
		for(int i = 0 ; i< n; i++){
			int a,b,c;
			cin >> a >> b >> c;
			m = max(max(a,b),m);
			map[a][b] = map[b][a] = c;
		}
		for(int k = 0; k <= m; k++){
			for(int i = 0; i <= m; i++){
				for(int j = 0; j <= m; j++){
					map[i][j] = min(map[i][j],map[i][k]+map[k][j]);
				}
			}
		}
		int ans[10] = {};
		for(int i = 0 ; i<=m; i++)for(int j = 0 ; j <= m; j++)ans[i] += map[i][j];
		int a = m;
		for(int i = 0; i <= m; i++){
			if(ans[i] < ans[a]) a = i;
		}
		cout << a << " " << ans[a] << endl;
	}
}

C++: #include <queue>
#include <vector>
#include <stdio.h>
using namespace std;

const int INF = 1e8;
struct edge{int to, cost;};
typedef pair<int, int> pii;
const int MAX_N = 50;
const int MAX_V = 15;
int n, V;
//ある街から出ている道
vector<edge> G[MAX_V];
int d[MAX_V];

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

void solve(){
    int ans = INF, num;
    int vmax = 0;
    int from, to, cost;
    for(int i=0; i<n; i++){
        scanf("%d%d%d", &from, &to, &cost);
        G[from].push_back(edge{to, cost});
        G[to].push_back(edge{from, cost});
        vmax = max(vmax, max(from, to));
    }
    V = vmax+1;
    for(int i=0; i<V; i++){
        int tmp;
        if ((tmp = dijkstra(i)) < ans){
            ans = tmp;
            num = i;
        }
    }
    printf("%d %d\n", num, ans);
}

int main(){
    while(scanf("%d", &n), n)
        solve();
    return 0;
}

C++: #include<stdio.h>
#include<vector>
#include<algorithm>
#define MAX 10005
#define inf 1000000
using namespace std;
int N,M,n,m;
int d[105],cost[105][105],pre[105];
bool used[105];
vector<int>a;
void dijkstra(int s)
{
	for(int i=0;i<=m;i++)
	{
		d[i]=inf;
		used[i]=false;
	}
	d[s]=0;
	while(true)
	{
		int v=-1;
		for(int u=0;u<=m;u++)
		{
			if(!used[u]&&(v==-1||d[u]<d[v]))
			v=u;
		}
		if(v==-1)
		break;
		used[v]=true;
		for(int u=0;u<=m;u++)	
		{
			if(d[u]>d[v]+cost[v][u])
			d[u]=d[v]+cost[v][u];
		}
	}
	return ;
}
int main(void)
{
	int s,e,t;
	while(scanf("%d",&n)==1)
	{
		if(n==0)
		break;
		for(int i=0;i<=n;i++)
        {
        	for(int j=0;j<=i;j++)
        	{
        		if(i==j)
        		cost[i][j]=0;
        		else
        		cost[i][j]=cost[j][i]=inf;
			}
        }
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",&s,&e,&t);
			m=max(s,e);
			cost[e][s]=cost[s][e]=t;
		}
		int id=0;
		int ans=inf;
		for(int i=0;i<=m;i++)
		{
			int sum=0;
			dijkstra(i);
			for(int j=0;j<=m;j++)
			sum+=d[j];
			if(sum<ans)
			{
				ans=sum;
				id=i;
			}
		}
		printf("%d %d\n",id,ans);
	}
	return 0;
}