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 <cstring>
#include <iostream>
#include <queue>
using namespace std;

int n, m; // 道の数，街の数
int edges[10][10];

int dijkstra(int from, int to) {
    int visited[m];
    fill(visited, visited + m, 0xffffff);
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
    que.push(make_pair(0, from));
    visited[from] = 0;
    while (!que.empty()) {
        pair<int, int> current = que.top();
        que.pop();
        const int dist = current.first;
        const int pos = current.second;
        if (pos == to) {
            return dist;
        }
        for (int i = 0; i < m; i++) {
            const int d = dist + edges[pos][i];
            if (visited[i] > d) {
                visited[i] = d;
                que.push(make_pair(d, i));
            }
        }
    }
    return -1;
}

int main() {
    while (cin >> n, n) {
        memset(edges, 0x3, sizeof(edges));
        
        m = 0;
        for (int i = 0; i < n; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            edges[a][b] = edges[b][a] = c;
            m = max(a, max(b, m));
        }
        m++;
        
        int res, res_time = 0x7fffffff;
        for (int i = 0; i < m; i++) {
            int total = 0;
            for (int j = 0; j < m; j++) {
                total += dijkstra(i, j);
            }
            if (total < res_time) {
                res_time = total;
                res = i;
            }
        }
        
        cout << res << ' ' << res_time << endl;
    }
    
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    while (cin >> n, n) {
        int g[10][10];
        for (int i = 0; i < 10; i++) {
            fill(g[i], g[i]+10, 1010001000);
        }
        for (int i = 0; i < n; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            g[a][b] = c;
            g[b][a] = c;
        }
        for (int k = 0; k < 10; k++) {
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    g[i][j] = min(g[i][j], 
                            g[i][k] + g[k][j]);
                }
            }
        }
        int ans = 0, max = 1010001000;
        for (int i = 0; i < 10; i++) {
            int sum = 0;
            bool fl = false;
            for (int j = 0; j < 10; j++) {
                if (i == j) {
                    continue;
                }
                if (g[i][j] != 1010001000) {
                    fl = true;
                    sum += g[i][j];
                }
            }
            if (fl && max > sum) {
                max = sum;
                ans = i;
            }
        }
        cout << ans << " " << max << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<string.h>

using namespace std;

#define INF 1000000

int E,V,r[50][3],d[12][12];

void warshall_floyd(){
  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]);
}

void init(){
  for(int i=0;i<12;i++)
    for(int j=0;j<12;j++)
      d[i][j]=INF;

  memset(r,0,sizeof(r));
  V=0;
  E=0;
}

void solve(){
  warshall_floyd();

  int res[12];
  fill(res,res+12,0);


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


  int res1=INF;
  int res2=INF;

  for(int i=0;i<V;i++){
    if(res[i]<res2){
      res1=i;
      res2=res[i];
    }
  }

  printf("%d %d\n",res1,res2);
}

int main(){
  while(true){
    init();
    scanf("%d",&E);
    if(E==0) break;
    for(int i=0;i<E;i++){
      scanf("%d%d%d",&r[i][0],&r[i][1],&r[i][2]);
    }

    for(int i=0;i<10;i++){
      V=max(V,r[i][1]);
    }
    V++;


    for(int i=0;i<E;i++){
      d[r[i][0]][r[i][1]]=r[i][2];
      d[r[i][1]][r[i][0]]=r[i][2];
    }

    for(int i=0;i<V;i++)
      d[i][i]=0;

    solve();
  }
  return 0;
}

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

const int N = 15;
const int INF = 1 << 25;
int dist[N][N];
void chmin(int &a, int b) {
    a = std::min(a, b);
}

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

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

        int T = 0;
        for(int i=0; i<M; i++) {
            int a, b, c; scanf("%d%d%d", &a, &b, &c);
            chmin(dist[a][b], c);
            chmin(dist[b][a], c);
            T = std::max({T, a+1, b+1});
        }

        for(int k=0; k<T; k++) {
            for(int i=0; i<T; i++) {
                for(int j=0; j<T; j++) {
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }

        int ans = INF, idx = 0;
        for(int i=0; i<T; i++) {
            int sum = 0;
            for(int k=0; k<T; k++) {
                sum += dist[i][k];
            }
            if(ans > sum) {
                ans = sum;
                idx = i;
            }
        }
        printf("%d %d\n", idx, ans);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;

		if(n == 0){
			break;
		}

		int* start = new int[n];
		int* goal = new int[n];
		int* cost = new int[n];

		for(int i = 0; i < n; i++){
			cin >> start[i] >> goal[i] >> cost[i];
		}

		int town = 0;

		for(int i = 0; i < n; i++){
			town = max(start[i], goal[i]);
		}

		town++;

		vector<vector<int> > dist(town, vector<int>(town, INT_MAX / 2));

		for(int i = 0; i < n; i++){
			dist[start[i]][goal[i]] = cost[i];
			dist[goal[i]][start[i]] = cost[i];
		}

		for(int i = 0; i < town; i++){
			dist[i][i] = 0;
		}


		for(int k = 0; k < town; k++){
			for(int i = 0; i < town; i++){
				for(int j = 0; j < town; j++){
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
		int* total = new int[town];
		int TOTAL = INT_MAX / 2;
		int S = 0;

		for(int i = 0; i < town; i++){
			total[i] = 0;
		}

		for(int i = 0; i < town; i++){
			for(int j = 0; j < town; j++){
				total[i] += dist[i][j];
			}
			if(TOTAL > total[i]){
				TOTAL = min(TOTAL, total[i]);
				S = i;
			}
		}

		cout << S << " " << TOTAL << endl;
		delete [] start;
		delete [] goal;
		delete [] cost;
		delete [] total;
	}
	return 0;
}