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 <map>
using namespace std;
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x>y?y:x)
#define INF 1000000
typedef long long ll;
typedef map<ll,int> M;

ll cost[15][15];

int main()
{
	int n;
	ll sum;
	int max=0;
	M d;
	while(cin>>n,n){
		max=0;

		for(int i=0;i<15;i++){
			for(int j=0;j<15;j++){
				cost[i][j]=(i==j?0:INF);
			}
		}
		
		for(int i=0;i<n;++i){
			int a,b;
			ll c;
			cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
			if(max<MAX(a,b))max=MAX(a,b);

		}
		
		for(int i=0;i<=max;i++){
			for(int j=0;j<=max;j++){
				for(int k=0;k<=max;k++){
					cost[i][j]=MIN(cost[i][j],cost[i][k]+cost[k][j]);
				}
			}
		}
		
		for(int i=0;i<=max;i++){
			sum=0;
			for(int j=0;j<=max;j++){
				sum+=cost[i][j];
			}
			d[sum]=i;
		}
		M::iterator it=d.begin();
		cout<<(*it).second<<" "<<(*it).first<<endl;
		d.clear();
	}
	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;
		
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			dp[a][b]=c;
			dp[b][a]=c;
		}
		rep(i,111)dp[i][i]=0;
		
		rep(k,n){
			rep(i,n){
				rep(j,n){
					dp[i][j] = min(dp[i][k]+dp[k][j],dp[i][j]);
				}
			}
		}
		
		
		int ans=1000000000;
		rep(i,n){
			int sum=0;
			rep(j,m){
				sum+=dp[i][j];
			}
			ans = min(ans,sum);
		}
		printf("%d\n",ans);
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <cstring> 
using namespace std;
const int N=10,INF=0x3f3f3f3f;
int n,d[N][N],c,x,y,m;
int main(){
    while(~scanf("%d",&m),m){
        memset(d,INF,sizeof(d)); n=0;
        while(m--){
            scanf("%d%d%d",&x,&y,&c);
            d[x][y]=d[y][x]=c;
            n=max(n,max(x,y));
        }
        for(int k=0;k<=n;k++)
            for(int i=0;i<=n;i++)
                for(int j=0;j<=n;j++)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        int ans=INF,pos=0;
        for(int i=0;i<=n;i++){
            int tmp=0;
            for(int j=0;j<=n;j++)if(i!=j)tmp+=d[i][j];
            if(tmp<ans)ans=tmp,pos=i;
        }printf("%d %d\n",pos,ans);
    }return 0;
}

C++: #include <cstdio>
#include <algorithm>
#define INF 1000000

int edge[10][10];
int n;
bool isexist[10];

int calc(int city){
	int cost[10];
	std::fill_n(cost, 10, INF);
	cost[city]=0;

	while(true){
		bool update=false;
		for(int i=0;i<10;i++){
			if(!isexist[i]) break;
			for(int j=0;j<10;j++){
				if(!isexist[j]) break;
				if(cost[i]+edge[i][j]<cost[j]){
					cost[j]=cost[i]+edge[i][j];
					update=true;
				}
			}
		}
		if(!update) break;
	}
	int sum=0;
	for(int i=0;i<10;i++){
		if(isexist[i]) sum+=cost[i];
	}
	return sum;
}

void solve(){
	int min_city;
	int min_cost=INF;
	for(int i=0;i<10;i++){
		if(isexist[i]){
			int cost=calc(i);
			if(min_cost>cost){
				min_city=i;
				min_cost=cost;
			}
		}
	}
	std::printf("%d %d\n",min_city+1,min_cost);
	return;
}

int main(){
	while(std::scanf("%d",&n),n){
		for(int i=0;i<10;i++){
			isexist[i]=false;
			for(int j=0;j<10;j++){
				edge[i][j]=INF;
			}
		}
		for(int i=0;i<n;i++){
			int a,b,c;
			std::scanf("%d %d %d",&a,&b,&c);
			edge[a][b]=c;
			edge[b][a]=c;
			isexist[a]=true;
			isexist[b]=true;
		}
		solve();
	}

	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
const lnt INF = 0xffffffffffffff;
lnt d[10][10];
lnt x,y,z;
lnt used[10];
int main()
{while(1){
	lnt n;
	cin>>n;
	if(!n) return 0;
	fill(d[0],d[10]+10,INF);
	fill(used,used+10,0);
	for(lnt i=0;i<n;i++){
		cin>>x>>y>>z;
		used[x]=1;
		used[y]=1;
		d[x][y]=z;
		d[y][x]=z;
	}
	for(lnt i=0;i<10;i++){
		if(used[i]) d[i][i]=0;
	}
	for(lnt k=0;k<10;k++){
		for(lnt i=0;i<10;i++){
			for(lnt j=0;j<10;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	P ans=P(-1,INF);
	lnt sum;
	for(lnt i=0;i<10;i++){
		if(!used[i]) continue;
		sum=0;
		for(lnt j=0;j<10;j++){
			if(!used[j]) continue;
			sum+=d[i][j];
		}
		if(ans.second>sum){
			ans.first=i;
			ans.second=sum;
		}
	}
	cout<<ans.first<<' '<<ans.second<<endl;
}}

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

#define INF (1 << 29)
typedef long long ll;
int main(){
  int n;
  ll cost[11][11], town[11];
  int from, to, t;
  while(cin >> n, n){
    for(int i = 0 ; i < 11 ; i++){
      town[i] = 0;
      for(int j = 0 ; j < 11 ; j++){
	cost[i][j] = INF;
	if(i == j) cost[i][j] = 0;
      }
    }

    int min_town=11, max_town=0;
    
    while(n--){
      cin >> from >> to >> t;
      min_town = min(min_town, min(from, to));
      max_town = max(max_town, max(from, to));
      cost[from][to] = t;
      cost[to][from] = t;
    }

    for(int k = min_town ; k <= max_town ; k++){
      for(int i = min_town ; i <= max_town ; i++){
	for(int j = min_town ; j <= max_town ; j++){
	  cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
	}
      }
    }
	
    ll min_t = INF;
    for(int i = min_town ; i <= max_town ; i++){
      for(int j = min_town ; j <= max_town ; j++){
	town[i] += cost[i][j];
      }
      min_t = min(min_t, town[i]);
    }
  
    for(int i = min_town ; i <= max_town ; i++){
      if(town[i] == min_t){
	cout << i << ' ' << min_t << endl;
	break;
      }
    }
  }
  return 0;
}

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

#define INF (1<<29)

int graph[11][11];

void wa(int m){

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

int main(){
  int m,n,a,b,c;
  
  while(scanf("%d",&n),n!=0){
    
    m=0;
    fill_n(*graph,11*11,INF);
    
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&a,&b,&c);
      graph[a][b]=c;
      graph[b][a]=c;
      m = max(m,max(a,b));
    }
    
    for(int i=0;i<=m;i++) graph[i][i]=0;
    wa(m);
    
    int num,sum,ans=INF;
    for(int i=0;i<=m;i++){
      sum=0;
      for(int j=0;j<=m;j++) sum = graph[i][j]==INF?INF:sum+graph[i][j];
      if(sum < ans){
	num = i;
	ans = sum;
      }
    }
    printf("%d %d\n",num,ans);
  }
  return(0);
}