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<math.h>
#include<algorithm>
#include<ctype.h>
#include<stdlib.h>
#include<queue>
#include<vector>
#include<string.h>
using namespace std;
#define oo 0x3f3f3f3f
#define maxn 1010

int maps[maxn][maxn];
int dis[maxn];
int vis[maxn];
int m;

void Init(int n)
{
    for(int i=0;i<=n+2;i++)
    {
        for(int j=0;j<=n+2;j++)
        {
            if(i==j)
                maps[i][j]=0;
            else
                maps[i][j]=oo;
        }
    }
}

int dij(int pos)
{
    int Min;
    int s=pos;
    for(int i=0;i<=m;i++)
        {
            dis[i]=maps[pos][i];

            vis[i]=0;
        }

    vis[pos]=1;
    for(int i=0;i<m;i++)
    {
        Min=oo;
        for(int j=0;j<=m;j++)
        {
            if(!vis[j] && Min>dis[j])
            {
                Min=dis[j];
                pos=j;
            }
        }

        vis[pos]=1;
        for(int j=0;j<=m;j++)
        {
            if(!vis[j] && dis[j] > Min+maps[pos][j])
                dis[j]=Min+maps[pos][j];
        }
    }
    int sum=0;
    for(int i=0;i<=m;i++)
        sum+=dis[i];
    return sum;

}

int main()
{
    int n;
    while(~scanf("%d",&n),n)
    {
        Init(n);
        int a,b,c;
        m=-1;
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            maps[a][b]=maps[b][a]=min(c,maps[a][b]);
            m=max(max(a,b),m);
        }
        int ans=oo,k=0;
        for(int i=0;i<=m;i++)
        {
            int q=dij(i);

            if(q<ans)
            {
                ans=q;
                k=i;
            }
        }
        printf("%d %d\n",k,ans);
    }
    return 0;
}

C++: #include <iostream>
#include <utility>
#include <climits>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
void solve(int n){
	long dp[10][10],ans=INT_MAX,ans2;
	rep(i,10) rep(j,10) dp[i][j]=INT_MAX;

	rep(i,n){
		int f,t,l;
		cin>>f>>t>>l;
		dp[f][t]=l;dp[t][f]=l;
		dp[i][i]=0;
	}

	rep(k,10) rep(i,10) rep(j,10) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
	int numofnINF=0;

	rep(i,10) if(dp[0][i]!=INT_MAX) numofnINF++;

	rep(i,10){
		long acc=0;
		rep(j,numofnINF) acc+=dp[i][j];
		if(ans>acc){ans=acc;ans2=i;}
	}
	cout<<ans2<<' '<<ans<<endl;
	return;
}

int main(){
	int c;
	cin>>c;
	while(c){
		solve(c);
		cin>>c;
	}
	return 0;
}

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

using namespace std;

int d[10][10];

int main()
{
	for(;;){
		int n, t_cont = 0, best_t = -1;
		int from, to, cost, cont = 0;
		int Min = 1000000000;
		bool isUsed[11] = {0};
		
		
		//INFツづ渉可甘コツ可サ
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				d[i][j] = 100000;
				if(i == j){
					d[i][j] = d[j][i] = 0;
				}
			}
		}
		
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> from >> to >> cost;
			d[from][to] = d[to][from] = cost;
			isUsed[from] = 1;
			isUsed[to] = 1;
		}
		
		for(int i = 0; i < 11; i++){
			if(isUsed[i] == 1){
				t_cont++;
			}
		}
		
	//	cout << t_cont << endl;
		
		//ツδ渉ーツシツδδδ仰づ猟ャツつキ
		
		for(int k = 0; k < t_cont; k++){
			for(int i = 0; i < t_cont; i++){
				for(int j = 0; j < t_cont; j++){
					d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
				}
			}
		}
		/*
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				printf("%d   ",d[i][j]);
			}
			cout << endl;
		}
		*/
		//ツ全ツ閉板個ゥツづゥ
		for(int i = 0; i < t_cont; i++){
			for(int j = 0; j < t_cont; j++){
				cont += d[i][j];
			}
			if(cont < Min){
				Min = cont;
				best_t = i;
			}
			cont = 0;
		}
		
		cout << best_t << " " << Min << endl;
	}
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

#define INF 1000000000

long long edges[20][20];
long long dist[20][20];

int ids[10];
int nids;

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N==0)break;

        memset(edges,0,sizeof(edges));

        nids = 0;

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            int ix=-1;
            int iy=-1;

            for(int l=0;l<nids;++l){
                if(ids[l]==x) ix = l;
                if(ids[l]==y) iy = l;
            }

            if(ix<0){ ix = nids; ids[nids++]=x; }
            if(iy<0){ iy = nids; ids[nids++]=y; }

            edges[ix][iy] = edges[iy][ix] = c;

        }

        for(int i=0;i<nids;++i)
            for(int j=0;j<nids;++j){
                if(i==j)
                    dist[i][j]=0;
                else if(edges[i][j]==0)
                    dist[i][j]=INF;
                else
                    dist[i][j]=edges[i][j];
            }

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

        int ans  = 0;
        long long msum = INF;

        for(int i=0;i<nids;++i){

            long long sum = 0;
            for(int j=0;j<nids;++j){

                if(dist[i][j]==INF)continue;
                sum += dist[i][j];
            }

            if(sum<msum){
                ans  = i;
                msum = sum;
            }

        }

        cout << ids[ans] << " " << msum << endl;


    }

    return 0;

}

C++: #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#define MAX_V 10
#define INF 1000000
#define NIL -1
using namespace std;

struct edge {int to,cost;};
typedef pair<int,int> P;	//first:最短距離 second:頂点番号


int d[MAX_V];

void dijkstra(int s,vector<edge> G[]){
	//greater<P>を指定することでfirstが小さい順に取り出せるようになる
	priority_queue<P,vector<P>,greater<P>> que;
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()){
		P 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(P(d[e.to],e.to));
			}
		}
	}
	
}

int E;
bool cities[MAX_V];//その番号の町が出てくるか否か

int main(){
	cin >>E;
	while(E != 0){
		vector<edge> G[MAX_V];		//隣接リスト
		fill(cities,cities + MAX_V,false);
		int a,b,cost;
		for(int i = 0;i < E;i++){
			cin >>a >>b >>cost;
			cities[a] = true;cities[b] = true;
			edge e;e.to = b;e.cost = cost;
			G[a].push_back(e);
			e.to = a;
			G[b].push_back(e);
		}
		int mini = INF;int num = NIL;
		for(int i = 0;i < MAX_V;i++){
			fill(d,d+MAX_V,INF);
			for(int j = 0;j < MAX_V;j++){
				if(!cities[j])d[j] = 0;}
			dijkstra(i,G);
			int min_tmp= 0;
			for(int k = 0;k < MAX_V;k++)min_tmp += d[k];
			if(min_tmp < mini){mini = min_tmp;num = i;}
		}
		cout <<num <<" " <<mini <<endl;
		cin >>E;
	}
	return 0;
}