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 <bits/stdc++.h>

using namespace std;

int main(){
	while (true){
		int array[10][10], a, b, c, i, j, k, m = 0, n, ans_map = 0, ans_cost = 1 << 25;
		scanf("%d", &n);
		if (!n){
			return 0;
		}
		for (i = 0; i < 10; i++){
			for (j = 0; j < 10; j++){
				if (i == j){
					array[i][j] = 0;
				}
				else{
					array[i][j] = 1 << 25;
				}
			}
		}
		for (i = 0; i < n; i++){
			scanf("%d %d %d", &a, &b, &c);
			array[a][b] = array[b][a] = c;
			m = max(m, b);
		}
		m++;
		for (i = 0; i < m; i++){
			for (j = 0; j < m; j++){
				for (k = 0; k < m; k++){
					array[j][k] = array[k][j] = min(array[j][k], array[j][i] + array[i][k]);
				}
			}
		}
		for (i = 0; i < m; i++){
			int cost = 0;
			for (j = 0; j < m; j++){
				cost += array[i][j];
			}
			if (cost < ans_cost){
				ans_cost = cost;
				ans_map = i;
			}
		}
		printf("%d %d\n", ans_map, ans_cost);
	}
}

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

const int INF = 1 << 29;

typedef std::pair<int, int> P;

int n;

int main()
{
	while( std::cin >> n, n )
	{
		int d[10][10], v = 0;

		for( int i = 0; i != 10; ++i )
			for( int j = 0; j != 10; ++j )
				d[i][j] = i == j ? 0 : INF;

		for( int i = 0; i != n; ++i )
		{
			int a, b, c;
			std::cin >> a >> b >> c;
			d[a][b] = d[b][a] = c;
			v = std::max( v, std::max( a, b ) );
		}

		for( int k = 0; k <= v; ++k )
			for( int i = 0; i <= v; ++i )
				for( int j = 0; j <= v; ++j )
					d[i][j] = std::min( d[i][j], d[i][k] + d[k][j] );
	
		P ans( INF, INF );
		for( int i = 0; i <= v; ++i )
		{
			P sum( 0, i );
			for( int j = 0; j <= v; ++j )
				sum.first += d[i][j];

			ans = std::min( ans, sum );
		}

		std::cout << ans.second << ' ' << ans.first << std::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;
}

C++: #include<iostream>
using namespace std;
#define MAX_VAL 100
#define INF 12345678

int d[MAX_VAL][MAX_VAL];
int V = 0;

void warshall_floyd(){
	for(int k = 0; k < V; k++)
		for(int i = 0; i < V; i++)
			for(int j = 0; j < V; j++) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
}

int main(){
	int n, m, f, t, cost;
	
	while(true){
		int ans = INF, num = 0;
		cin>>n;
		
		if(!n) break;
	
	
		for(int i = 0; i < 10; i++)
			for(int j = 0; j < 10; j++)if(i==j)d[i][j]=INF;else d[i][j]=INF;
	
	
		V = 0;
	
		for(int i = 1; i <= n; i++){
			cin>>f>>t>>cost;
			d[f][t] = d[t][f] = cost;
			d[f][f] = d[t][t] = 0;
			V = max(V,max(f,t));
		}
		V++;
	
		warshall_floyd();
		
		for(int i = 0; i < V; i++){
			int sum = 0;
			for(int j = 0; j < V; j++){
				sum += d[i][j];
			}
			if(ans > sum){
				ans = sum;
				num = i;
			}
		}
		cout<<num<<" "<<ans<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

#define INF INFINITY

int N;
float dat[10][10];
int a,b,c,M;

int main(){
    while(scanf("%d",&N),N){
        memset(dat,0,sizeof(dat));
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                if(i!=j)dat[i][j]=INF;
            }
        }
        M=0;
        for(int i=0;i<N;i++){
            scanf("%d%d%d",&a,&b,&c);
            dat[a][b]=dat[b][a]=c;
            M=max(M,max(a,b)+1);
        }
        for(int k=0;k<10;k++){
            for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                    dat[i][j]=min(dat[i][j],dat[i][k]+dat[k][j]);
                }
            }
        }
        int S;float T=INF;
        for(int s=0;s<M;s++){
            float t=0;
            for(int i=0;i<M;i++){
                t+=dat[s][i];
            }
            if(T>t){
                S=s;
                T=t;
            }
        }
        printf("%d %d\n",S,(int)T);
    }
}

C++: #include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007

using namespace std;
#define ll long long
#define dbg if(0)

int main(){
    ll n;
    do{
        cin >>n;
        if (n==0)break;
        int mtown=0;
        ll g[10][10];
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                g[i][j]=INT_MAX;
            }
                g[i][i]=0;
        }
        for(int i=0;i<n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            mtown=max(a,max(mtown,b));
            g[a][b]=c;
            g[b][a]=c;
        }
        for(int k=0;k<10;k++){
            for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                    g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
                }
            }
        }
        dbg{
            for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                    cout <<g[i][j]<<" ";
                }
                cout <<endl;
            }
        }
        ll ans=INT_MAX;
        ll ansid=11;
        for(int i=0;i<=mtown;i++){
            ll cand=0;
            for(int j=0;j<=mtown;j++){
                if (g[i][j]==INT_MAX)break;
                cand+=g[i][j];
            }
            if(ans>=cand){
                if (cand==ans){
                    ansid=min((ll)i,ansid);
                }else{
                    ans=cand;
                    ansid=i;
                }
            }
        }
        cout <<ansid<<" "<<ans<<endl;
    }while(1);

    return 0;
}