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 <cstring>
using namespace std;

#define min(a,b) ((a<b) ? a : b)

int cost[10][10];

/*
void showPath(int n)
{
    int i,j;
    cout << "------------------------" << endl;
    for (i = 0 ; i <= n ; i++) {
        cout << cost[i][0];
        for (j = 1 ; j <= n ; j++) {
            cout << ", " << cost[i][j];
        }
        cout << endl;
    }
    cout << "------------------------" << endl;
}
*/

void calcPath(int n)
{
    int s,i,j,k,d;

    for (s = 0 ; s < 45 ; s++) {
        for (i = 0 ; i <= n ; i++) {
            for (j = 0 ; j <= n ; j++) {
                d = cost[i][j];
                for (k = 0 ; k <= n ; k++) {
                    if ( (cost[i][k] < 0) || (cost[k][j] < 0) ) continue;
                    d = (d >= 0) ? min(d,cost[i][k]+cost[k][j]) : cost[i][k]+cost[k][j];
                }
                cost[i][j] = d;
            }
        }
    }
}

// ----------------------------------------------------------------
int main(void)
{
    int i,j,len, minpath,n, townA, townB, t, townLast, bestTownNo;

    while(cin >> n) {
        if (n <= 0) break;
        // Initialize variables
        memset(cost,-1,sizeof(cost));
        townLast = -1;
        // read & set data
        for (i = 0 ; i < n ; i++) {
            cin >> townA;
            cin >> townB;
            cin >> t;  // time A->B
            cost[townA][townA] = 0;
            cost[townB][townB] = 0;
            cost[townA][townB] = t;
            cost[townB][townA] = t;
            if (townA > townLast) townLast = townA;
            if (townB > townLast) townLast = townB;
        }
        // calculate minimum path
//        showPath(townLast);
        calcPath(townLast);
//        showPath(townLast);
        // find best solution
        bestTownNo = -1;
        minpath = -1;
        for (i = 0 ; i <= townLast ; i++) {
            len = 0;
            for (j = 0 ; j <= townLast ; j++) {
                if(cost[i][j] > 0) len += cost[i][j];
            }
            if ((minpath < 0) || (len < minpath)) {
                minpath = len;
                bestTownNo = i;
            }
        }
        cout << bestTownNo << " " << minpath << endl;
    }

    return 0;
}

C++: #include<stdio.h>
#define MAX 0x0fffffff

int map[15][15];
int maxi;

int main()
{
    int n,i,j,k;
    int maxx,temp;
    scanf("%d",&n);
    while(n)
    {
        maxi=0;
        for(i=0;i<15;i++)
        {
            for(j=0;j<15;j++)
            {
                map[i][j]=(i!=j)*MAX;
            }
        }

        for(temp=0;temp<n;temp++)
        {
            scanf("%d%d%d",&i,&j,&k);
            if(i>maxi)
                maxi=i;
            if(j>maxi)
                maxi=j;
            map[i][j]=map[j][i]=k;
        }
        for(k=0;i<=maxi;i++)
        {
            for(i=0;j<=maxi;j++)
            {
                for(j=0;k<=maxi;k++)
                {
                    if(map[i][j]>map[i][k]+map[k][j])
                        map[i][j]=map[i][k]+map[k][j];
                }
            }
        }
        for(i=0;i<=maxi;i++)
        {
            for(j=1;j<=maxi;j++)
            {
                map[i][0]+=map[i][j];
            }
        }
        for(i=0,maxx=MAX;i<=maxi;i++)
        {
            if(map[i][0]<maxx)
            {
                maxx=map[i][0];
                temp=i;
            }
        }
        printf("%d %d\n",temp,maxx);
        scanf("%d",&n);
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
const int INF = 1 << 20;
const int N = 11;
int tim[N][N];
using namespace std;
int main()
{
	int a, b, ti, n;
	while (1){
		cin >> n;
		if (n == 0)break;

		for (int i = 0; i < N; i++){
			for (int i2 = 0; i2 < N; i2++){
				if (i != i2){
					tim[i][i2] = INF;
				}
				else
					tim[i][i2] = 0;
			}
		}

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

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

		int mint = INF;
		vector<int>p;
		p.clear();
		for (int i = 0; i <= m; i++){
			int mt = 0;
			for (int i2 = 0; i2 <= m; i2++){
					mt += tim[i][i2];
			}
			p.push_back(mt);
			mint = min(mt, mint);
		}

		for (int i = 0; i <= p.size(); i++){
			if (p[i] == mint){
				cout << i << " " << mint << endl;
				break;
			}
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int n, v_max;
  int d[10][10];

  while (cin >> n, n){
    memset(d, 1e9 + 9, sizeof(d));
    v_max = 0;
    REP(i, n){
      int a, b, c;
      cin >> a >> b >> c;
      v_max = max(v_max, max(a, b));
      d[a][b] = c;
      d[b][a] = c;
    }

    v_max++;
    REP(i, v_max) d[i][i] = 0;
    REP(k, v_max) REP(i, v_max) REP(j, v_max) {
      d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    pair<int, int> mini;
    mini.second = 1e9 + 9;
    REP(i, v_max) {
      int sum = 0;
      REP(j, v_max) {
        if (d[i][j] == 1e9 + 9) continue;
        sum += d[i][j];
      }
      if (mini.second > sum){
        mini.first = i;
        mini.second = sum;
      }
    }

    cout << mini.first << " " << mini.second << endl;
  }
}