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 <queue>
#include <stdlib.h>
#define INF 123456789
using namespace std;
typedef pair<int,int> P;//first:???????????¢/second:????????????
int main() {
// AOJ0189 Dijkstra
	for (;;)
	{
		struct edge {int to,cost;};
		int city = 0;//?????¨???????????????????°????(0~7?????§????????????city == 8??§??????)
		int n;
		cin >> n;
		vector<edge> es[11];
		if (n == 0) break;
		for (int i = 0;i < n;i++)
		{
			int a,b,c;
			cin >> a >> b >> c;
			es[a].push_back(edge{b,c});
			es[b].push_back(edge{a,c});//????????¨???
 			city = max (max(a,b)+1,city);
		}
		int min = INF;
		int mincity;
		for (int target_city = 0;target_city < city;target_city++)
		{
			//target_city?????????????°???????????¨??????????????????????
			int d[city];
			priority_queue <P,vector<P>,greater<P> > que;
			for (int i = 0;i < city;i++)
			{
				d[i] = INF;
			}
			d[target_city] = 0;
			que.push(P(0,target_city));
			while(!que.empty())
			{
				P pp = que.top();
				que.pop();
				if(d[pp.second] < pp.first) continue;
				d[pp.second] = pp.first;
				for (int i = 0;i < es[pp.second].size();i++)
				{
					//?????????????????????????????????????????????
					if (es[pp.second][i].cost + pp.first < d[es[pp.second][i].to])
					{
						d[es[pp.second][i].to] = es[pp.second][i].cost + pp.first;
						que.push(P(d[es[pp.second][i].to],es[pp.second][i].to));
					}
				}
			}
			int sum = 0;
			for (int i = 0;i < city;i++)
			{
				sum += d[i];
			}
			if (sum < min)
			{
				min = sum;
				mincity = target_city;
			}
		}
		cout << mincity << " " << min << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
static const int MAX = 10;
static const int INFTY = 1000000;
int V;
int d[MAX][MAX];


void floyd() {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            if (d[i][k] == INFTY) continue;
            for (int j = 0; j < V; j++) {
                if (d[k][j] == INFTY) continue;
                d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int sum, minv=INFTY, mini;
    for (int i = 0; i < V; i++) {
        sum = 0;
        for (int j = 0; j < V; j++) sum += d[i][j];
        if (sum < minv) { minv = sum, mini = i; }
    }
    printf("%d %d\n", mini, minv);
}



int main() {
    int E, source, target, cost;
    for(; ;) {
        std::scanf("%d", &E);
        if (E == 0) break;
        for (int i = 0; i < 10; i++) fill(d[i], d[i]+10, INFTY);
        V = 0;
        for (int i = 0; i < E; i++) {
            std::scanf("%d %d %d", &source, &target, &cost);
            d[source][target] = d[target][source] = cost;
            V = max(V, max(source, target));
        }
        V++;
        for (int i = 0; i < V; i++) d[i][i] = 0;
        floyd();
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 10000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
struct edge{int to,cost;};
int N;
int d[10];
bool f[10];
vector<edge> G[10];
void dijkstra(int s){
      REP(i,N)d[i]=INT_MAX;
      d[s]=0;
      priority_queue<P,vector<P>,greater<P> > Q;
      Q.push(P(0,s));
      while(!Q.empty()){
            P p=Q.top();Q.pop();
            int v=p.second;
            if(d[v]>p.first)continue;
            REP(i,G[v].size()){
                  edge e=G[v][i];
                  if(d[e.to]>d[v]+e.cost){
                        d[e.to]=d[v]+e.cost;
                        Q.push(P(d[e.to],e.to));
                  }
            }
      }
}
int main(){
      while(cin>>N&&N){
            memset(f,false,sizeof(f));
            REP(i,N){
                  int a,b,c;
                  cin>>a>>b>>c;
                  G[a].PB((edge){b,c});
                  G[b].PB((edge){a,c});
                  f[a]=f[b]=true;
            }
            ll ans=INT_MAX,pos=-1;
            REP(i,10){
                  if(!f[i])continue;
                  int sum=0;
                  dijkstra(i);
                  REP(j,10)if(f[j])sum+=d[j];
                  if(ans>sum){
                        ans=sum;
                        pos=i;
                  }
            }
            cout<<pos<<" "<<ans<<endl;
      }
}