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 <climits>
#include <vector>
#include <numeric>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

const int INF = INT_MAX / 2;

struct Edge{
	int from, to, cost;

	Edge( int f, int t, int c ) : from( f ), to( t ), cost( c )
	{
		return;
	}
};

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

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

		if ( !n )
		{
			break;
		}

		int V = 0;
		vector< Edge > E;

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

			V = max( V, max( f, t ) );

			E.push_back( Edge( f, t, c ) );
		}

		V++;

		VVI G( V, VI( V, INF ) );

		for ( int i = 0; i < V; i++ )
		{
			G[i][i] = 0;
		}

		for ( int i = 0; i < n; i++ )
		{
			Edge &e = E[i];

			G[ e.from ][ e.to ] = e.cost;
			G[ e.to ][ e.from ] = e.cost;
		}

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

		int num, res = INT_MAX;

		for ( int i = 0; i < V; i++ )
		{
			int sum = accumulate( G[i].begin(), G[i].end(), 0 );

			if ( sum < res )
			{
				num = i;
				res = sum;
			}
		}

		cout << num << ' ' << res << endl;
	}	

	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////
const int MAX_V = 10 , MAX_M = 45;
vector<vector<ll>> dp(MAX_V,vector<ll>(MAX_V,INF));
//d[[i][j]:i,j間の最短経路
int E,V=0; //頂点数

void wf(){
	rep(k,0,V)
		rep(i,0,V)
			rep(j,0,V)
				dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j] );
}

//入力
void make(){
	rep(i,0,E){
		int u,v,c;
		cin>>u>>v>>c;
		dp[u][v] = c;
		dp[v][u] = c;
		V = max(V,u+1);
		V = max(V,v+1);
	}
}

int main(){
	while( cin >> E ){
		if( !E )
			break;

		rep(i,0,MAX_V){
			rep(j,0,MAX_V){
				if( i == j ) dp[i][j] = 0;
				else dp[i][j] = INF;
			}
		}

		V = 0;
		make();
		wf();

		rep(i,0,V){
			rep(j,0,V){
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}

		ll ans = INF;
		int idx = 0;
		rep(i,0,V){
			ll sum = 0;
			rep(j,0,V){
				if( dp[i][j] != INF)
					sum += dp[i][j];
			}
			if( ans > sum ){
				ans = sum;
				idx = i;
			}
		}
		cout << idx << " " << ans << endl;
	}
	ret 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define INF 10000
#define MAXV 45

int dist[MAXV][MAXV];

int main(void){
	int n;

	while(1){
		int town=0;

		cin >> n;
		if(n==0)break;

		memset(dist,INF,sizeof(int)*MAXV*MAXV);
		for(int i=0; i<n; i++){
			int from,to,cost;
			cin >> from >> to >> cost;
			dist[from][to] = cost;
			dist[to][from] = cost;
			town = max(town,max(to,from));
		}
		town++;

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

		/*
		for(int i=0; i<town; i++){
			for(int j=0; j<town; j++){
				printf("%3d",dist[i][j]);
			}
			printf("\n");
		}
		*/
		
		int mincost=INF;
		int mintown;
		for(int i=0; i<town; i++){
			int cost=0;
			for(int j=0; j<town; j++)
				cost += dist[i][j];
			if(mincost>cost){
				mincost = cost;
				mintown = i;
			}
		}

		cout << mintown << " " << mincost << endl;
	}

	return 0;
}

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

using namespace std;


int main(){

    long long n;
    vector< vector<long long> > map(100,vector<long long>(100));
    long long a,b,c;
    vector<long long> v(100);
    fill(v.begin(),v.end(),1<<20);
    while(true){
	fill(map.begin(),map.end(),v);
	cin >> n;
	long long ma=0;
	if(n == 0) break;
	for(long long i=0;i<n;i++){
	    cin >> a >> b >> c;
	    map[a][b] = c;
	    map[b][a] = c;
	    ma = max(ma,b);
	}
	for(long long i=0;i<ma;i++){
	    map[i][i] = 0;
	}
	ma++;
	for(long long i=0;i<ma;i++){
	    for(long long j=0;j<ma;j++){
		for(long long k=0;k<ma;k++){
			map[i][j] = min(map[i][j] ,map[i][k] + map[k][j] );
		}
	    }
	}

	long long res = 1<<30,t=0;
	for(long long i=0;i<ma;i++){
	    a =0;
	    for(long long j=0;j<ma;j++){
		a += map[i][j];
	    }
	    if(a!=0 && res>a){
		res = a;
		t = i;
	    }
	}
	cout << t<<" " << res << endl;
    }
    
    return 0;
}

C++: #include<cstdio>
#include<algorithm>
#define N 11
#define inf 10000000
using namespace std;
int d[N][N],V;
void warshall_floyd(void)
{
	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]);
		}
	}
	return ;
}
void init(void)
{
	for(int i=0;i<N;i++)
	fill(d[i],d[i]+N,inf);
	for(int i=0;i<N;i++)
	d[i][i]=0;
	return ;
}
int main(void)
{
	int n;
	while(scanf("%d",&n)==1)
	{
		if(n==0)
		break;
		init();
		int s,e,c;
		V=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",&s,&e,&c);
			d[s][e]=d[e][s]=c;
			V=max(V,max(s,e));
		}
		warshall_floyd();
		int ans=inf;
		int sum=0;
		int id=0;
		for(int i=0;i<=V;i++)
		{
			sum=0;
			for(int j=0;j<=V;j++)
			sum+=d[i][j];
			if(sum<ans)
			{
				ans=sum;
				id=i;
			}
		}
		printf("%d %d\n",id,ans);
	}
	return 0;
}