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 <cmath>
#define INF 100000000
using namespace std;

int main(){
	int d[10][10];
	int n;
	while(cin >> n,n){
		for(int i = 0;i < 10;i++){
			for(int j = 0;j < 10;j++){
				d[i][j] = INF;
			}
			d[i][i] = 0;
		}
		int num = 0;
		for(int i = 0;i < n;i++){
			int a,b,c;
			cin >> a >> b >> c;
			num = max(num,max(a,b));
			d[a][b] = c;
			d[b][a] = c;
		}
		num++;
		for(int k = 0;k < num;k++){
			for(int i = 0;i < num;i++){
				for(int j = 0;j < num;j++) d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
			}
		}
		int res = INF,minnum = -1;
		for(int i = 0;i < num;i++){
			int sum = 0;
			for(int j = 0;j < num;j++){
				sum += d[i][j];
			}
			if(sum < res){
				res = sum;
				minnum = i;
			}
		}
		cout << minnum << " " << res << endl;
	}
	return 0;
}

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

int main()
{
    int v, s, a, b, c, min_v;
    int d[10][10];
    
    while(cin >> s, s)
    {
        v = 1, min_v = 0;        
        for(int i = 0; i < 10; ++i)
            for(int j = 0; j < 10; ++j)
                if(i == j)  d[i][j] = 0;
                else        d[i][j] = 100000000;
        
        for(int i = 0; i < s; ++i)
        {
            cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
            v = max(a + 1, max(b + 1, v));
        }
        
        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]);
        
        for(int i = 0; i < v; ++i)
            for(int j = 1; j < v; ++j)
                d[i][0] += d[i][j];
        
        for(int i = 1; i < v; ++i)
            if(d[i][0] < d[min_v][0])
                min_v = i;
        
        cout << min_v << ' ' << d[min_v][0] << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

typedef long long int lli;
lli INF = 1000000LL;

int main() {

  array<array<lli, 10>, 10> table;
  
  while( true ){
	int n;
	cin >> n;
	if ( n == 0 ) break;

	for ( int i = 0; i < 10; i++ ) {
	  for ( int j = 0; j < 10; j++ ) {
		table[ i ][ j ] = INF;
	  }
	}
	
	int m = -1;
	for ( int i = 0; i < n; i++ ) {
	  int v1, v2, c;
	  cin >> v1 >> v2 >> c;
	  table[ v1 ][ v2 ] = c;
	  table[ v2 ][ v1 ] = c;
	  m = max( max( v1, v2 ), m );
	}
	for ( int i = 0; i < 10; i++ ) {
	  table[ i ][ i ] = 0LL;
	}

	for ( int k = 0; k <= m; k++ ) {
	  for ( int i = 0; i <= m; i++ ) {
		if ( table[ i ][ k ] >= INF ) continue;
		for ( int j = 0; j <= m; j++ ) {
		  if ( table[ i ][ j ] > table[ i ][ k ] + table[ k ][ j ] ) {
			table[ i ][ j ] = table[ i ][ k ] + table[ k ][ j ];
		  }
		}
	  }
	}
	lli ans = INF;
	int num = -1;
	for ( int i = 0; i <= m; i++ ) {
	  lli sum = 0;
	  for ( int j = 0; j <= m; j++ ) {
		sum += table[ i ][ j ]; 
	  }
	  if ( ans > sum ) {
		ans = sum;
		num = i;
	  }
	}
	cout << num << " " << ans << endl;
  }
}

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

int d[11][11];

void init(){
  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] = 1e9;
    }
  }
}

int main(void){
  int n;
  while(true){
    cin >> n;
    if(!n) break;
    int a, b, c, m = 0;
    init();

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

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

    int town, mincost = 1e9;

    for(int i = 0; i <= m; i++){
      int sum = 0;
      for(int j = 0; j <= m; j++){
        sum += d[i][j];
      }
      if(sum < mincost){
        town = i;
        mincost = sum;
      }
    }

    cout << town << " " << mincost << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>

const int inf = 99999;

using namespace std;

int main()
{
	int a[11][11], n, s, t, u, v;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		fill(&a[0][0], &a[10][10], inf);
		for(int i = 0; i < 11; i++){
			a[i][i] = 0;
		}
		v = 0;
		for(int i = 0; i < n; i++){
			cin >> s >> t >> u;
			a[s][t] = a[t][s] = u;
			if(v < s){
				v = s;
			}
			if(v < t){
				v = t;
			}
		}
		
		for(int k = 0; k <= v; k++){
			for(int i = 0; i <= v; i++){
				for(int j = 0; j <= v; j++){
					a[i][j] = (a[i][j] > a[i][k]+a[k][j])? a[i][k]+a[k][j] : a[i][j];
				}
			}
		}
		
		t = inf;
		for(int i = 0; i <= v; i++){
			s = 0;
			for(int j = 0; j <= v; j++){
				s += a[i][j];
			}
			if(t > s){
				t = s;
				u = i;
			}
		}
		cout << u << " " << t << endl;
	}
	
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#define INF 0x3f3f3f

int max(int x,int y){return x>y?x:y;} 
int min(int x,int y){return x<y?x:y;}
int d[110][110];
void floyd(int n){
	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]));
}
void into(int n){
	memset(d,INF,sizeof(d));
	for(int i=0;i<n;i++)
		d[i][i]=0;
}
int main(){
	int n,m;
	int a,b,k;
	while(~scanf("%d",&n),n){
		into(12);
		m=0;
		for(int i=0;i<n;i++){
			scanf("%d%d%d",&a,&b,&k);
			d[a][b]=d[b][a]=k;
			m=max(max(a,b),m);
		}
		floyd(m+1);
		int minn=INF;
		int kase;
		for(int i=0;i<=m;i++){
			int ans=0;
			for(int j=0;j<=m;j++) ans+=d[i][j]; 
			if(ans<minn){
				minn=ans;
				kase=i;
			}
			
		}
		printf("%d %d\n",kase,minn);
	}
	return 0;
}