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>

using namespace std;

const int INF = 1<<29;
const int N = 10;

int main(){
    int n;
    while(true){
        cin >> n;
        if(!N) break;

        int dp[N][N];
        for(int i=0;i<N;i++)
        for(int j=0;j<N;j++) dp[i][j] = INF;

        int a,b,c;
        while(n--){
            cin >> a >> b >> c;
            dp[a][b] = c;
            dp[b][a] = c;
        }

        for(int k=0;k<N;++k){
            for(int i=0;i<N;++i){
                for(int j=0;j<N;++j){
                    if(dp[i][j] > dp[i][k] + dp[k][j])
                        dp[i][j] = dp[i][k] + dp[k][j];
                }
            }
        }

    int sum[N];
    for(int i=0;i<N;i++){
        sum[i] = 0;
        for(int j=0;j<N;j++){
            if(i != j && dp[i][j]!=INF){
                sum[i] += dp[i][j];
            }
        }
    }

    int ans_i = 0;
    for(int i=0;i<N;i++){
        if(sum[i] < sum[ans_i] && sum[i] != 0){
            ans_i = i;
        }
    }

    cout << ans_i << " " << sum[ans_i] << endl;

    }

}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    vector<int> vv;
    int dp[10][10], ans[10] = {};
    rep(i, 10) rep(j, 10) dp[i][j] = i == j ? 0 : INF;
    rep(i, n) {
      int a, b, c;
      bool key1 = 1, key2 = 1;
      cin >> a >> b >> c;
      if (i == 0) {
        vv.push_back(a);
        vv.push_back(b);
      }
      rep(i, vv.size()) {
        if (vv[i] == a)
          key1 = 0;
        if (vv[i] == b)
          key2 = 0;
      }
      if (key1)
        vv.push_back(a);
      if (key2)
        vv.push_back(b);
      dp[a][b] = c;
      dp[b][a] = c;
    }
    rep(k, n) rep(i, n) rep(j, n) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    rep(i, vv.size()) rep(j, vv.size()) ans[i] += dp[vv[i]][vv[j]];
    rep(i, 10) if (ans[i] == 0) ans[i] = INF;
    cout << distance(ans, min_element(ans, ans + n)) << ' '
         << ans[distance(ans, min_element(ans, ans + n))] << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

typedef long long ll;
void show_path_list();

ll path_list[10][10];

void init(){
  for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
      path_list[i][j] = 99999999999;
    }
  }
}

int main(){
  int n, from, to, cost, t;

  while(true){
    t = 0;

    init();
    cin >> n;

    if( n == 0 ) break;

    for(int i = 0; i < n; i++){
      cin >> from >> to >> cost;
      path_list[from][to] = cost;
      path_list[to][from] = cost;
      t = max( t, max( from, to ) );
    }
    t++;

    for(int i = 0; i < t; i++){
      path_list[i][i] = 0;
    }

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

    ll min_town, min_cost = 9999999999;

    for(int i = 0; i < t; i++){
      ll cost = 0;
      for(int j = 0; j < t; j++){
        cost += path_list[i][j];
      }
      if( cost < min_cost ){
        min_town = i;
        min_cost = cost;
      }
    }
    //show_path_list();

    cout << min_town << " " << min_cost << endl;
  }
}

void show_path_list(){
  for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
      cout << path_list[i][j] << " ";
    }
    cout << endl;
  }
}

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

#define MAX 11
#define INF (1<<23)

int G[MAX][MAX];

int main() {
  int n, x, y, c;
  int V;
  
  while(cin >> n, n) {
    fill(G[0], G[MAX], INF);
    
    for(int i=0; i<MAX; i++) {
      G[i][i] = 0;
    }
    
    V = 0;
    for(int i=0; i<n; i++) {
      cin >> x >> y >> c;
      V = max(V, max(x, y));
      G[x][y] = G[y][x] = c;
    }

    V++;
    
    for(int k=0; k<V; k++) {
      for(int i=0; i<V; i++) {
	for(int j=0; j<V; j++) {
	  G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	}
      }
    }
    
    int sum, ans = INF, id;
    
    for(int i=0; i<V; i++) {
      sum = 0;
      for(int j=0; j<V; j++) {
	sum += G[i][j];
      }
      if(ans > sum) {
	ans = sum;
	id = i;
      }
    }
    
    cout << id << " " << ans << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <queue>
#define INF 123456789
using namespace std;
typedef pair<int,int> P;//first:???????????¢/second:????????????
int main() {
// AOJ0189 Dijkstra
	for (;;)
	{
		struct edge {int to,cost;};
		int city = 0;//?????¨???????????????????°????(0~7?????§????????????city == 8??§??????)
		int n;
		cin >> n;
		vector<edge> es[11];
		if (n == 0) break;
		for (int i = 0;i < n;i++)
		{
			int a,b,c;
			cin >> a >> b >> c;
			es[a].push_back(edge{b,c});
			es[b].push_back(edge{a,c});//????????¨???
 			city = max (max(a,b)+1,city);
		}
		int min = INF;
		int mincity;
		for (int target_city = 0;target_city < city;target_city++)
		{
			//target_city?????????????°???????????¨??????????????????????
			int d[city];
			priority_queue <P,vector<P>,greater<P> > que;
			for (int i = 0;i < city;i++)
			{
				d[i] = INF;
			}
			d[target_city] = 0;
			que.push(P(0,target_city));
			while(!que.empty())
			{
				P pp = que.top();
				que.pop();
				if(d[pp.second] < pp.first) continue;
				d[pp.second] = pp.first;
				for (int i = 0;i < es[pp.second].size();i++)
				{
					//?????????????????????????????????????????????
					if (es[pp.second][i].cost + pp.first < d[es[pp.second][i].to])
					{
						d[es[pp.second][i].to] = es[pp.second][i].cost + pp.first;
						que.push(P(d[es[pp.second][i].to],es[pp.second][i].to));
					}
				}
			}
			int sum = 0;
			for (int i = 0;i < city;i++)
			{
				sum += d[i];
			}
			if (sum < min)
			{
				min = sum;
				mincity = target_city;
			}
		}
		cout << mincity << " " << min << endl;
	}
	return 0;
}