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 <cstdio>
#include <climits>
#include <algorithm>

using namespace std;

#define N 15
#define INF INT_MAX

int dp[N][N];

int n, ans_index, ans_length;

void solve(){
	for (int k = 0; k < n; k++){
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				if (dp[i][k] != INF && dp[k][j] != INF){
					dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
				}
			}
		}
	}

	ans_index = 0;
	ans_length = INF;
	
	for (int i = 0; i < n; i++){
		int sum = 0;
		for (int j = 0; j < n; j++){
			if (i == j) continue;
			sum += dp[i][j];
		}
		if (sum < ans_length){
			ans_index = i;
			ans_length = sum;
		}
	}
}

int main(){
	int t;
	while(true){
		scanf("%d", &t);
		if (t == 0) break;
		n = 0;
		
		fill((int*)dp, (int*)dp + N * N, INF);
		for (int i = 0; i < t; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			if (a > n) n = a;
			if (b > n) n = b;
			dp[a][b] = c;
			dp[b][a] = c;
		}
		n++;
		solve();
		printf("%d %d\n", ans_index, ans_length);
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

#define INF 1000000

int main(){
	while(1){
		int n,m=0;
		cin>>n;
		if(n==0)break;
		
		int cost[10][10]={0};
		rep(i,10)rep(j,10)cost[i][j]=INF;
		
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
			
			m=max(max(a,b),m);
		}
		
		
		int dp[10][10][10]={0};
		
		rep(i,10){
			rep(j,10){
				dp[0][i][j] = cost[i][j];
				dp[0][i][j] = min( dp[0][i][j],  cost[i][0] + cost[0][j]);
			}
		}
		
		reps(k,1,10){
			rep(i,10){
				rep(j,10){
					dp[k][i][j] = min(dp[k-1][i][j], dp[k-1][i][k] + dp[k-1][k][j]);
				}
			}
		}
		
		
		int maxp = -1;
		int maxsum = INF;
		
		rep(i,m+1){
			int ssum = 0;
			rep(j,m+1){
				if(i==j)continue;
				ssum += dp[9][i][j];
			}
			
			if(maxsum > ssum){
				maxsum = ssum;
				maxp = i;
			}
		}
		
		printf("%d %d\n",maxp,maxsum);
	}
}

C++: // 2016/06/16 AOJ0200:「Convenient Location」 Sae.I
#include <iostream>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n;		//道の数
		cin >> n;

		if(n==0)	//nが0なら
			break;

		int T[10][10];	//道の情報初期化
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;	//同じ町から町へは0
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;	//町の総数

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;	//a町からb町、b町からa町までの時間

			if(a+1>m){	
				m = a+1;
			}
			if(b+1>m){		
				m = b+1;
			}
		}

		//ワーシャルフロイド法
		int time[1000][1000];		//最短時間
		for(int i=0;i<m;i++){		//重み配列で初期化
			for(int j=0;j<m;j++){
				time[i][j]=T[i][j];
			}
		}
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(time[i][j]>time[i][k]+time[k][j]){	//時間
						time[i][j] = time[i][k]+time[k][j];
					}
				}
			}
		}

		int machi=0;
		int Time=0;
		int time2[1000];
		for(int i=0;i<m;i++){
			time2[i]=0;
		}
	
		for(int i=0;i<m;i++){
			time2[i]=0;
			for(int j=0;j<m;j++){
				time2[i]= time2[i]+time[i][j];
			}

			if(i!=0){
				if(time2[i]<time2[i-1]){
					Time=time2[i];
					machi=i;
				}
			}
			else{
				Time=time2[i];
				machi=i;
			}
		}


		cout << machi << " " << Time << '\n';


	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <functional>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define inf 0x3f7f7f7f

using namespace std;

int dp[11][11];

int main()
{
	int t, i, j, k, x, y, z, n, MIN, sum[11];
	while (scanf("%d", &t) && t)
	{
		for (i = n = 0; i < 11; i++)
			for (j = 0; j < 11; j++)
				dp[i][j] = inf;
		while (t--)
		{
			scanf("%d%d%d", &x, &y, &z);
			dp[x][y] = dp[y][x] = z;
			n = max(n, max(x + 1, y + 1));
		}
		for (k = 0; k < n; k++)
			for (i = 0; i < n; i++)
				for (j = 0; j < n; j++)
					dp[i][j] = min(dp[i][k] + dp[k][j], dp[i][j]);
		for (i = 0, MIN = 0; i < n; i++)
		{
			for (j = sum[i] = 0; j < n; j++)
				if (i != j)
					sum[i] += dp[i][j];
			if (sum[MIN] > sum[i])
				MIN = i;
		}
		printf("%d %d\n", MIN, sum[MIN]);
	}	
	return 0;
}

C++: #include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
const int INF = 100000000, mod = 1000000007;
using namespace std;

int n, maxcity = 0, d[12][12], sum[12], ans = INF;

int main() {
    cin >> n;
    for (int i = 0; i <= 11; i++) {
        for (int j = 0; j <= 11; j++) {
            if (i == j)d[i][j] = 0;
            else d[i][j] = INF;
        }
    }
    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
        maxcity = max(maxcity, b);
    }
    for (int k = 0; k <= maxcity; k++) {
        for (int i = 0; i <= maxcity; i++) {
            for (int j = 0; j <= maxcity; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    for (int i = 0; i <= maxcity; i++) {
        for (int j = 0; j <= maxcity; j++) {
            sum[i] += d[i][j];
        }
    }
    for (int i = 0; i <= maxcity; i++) ans = min(ans, sum[i]);
    cout << ans << endl;
    return 0;
}

C++: // AOJ 0189 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0189)
#include<cstdio>
#include<algorithm>
#include<numeric>
#include<limits>
#define rep(i,a) for(int i=0;i<(a);++i)

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

const int MAX_N = 10, INF = std::numeric_limits<int>::max()>>4;

int d[MAX_N][MAX_N];

int main()
{
	int n;
	while( scanf( "%d", &n ), n )
	{
		rep( i, MAX_N ) rep( j, MAX_N )
			d[i][j] = i==j?0:INF;

		rep( i, n )
		{
			int a, b, c;
			scanf( "%d%d%d", &a, &b, &c );
			d[a][b] = d[b][a] = c;
		}

		rep( k, MAX_N ) rep( i, MAX_N ) rep( j, MAX_N )
			d[i][j] = std::min( d[i][j], d[i][k]+d[k][j] );

		P ans( INF, INF );
		rep( i, MAX_N )
		{
			int s = 0;
			rep( j, MAX_N ) if( d[i][j] != INF )
				s += d[i][j];

			if( s )
				ans = std::min( ans, P( s, i ) );
		}

		printf( "%d %d\n", ans.second, ans.first );
	}

	return 0;
}