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 <cstdio>
#include <algorithm>
using namespace std;

const int MAX_TOWN = 9;
const int INF = 1 << 20;

int d[MAX_TOWN + 1][MAX_TOWN + 1];

int main()
{
  while (true) {
    int N; scanf("%d", &N);
    if (N == 0) break;

    for (int i = 0; i <= MAX_TOWN; i++) {
      for (int j = 0; j <= MAX_TOWN; j++) {
        d[i][j] = i == j ? 0 : INF;
      }
    }

    for (int i = 0; i < N; i++) {
      int a, b, c; scanf("%d%d%d", &a, &b, &c);
      d[a][b] = d[b][a] = c;
    }

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

    int min_t = -1, min_c = INF;

    for (int i = 0; i <= MAX_TOWN && d[i][0] != INF; i++) {
      int sum = 0;
      for (int j = 0; j <= MAX_TOWN && d[i][j] != INF; j++) {
        sum += d[i][j];
      }

      if (min_c > sum) {
        min_t = i;
        min_c = sum;
      }
    }

    printf("%d %d\n", min_t, min_c);
  }
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <climits>
typedef long long ll;

const int max_t = 20;
ll dist[max_t][max_t];

int main() {
	//freopen("aoj0189.txt", "r", stdin);
	while (1) {
		int n, t = 0;
		scanf("%d", &n);
		if (n == 0) break;
		
		for (int i = 0; i < max_t; i++) {
			std::fill(dist[i], dist[i] + max_t, INT_MAX);
		}
		for (int i = 0; i < n; i++) {
			int from, to;
			ll d;
			scanf("%d%d%lld", &from, &to, &d);
			t = std::max(t, from);
			t = std::max(t, to);
			dist[from][to] = d;
			dist[to][from] = d;
		}
		for (int i = 0; i <= t; i++) {
			dist[i][i] = 0;
		}

		for (int k = 0; k <= t; k++) {
			for (int i = 0; i <= t; i++) {
				for (int j = 0; j <= t; j++) {
					if (dist[i][k] != INT_MAX && dist[k][j] != INT_MAX)
						dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}

		ll min_len = INT_MAX;
		int start = -1;
		for (int i = 0; i <= t; i++) {
			ll len = 0;
			for (int j = 0; j <= t; j++) {
				if (j == i) continue;

				len += dist[i][j];
			}
			if (len < min_len) {
				min_len = len;
				start = i;
			}
		}

		printf("%d %lld\n", start, min_len);
	}
	return 0;
}

C++: #include<iostream>

#define TOWN_MAX 10
#define ROAD_MAX 45
#define INF 1000000000

int  distances[TOWN_MAX][TOWN_MAX];

int solve(int);

int main(int argc, char const* argv[]) {
    int n;

    while (true) {
        std::cin >> n;
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

int solve(int road_num) {

    for (int i = 0; i < TOWN_MAX; i++)
        for (int j = 0; j < TOWN_MAX; j++)
            distances[i][j] = (i == j) ? 0 : INF;

    for (int i = 0; i < road_num; i++) {
        int src, dest, cost;
        std::cin >> src >> dest >> cost;
        distances[src][dest] = cost;
        distances[dest][src] = cost;
    }

    for (int infix_road = 0; infix_road < road_num; infix_road++) {
        for (int begin_town = 0; begin_town < TOWN_MAX; begin_town++) {
            for (int end_town = 0; end_town < TOWN_MAX; end_town++) {
                distances[begin_town][end_town] = std::min(distances[begin_town][end_town],
                        distances[begin_town][infix_road] + distances[infix_road][end_town]);
            }
        }
    }

    int min_cost = INF;
    int min_cost_index = 0;
    for (int i = 0; i < TOWN_MAX; i++) {
        int sum_cost = 0;
        for (int j = 0; j < TOWN_MAX; j++) {
            if (distances[i][j] != INF) sum_cost += distances[i][j];
        }

        if (sum_cost < min_cost && sum_cost != 0) {
            min_cost       = sum_cost;
            min_cost_index = i;
        }
    }

    std::cout << min_cost_index << " " << min_cost << std::endl;

    return 0;
}

C++: #include<iostream>

using namespace std;
struct edge{ int from,to,cost; };
edge es[90];
int d[10][10];//h:ツ始ツ点 w:ツ姪堋的ツ地
int e;

int main()
{
    while(1)
    {
        cin>>e;
        if(e==0) break;
        for(int i=0;i<2*e;i+=2)
        {
            cin>>es[i].from>>es[i].to>>es[i].cost;
            es[i+1]=es[i];
            swap(es[i+1].from,es[i+1].to);//ツ逆ツづ個陛督づーツ暗クツつュ
        }
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++) d[i][j]=10000;
        }
        for(int i=0;i<10;i++)
        {
            d[i][i]=0;
            while(true)
            {
                bool up=false;
                for(int j=0;j<2*e;j++)
                {
                    edge ed=es[j];
                    if(d[i][ed.from]!=10000&&d[i][ed.to]>d[i][ed.from]+ed.cost)
                    {
                        d[i][ed.to]=d[i][ed.from]+ed.cost;
                        up=true;
                    }
                }
                if(!up) break;
            }
        }
        pair<int,int> res;
        res.first=-1;res.second=300000;
        for(int i=0;i<10;i++)
        {
            int sum=0;
            for(int j=0;j<10;j++)
            {
                if(d[i][j]!=10000)
                    sum+=d[i][j];
            }
            if(sum!=0&&sum<res.second)
            {
                res.first=i;
                res.second=sum;
            }
        }
        cout<<res.first<<" "<<res.second<<endl;
    }
    return 0;
}