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 <algorithm>
#include <string.h>
#define INF 100000000
using namespace std;
int d[1000][1000];
int V; 


void warshall_floyd(){
  for(int i = 0 ; i <= V ; i++ )d[i][i] = 0;

  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;
  while( cin >> n,n){
     V = 0;
    for(int i = 0 ; i < 1000 ; i++){
      for(int j = 0 ; j < 1000 ; j++){
	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;
      if(a > V )V = a;
      if(b > V )V = b;
    }

    warshall_floyd();

    int ans = INF,ansi;
    for(int i = 0 ; i <= V ; i++){
      int sum = 0;
      for(int j = 0 ; j <= V ; j++){
	sum+=d[i][j];
      }
	if(sum < ans){
	  ans = sum;
	  ansi = i;
	}
    }
    cout << ansi << " " << ans << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
const int INF = 1e6;
int main(void){
  int n;
  int cost[10][10];
  while(cin>>n){
    if(n==0) break;
    REP(i,10)REP(j,10) cost[i][j] = INF;
    REP(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      cost[a][b] = cost[b][a] = c;
    }
    REP(k,10)REP(i,10)REP(j,10)cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
    int ans = INF;
    int ansi;
    REP(i,10){
      int tmp=0;
      REP(j,10)tmp+=(cost[i][j]!=INF&&i!=j)?cost[i][j]:0;
      if(tmp!=0&&ans>tmp){
        ans = tmp;
        ansi = i;
      }
    }
    cout<<ansi<<" "<<ans<<endl;
  }

  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;
}

C++: /*
* Desciption:  Desciption
* Created:    2016-02-21
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<memory.h>
using namespace std;
const int maxn=15,INF=100000;
int dp[maxn][maxn];
int n,t,a,b,c,temp,ans,ai;
int main()
{
	while (scanf("%d",&t)&&t)
	{
		n=0;
		for (int i = 0; i < maxn; i += 1)fill(dp[i],dp[i]+maxn,INF);
		for (int i = 0; i < maxn; i += 1)dp[i][i]=0;
		for (int i = 0; i < t; i += 1)
		{
			scanf("%d",&a);
			scanf("%d",&b);
			scanf("%d",&c);
			dp[a][b]=dp[b][a]=c;
			if(a>n)n=a;
			if(b>n)n=b;
		}
		ans=INF;
		for (int k = 0; k <= n; k += 1)
		{
			for (int i = 0; i <= n; i += 1)
			{
				for (int j = 0; j <= n; j += 1)
				{
					dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
				}
			}
		}
		ans=INF;
		for (int i = 0; i <= n; i += 1)
		{
			temp=0;
			for (int j = 0; j <= n; j += 1)
			{
				if(i==j)continue;
				temp+=dp[i][j];
			}
			if(temp<ans){
				ai=i;
				ans=temp;
			}
		}
		printf("%d %d\n",ai,ans);
		
	}
	return 0;
}

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

using namespace std;

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

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		
		
		int dp[111][111]={0};
		rep(i,111)rep(j,111)dp[i][j]=1000000000;
		
		
		int m=0;
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			dp[a][b]=min(c,dp[a][b]);
			dp[b][a]=min(c,dp[a][b]);
			
			m=max(m,max(a,b));
		}
		m++;
		rep(i,111)dp[i][i]=0;
		
		
		rep(k,m){
			rep(i,m){
				rep(j,m){
					dp[i][j] = min(dp[i][k]+dp[k][j],dp[i][j]);
				}
			}
		}
		
		rep(i,m){
			rep(j,m){
				printf("%d ",dp[i][j]);
			}puts("");
		}
		
		
		int ans=1000000000;
		int minp=-1;
		rep(i,m){
			int sum=0;
			rep(j,m){
				sum+=dp[i][j];
			}
			if(ans>sum){
				minp=i;
				ans = sum;
			}
		}
		printf("%d %d\n",minp,ans);
	}
}

C++: // 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(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;
				}
				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;

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

    for(int k=0;k<m;k++){
      for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
          if(T[i][j] > T[i][k]+T[k][j])
            T[i][j] = T[i][k] + T[k][j];
        }
      }
    }
    int min_town_n;
    int min_town_time = INF;
    for(int k=0;k<m;k++){
      int sub = 0;
      for(int i=0;i<m;i++){
        if(T[k][i] != INF)
          sub += T[k][i];
          cout << T[k][i] << ",";
      }
      cout << " sub = " << sub << endl;
      if(min_town_time > sub){
        min_town_time = sub;
        min_town_n = k;
      }
    }
    cout << min_town_n << ' ' << min_town_time << endl;
	}

	return 0;
}