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;

struct E{ int a, b, c; };

int main(){
	int n;
	E edge[45];
	int fr, to, co;
	int d[10][10];
	int town;
	const int INF = 100000000;
	bool update;
	int res_town, res_cost, sub;
	
	while(true){
		scanf("%d", &n);
		
		if(n == 0) return 0;
		
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				d[i][j] = INF;
			}
		}
		for(int i = 0; i < 10; i++) d[i][i] = 0;
		
		town = 0;
		for(int i = 0; i < n; i++){
			scanf("%d%d%d", &fr, &to, &co);
			town = max(town, max(fr, to));
			d[fr][to] = co; d[to][fr] = co;
			edge[i].a = fr; edge[i].b = to; edge[i].c = co;
		}
		
		res_town = 0; res_cost = INF * 10;
		for(int i = 0; i <= town; i++){
			sub = 0;
			
			//dijkstra
			update = true;
			while(update){
				update = false;
				for(int j = 0; j < n; j++){
					if(d[i][edge[j].a] + edge[j].c < d[i][edge[j].b]){
						update = true;
						d[i][edge[j].b] = d[i][edge[j].a] + edge[j].c;
					}
					if(d[i][edge[j].b] + edge[j].c < d[i][edge[j].a]){
						update = true;
						d[i][edge[j].a] = d[i][edge[j].b] + edge[j].c;
					}
				}
			}
			
			for(int j = 0; j <= town; j++) sub += d[i][j];
			
			if(sub < res_cost){
				res_town = i;
				res_cost = sub;
			}
		}
		
		printf("%d %d\n", res_town, res_cost);
	}
}

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

typedef vector<vector<int> > Matrix;

const int MAX_M = 10; // 町の数
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, m;
  while(cin >> n, n != 0) {
    m = 0;
    d = Matrix(MAX_M, vector<int>(MAX_M, INF));
    for (int i = 0; i < MAX_M; i++) d[i][i] = 0;

    for (int i = 0; i < n; i++) {
      int from, to, dist;
      cin >> from >> to >> dist;
      d[from][to] = dist;
      d[to][from] = dist;
      
      // 初期状態では町の数がわからないので、道情報を読み込みながら調べる
      m = max(m, from+1);
      m = max(m, to+1);
    }
    warshall_floyd(m);
    int min_m = -1, min_dist = INF;

    for (int i = 0; i < m; i++) {
      int sum = 0;
      for (int j = 0; j < m; j++) {
        sum += d[i][j];
      }
      if (sum < min_dist) {
        min_dist = sum;
        min_m = i;
      }
    }
    cout << min_m << " " << min_dist << endl;
  }
  return 0;
}

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 (100000000)


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++: #include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

struct Edge{
	int to;
	int weight;
	
	Edge(int _to, int _w) : to(_to), weight(_w){}
	Edge() : to(-1), weight(-1){}
};

const int MAXN = 10;
const int INF = 0x3f3f3f3f;
int dist[MAXN];
bool isVis[MAXN];
int E, N;
vector<Edge> graph[MAXN];
vector<pair<int ,int> > dists;

struct cmp{
	bool operator() (int a, int b){
		return dist[a] > dist[b];
	}
};

void clearV(){
	for(int i = 0; i < MAXN; ++i){
		graph[i].clear();
	}
}

void init(){
	clearV();
	dists.clear();
	N = 0;
	for(int i = 0; i < E; ++i){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		graph[a].push_back(Edge(b, c));
		graph[b].push_back(Edge(a, c));
		if(a > N) N = a;
		if(b > N) N = b;
	}
}

int dijkstra(int s){
	
	fill(isVis, isVis + MAXN, false);
	fill(dist, dist + MAXN, INF);
	dist[s] = 0;
	
	for(int i = 0; i <= N; ++i){
		
		int u = -1, MIN = INF;
		for(int j = 0; j <= N; ++j){
			if(dist[j] < MIN && isVis[j] == false){
				u = j;
				MIN = dist[j];
			}
		}
		isVis[u] = true;
		if(u == -1) break;
		
		for(int j = 0; j < graph[u].size(); ++j){
			Edge nowEdge = graph[u][j];
			if(dist[nowEdge.to] > dist[u] + nowEdge.weight){
				dist[nowEdge.to] = dist[u] + nowEdge.weight;	
			}
		}
	}
	
	int sum = 0;
	for(int i = 0; i <= N; ++i){
		if(dist[i] != INF){
			sum += dist[i];
		}
	}
	
	return sum;
}

int main(){
	while(scanf("%d", &E) && E){
		init();
		int optimum = INF;
		int index = 0;
		for(int i = 0; i <= N; ++i){
			int sum = dijkstra(i);
			if(sum < optimum){
				optimum = sum;
			}
			dists.push_back(pair<int, int>(i, sum));
		}
		
		int ans = INF;
		for(int i = 0; i <= N; ++i){
			if(dists[i].second == optimum && i < ans){
				ans = i;
			}
		}
		printf("%d %d\n", ans, optimum);
	}
}

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

const int NUM = 15;

int main() {
	int wf[NUM][NUM];
	int n;
	while ( cin >> n , n ) {
		for ( int i = 0 ; i < NUM ; i++ ) {
			for ( int j = 0 ; j < NUM ; j++ ) {
				if ( i == j ) {
					wf[i][j] = 0;
				} else {
					wf[i][j] = 1000000;
				}
			}
		}
		
		int m=0;
		
		int a,b,c;
		for ( int i = 0 ; i < n ; i++ ) {
			cin >> a >> b >> c;
			wf[a][b] = wf[b][a] = c;
			if ( a > m ) {
				m = a;
			} if ( b > m ) {
					m = b;
			}
		}
		m++;
		for ( int a = 0 ; a < m ; a++ ) {
			for ( int b = 0 ; b < m ; b++ ) {
				for ( int c = 0 ; c < m ; c++ ) {
					wf[b][c] = min ( wf[b][c] , wf[b][a] + wf[a][c] );
				}
			}
		}
		int loc,sec = 1000000;
		for ( int a = 0 ; a < m ; a++ ) {
			int nsec = 0;
			for ( int b = 0 ; b < m ; b++ ) {
				nsec += wf[a][b];
			}
			if ( nsec < sec ) {
				loc = a;
				sec = nsec;
			}
		}
		cout << loc << " " << sec << endl;
	}
}