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 = 1000000000;

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

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		// ????????°

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

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

		int cnt=INF; int town=0;
		for(int i=0; i<m; i++){
			int tmp=0;
			for(int j=0; j<m; j++){
				tmp=tmp+T[i][j];
			}
			if(tmp<=cnt){
				cnt=tmp;
				town=i;
			}
		}

		cout << town << ' ' << cnt<<endl;
	}

	return 0;
}

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

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	const int INF = 0xfffffff;

	for(int n; cin >> n, n;) {
		int m = 0;
		vector<vector<int> > dist(10, vector<int>(10, INF));
		for(int i = 0; i < 10; ++i)
			dist[i][i] = 0;

		for(int i = 0; i < n; ++i) {
			int a, b, c;
			cin >> a >> b >> c;
			chmax(m, max(a, b));

			dist[a][b] = c;
			dist[b][a] = c;
		}

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

		int city, ans = INF;
		for(int i = 0; i < m; ++i) {
			int sum = 0;
			for(int j = 0; j < m; ++j)
				sum += dist[i][j];

			if(ans > sum) {
				ans = sum;
				city = i;
			}
		}

		cout << city << " " << ans << endl;
	}


	return EXIT_SUCCESS;
}

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

int table[10][10];
int town;
int INF = 9999;

void fw(){
    for(int k = 0; k <= town; k++){
        for(int i = 0; i <= town; i++){
            for(int j = 0; j <= town; j++){
                table[i][j] = min(table[i][j], table[i][k] + table[k][j]);
            }
        }
    }
}

void solve(){
    int ret, mintable = 1<<21;
    for(int i = 0; i <= town; i++){
        int candidate = 0;
        for(int j = 0; j <= town; j++){
            candidate += table[i][j];
        }
        if(candidate < mintable){
            mintable = candidate;
            ret = i;
        }
    }

    cout << ret << " " << mintable << endl;
}

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

        if(n == 0)  break;

        town = 0;
        memset(table, INF, sizeof(table));
        for(int i = 0; i < 10; i++) table[i][i] = 0;

        int a, b, c;
        while(n-- > 0){
            cin >> a >> b >> c;
            table[a][b] = table[b][a] = c;
            town = max(town, max(a,b));
        }

        fw();
        solve();
    }
    return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>

#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

const int INF = 1e+8;

typedef struct edge_def {
	int to;
	int cost;
	edge_def(int _to, int _cost) {to = _to; cost = _cost;}
} edge;

typedef pair<int, int> P;

int V, E;
const int MAX_V = 10;
vector<edge> G[MAX_V];	//[i] : fromを表す
int d[MAX_V];

void dijkstra(int s) {
	int i;
	priority_queue<P, vector<P>, greater<P> > q;

	for (i=0; i<V; i++) d[i] = INF;
	d[s] = 0;
	q.push(P(0, s));

	while (q.size()) {
		P p = q.top();
		q.pop();
		int v = p.second;

		if (d[v] < p.first) continue;

		for (i=0; i<(int)G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int i, j;
	int total;
	int minT;

	while (1) {
		scanf("%d ", &E);
		if (!E) break;

		V = 0;
		for (i=0; i<E; i++) {
			int ef, et, ec;
			scanf("%d%d%d ", &(ef), &(et), &(ec));
			G[ef].push_back(edge(et, ec));
			G[et].push_back(edge(ef, ec));
			V = max(V, ef);	
			V = max(V, et);	
		}
		V++;

		total = INF;
		minT = INF;
		for (i=0; i<V; i++) {
			dijkstra(i);

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

			if (sum < total) {
				total = sum;
				minT = i;
			} else if (sum == total && i < minT)
				minT = i;
		}

		printf("%d %d\n", minT, total);
	}	

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>

const int kMaxTown = 10;
const int kInf = 1 << 16;

int cost[kMaxTown][kMaxTown];

int main(){

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

		for (int i = 0; i < kMaxTown; i++)
			for (int j = 0; j < kMaxTown; j++)
				cost[i][j] = (i == j) ? 0 : kInf;

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

		for (int k = 0; k < kMaxTown; k++)
			for (int i = 0; i < kMaxTown; i++)
				for (int j = 0; j < kMaxTown; j++)
					cost[i][j] = std::min(cost[i][j], cost[i][k] + cost[k][j]);

		int best = 0;
		int bestSum = kInf;
		for (int i = 0; i < kMaxTown; i++){
			int sum = 0;
			for (int j = 0; j < kMaxTown; j++)
				if (cost[i][j] != kInf)
					sum += cost[i][j];
			if (sum == 0) continue;
			if (sum < bestSum){
				bestSum = sum;
				best = i;
			}
		}

		printf("%d %d\n", best, bestSum);
	}
	return 0;
}