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 <stdio.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define INF (10000000)


int main(void)
{
	int ans, ans_sum;
	int cost[10][10];
	int n;
	int city_cnt;
	
	while (1){
	scanf("%d", &n);
	
	if (n == 0){
		break;
	}
	
	REP(i, 10){
		REP(j, 10){
			if (i == j){
				cost[i][j] = 0;
			}
			else {
				cost[i][j] = INF;
			}
		}
	}
	
	city_cnt = 0;
	REP(i, n){
		int s, e, c;
		scanf("%d%d%d", &s, &e, &c);
		cost[s][e] = cost[e][s] = c;
		city_cnt = MAX(city_cnt, MAX(s, e));
	}
	city_cnt++;
	
	
	REP(i, city_cnt)REP(j, city_cnt)REP(k, city_cnt) cost[i][j] = MIN(cost[i][j], cost[i][k] + cost[k][j]);
	
	ans = 0;
	ans_sum = 0;
	REP(i, city_cnt){
		ans_sum += cost[0][i];
	}
	REP(i, city_cnt){
		int sum = 0;
		REP(j, city_cnt){
			sum += cost[i][j];
		}
		if (ans_sum > sum){
			ans_sum = sum;
			ans = i;
		}
	}
	
	printf("%d %d\n", ans, ans_sum);
	
	}
	return (0);
}

C++: // Warshall-floyd
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 114514810

int n, a, b, c, v, d[11][11];// v: num of nodes

void init()
{
    for(int i=0; i<11; i++) {
        for(int j=0; j<11; j++) {
            if(i==j)// If not exist cost, cost=INF
                d[i][j] = 0;
            else
                d[i][j] = INF;
        }
    }
}

int main(void)
{
    ios::sync_with_stdio(false);
    while(1) {
        cin >> n;
        if(n == 0) break;
        init();

        v = -1;
        for(int i=0; i<n; i++) {
            cin >> a >> b >> c;
            d[a][b] = c; d[b][a] = c;
            v = max(v, max(a, b));
        }
        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]);
                }
            }
        }


        int city, dist = INF;
        for(int i=0; i<v; i++) {
            int sum = 0;
            for(int j=0; j<v; j++) {
                sum += d[i][j];
            }
            if(sum < dist) {
                dist = sum;
                city = i;
            }
        }
        cout << city << " " << dist << endl;
    }

    return 0;
}

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

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d; // グラフの距離を格納した2次元配列（隣接行列）
          // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
    int n;
    int ans_min = 100000;
    int ans[10];
    int number;

    while(1){    
        for(int i=0; i<10; i++){
            ans[i] = 0;
        }

        d = Matrix(10, vector<int>(10, INF));
        for (int i = 0; i < 10; i++) d[i][i] = 0;
        
        cin >> n;
        if(n == 0){
            break;
        }

        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            d[from][to] = cost;
            d[to][from] = cost;
        }
        
        warshall_floyd(10);
        
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
            if (i != j && d[i][j] != INF)
                //cout << i << "から" << j << "へのコスト: " << d[i][j] << endl;
                ans[i] += d[i][j];
            }
            //cout<< ans[i]<<endl;
            if(ans_min>ans[i] &&ans[i] !=0){
                ans_min = ans[i];
                number = i;
            }
        }

        cout << number << " " << ans_min << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
#define V 10
#define INF (1<<30)-1
struct edge{int from,to,cost;};
int main(){
  int d[V];
  int n;
  while(cin>>n){
    if(n==0) break;
    edge es[2*n];
    int a,b,c;
    int ans = INF,ansi;
    for(int i=0;i<2*n;i+=2){
      cin >> a >> b >> c;
      es[i].from = es[i+1].to = a;
      es[i+1].from = es[i].to = b;
      es[i].cost = es[i+1].cost = c;
    }
    for(int j=0;j<V;j++){
      for(int i=0;i<V;i++) d[i] = INF; 
      d[j] = 0;
      while(true){
	bool updata = false;
	for(int i=0;i<2*n;i++){
	  edge e = es[i];
	  if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
	    d[e.to] = d[e.from] + e.cost;
	    updata = true;
	  }
	}
	if(!updata) break;
      }    
      int s = 0;
      for(int i=0;i<V;i++){
	if(d[i]!=INF){
	  s += d[i];
	}
      }
      if(s<ans&&s!=0){ans = s,ansi =j;};
    }
    cout << ansi << ' ' << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define INF 1000000
int cost[1000][1000];
int d[1000];
bool used[1000];
int V;

void dijkstra(int s){
 
  d[s] = 0;
  while(true){
    int v = -1;
    for(int u = 0 ; u <= V ; u++){
      if(!used[u] && (v == -1 || d[u] < d[v]))v = u;
    }

    if(v == -1) break;

    used[v] = true;

    for(int u = 0 ; u <= V ; u++ ){
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }
}

int main(){
  int u,v,c;
  int ans,ansi;
  int j;
  while( cin >> V, V) {
    int min = 100000000;

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

    for(int i = 0 ; i < V ; i++){
      cin >> v >> u >> c;
      cost[v][u] = c;
      cost[u][v] = c;
    }
    for( j = 0; j < V ; j++){
      fill(d,d + (V+1) , INF);
      fill(used,used + (V+1),false);

      dijkstra(j);
      ans = 0;	
      for(int i = 0 ; i <= V ; i++){
	if(d[i] < INF)ans +=  d[i];
      }
      for(int i = 0 ; i <= V ; i++){

      }
      if(min > ans && ans != 0 ){
	min = ans;
	ansi = j;
      }
    }
    cout << ansi<<" "<< min << endl;
  }

}

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

using namespace std;

#define chmin(a,b) a=min(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)

const int inf = 1e9;

int d[10][10];
bool found[10];
int N;

void wf()
{
	rep(k, 10) rep(i, 10) rep(j, 10) {
		chmin(d[i][j], d[i][k] + d[j][k]);
	}
}

int main()
{
	while (scanf("%d", &N), N) {
		fill_n(found, 10, false);
		fill(d[0], d[10], inf);
		rep(i, 10) d[i][i] = 0;

		rep(i, N) {
			int a, b, c; scanf("%d %d %d", &a, &b, &c);
			d[a][b] = d[b][a] = c;
			found[a] = found[b] = true;
		}

		wf();

		int mi = inf, a;

		rep(i, 10) if (found[i]) {
			int sum = 0;
			rep(j, 10) if (found[j]) {
				sum += d[i][j];
			}
			if (mi > sum) {
				mi = sum;
				a = i;
			}
		}

		printf("%d %d\n", a, mi);
	}
}