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>
using namespace std;
const int INF = 1e+9;

int main(){
	int n;
	while( cin >> n , n ){
		int d[11][11], v=0, s[11]={0};
		
		for(int i=0 ; i < 11 ; i++ ){
			for(int j=0 ; j < 11 ; j++ ){
				d[i][j] = (i==j)? 0 : INF;
			}
		}
		for(int i=0 ; i < n ; i++ ){
			int a,b,c;
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
			v = max( max( v , a ) , b );
		}

		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 ans = INF;
		for(int i=0 ; i <= v ; i++ ){
			int cost = 0;
			for(int j=0 ; j <= v ; j++ ){
				cost += d[i][j];
			}
			s[i] = cost;
			ans = min( ans , cost );
		}
		for(int i=0 ; i <= v ; i++ ){
			if( s[i] == ans ){
				cout << i << " " << ans << endl;
				break;
			}
		}
	}
}

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

const int INF = 10000000;

int main(){
  
  while(1){
  
  int n;
  int d[11][11] = {0};
  int m=0;
  
  scanf("%d",&n);
  
  if(n == 0)break;
    for(int i = 0;i < 10;i++){
    for(int j = 0;j < 10;j++){
      if(i == j) continue;
      d[i][j] = INF;
    }
  }
  
  for(int i = 0;i < n;i++){
    int a,b,c;
    
    scanf("%d%d%d",&a,&b,&c);
    
    d[a][b] = c;
    d[b][a] = c;
    
    m = max(m,max(a,b));
    
  }
  
  m++;
  
  for(int i = 0;i < m;i++){
    for(int j = 0;j < m;j++){
      for(int k = 0;k < m;k++) d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
    }
  }
  int ans1=0,ans2=100000000;
  for(int i = 0;i < m;i++){
    int tmp = 0;
    for(int j = 0;j < m;j++){
      if(i == j)continue;
      tmp += d[i][j];
    }
    if(ans2 > tmp){
      ans2 = tmp;
      ans1 = i;
    }
  }
  
  
  printf("%d %d\n",ans1,ans2);
  }
  
  return 0;
}

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

int main() {
	int towns[10][10]; 
	int n;
	while (1) {
		cin >> n;
		if (!n)break;

		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				towns[i][j] = INF;
			}
		}
		for (int i = 0; i < 10; i++) {
			towns[i][i] = 0;
		}
		int biggest_town = 0;
		int a, b, c;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			if (biggest_town < a)biggest_town = a;
			if (biggest_town < b)biggest_town = b;
			towns[a][b] = c;
			towns[b][a] = c;
		}

		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					if (towns[i][j] > towns[i][k] + towns[k][j]) {
						towns[i][j] = towns[i][k] + towns[k][j];
					}
				}
			}
		}
		int start, total_time = 100000;
		for (int i = 0; i <= biggest_town; i++) {
			int tmp = 0;
			for (int j = 0; j <= biggest_town; j++) {
				if (towns[i][j] != 10000000)tmp += towns[i][j];
			}
			if (total_time > tmp) {
				total_time = tmp;
				start = i;
			}
		}
		cout << start << ' ' << total_time << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <stack>
#include <queue>

using namespace std;

#define INF 1000000000

int main(void)
{
    int n;

    while (cin >> n, n)
    {
        int road[45][45];

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                road[i][j] = INF;
            }
        }

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

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

        int min = INF;
        int min_p;
        for (int i = 0; i < n; i++)
        {
            int sum = 0;
            for (int j = 0; j < n; j++)
            {
                if (i != j && road[i][j] != INF)
                {
                    //cout << i << " " << j << " " << road[i][j] << endl;
                    sum += road[i][j];
                }
            }
            if (sum > 0 && sum < min)
            {
                min = sum;
                min_p = i;
            }
        }
        cout << min_p << " " << min << endl;
    }

    return 0;
}

C++: #include <limits.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <utility>

using namespace std;

int N;
int cost[10][10];

pair<int, int> getMinCost() {
  // Flood.
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = i + 1; j < N; ++j) {
        if (k == i || k == j) {
          continue;
        }
        if (cost[i][k] != -1 && cost[k][j] != -1) {
          int c = cost[i][k] + cost[k][j];
          if (cost[i][j] == -1 || cost[i][j] > c) {
            cost[i][j] = cost[j][i] = c;
          }
        }
      }
    }
  }
  int sum[10];
  for (int i = 0; i < N; ++i) {
    sum[i] = 0;
    for (int j = 0; j < N; ++j) {
      sum[i] += cost[i][j];
    }
  }
  pair<int, int> result;
  result.second = INT_MAX;
  for (int i = 0; i < N; ++i) {
    if (sum[i] < result.second) {
      result = make_pair(i, sum[i]);
    }
  }
  return result;
}

int main() {
  //freopen("ConvenientLocation.in", "r", stdin);
  int R;
  while (scanf("%d", &R) == 1 && R != 0) {
    N = 0;
    memset(cost, -1, sizeof(cost));
    for (int i = 0; i < 10; ++i) {
      cost[i][i] = 0;
    }
    int a, b, c;
    for (int i = 0; i < R; ++i) {
      scanf("%d%d%d", &a, &b, &c);
      N = max(N, max(a, b));
      if (cost[a][b] == -1 || cost[a][b] > c) {
        cost[a][b] = cost[b][a] = c;
      }
    }
    N++;
    pair<int, int> result = getMinCost();
    printf("%d %d\n", result.first, result.second);
  }
  return 0;
}