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<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(int l = 0;l<2;l++){
	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 <bits/stdc++.h>
using namespace std;

const int INF = 10000000;
const int MAX_V = 11;

int d[MAX_V][MAX_V];
int V;

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 m;
  while ( cin >> m,m ) {
  for ( int i = 0; i < 51; i++ ) {
    for ( int j = 0; j < 51; j++ ) {
      if ( i == j ) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }

  int a,b,c;
  int maxn = 0;
  for ( int i = 0; i < m; i++ ) {
    cin >> a >> b >> c;
    maxn = max(maxn,max(a,b));
    d[a][b] = d[b][a] = c;
  }
  V = maxn + 1;
  warshall_floyd();


  int mincost = INF;
  int num;
  for ( int i = 0; i <= maxn; i++ ) {
    int total = 0;    
    for ( int j = 0; j <= maxn; j++ ) {
      if ( i != j ) {
	total += d[i][j];
      }
    }
    if ( mincost > total ) {
      mincost = total;
      num = i;
    }
  }
  cout << num << " " << mincost << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int edges[20][20];
int dist[20][20];

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N==0)break;

        int m = 0;

        memset(edges,0,sizeof(edges));

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            edges[x][y] = edges[y][x] = c;

            m = max(m,max(x,y));

        }

        for(int i=0;i<=m;++i)
            for(int j=0;j<=m;++j){
                if(i==j)
                    dist[i][j]=0;
                else if(edges[i][j]==0)
                    dist[i][j]=100000000;
                else
                    dist[i][j]=edges[i][j];
            }

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

        int ans  = 0;
        int msum = 10000000;

        for(int i=0;i<=m;++i){

            int sum = 0;
            for(int j=0;j<=m;++j){

                if(dist[i][j]==100000000)continue;
                sum += dist[i][j];
            }

            if(sum<msum){
                ans  = i;
                msum = sum;
            }

        }

        cout << ans << " " << msum << endl;


    }

    return 0;

}

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

#define N 10
#define INF 1000000
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)

int main() {
	int n, cost[N][N], ans, num, sum, m=0, a, b, c;
	while(1) {
		cin >> n;
		if(!n) break;
		for(int i=0; i<N; ++i) for(int j=0; j<N; ++j) {
			cost[i][j] = (i==j?0:INF);
		}
		m = 0;
		for(int i=0; i<n; ++i) {
			cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
			m = max(a, b);
		}
		for(int k=0; k<=m; ++k) {
			for(int i=0; i<=m; ++i) {
				for(int j=0; j<=m; ++j) {
					cost[i][j]= min(cost[i][j], cost[i][k]+cost[k][j]);
				}
			}
		}
		ans = INF; num = -1;
		for(int i=0; i<=m; ++i) {
			sum = 0;
			for(int j=0; j<=m; ++j) {
				sum += cost[i][j];
			}
			if(ans>sum) {
				num = i;
				ans = sum;
			}
		}
		cout << num << " " << ans << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int x[11][11];
int main()
{
    int n;
    while(~scanf("%d",&n)&&n)
    {
        int a,b,c;
        memset(x,0x3f,sizeof(x));
        for(int i=0;i<=n;i++)
            for(int j=0;j<=n;j++)
            if(i==j)
            x[i][j]=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            x[a][b]=x[b][a]=c;
        }
        for(int i=0;i<=n;i++)
            for(int j=0;j<=n;j++)
            for(int k=0;k<=n;k++)
            if(x[i][j]>x[i][k]+x[k][j])
            x[i][j]=x[i][k]+x[k][j];
//            for(int i=0;i<=n;i++)
//            {
//                for(int j=0;j<=n;j++)
//                    printf("%d ",x[i][j]);
//                printf("\n");
//            }
            int Min=0x3f3f3f3f,flag=0,sum=0;
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            {
                if(x[i][j]!=0x3f3f3f3f)
                sum+=x[i][j];
            }
                if(sum<Min)
                {
                    Min=sum;
                    flag=i;
                    sum=0;
                }
        }
        printf("%d %d\n",flag,Min);
    }
}

C++: #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 x[m];
		for(int i=0;i<m;i++)
			x[i]=0;
		
		int city,num;
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				x[i]=x[i]+T[i][j];
			}
			if(num>x[i]||i==0){
				num=x[i];
				city=i;
			}
		}
		
		cout<<city<<' '<<num<<endl;
		
	}


	return 0;
}