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>
#include<algorithm>
#define INF 999999
typedef long long ll;
using namespace std;
int n,a,b,c,maxm;
		int sum,miniNo,minim;
int t[100][100];
int main(){
	while(cin>>n,n){
		for(int i=0;i<100;i++)for(int j=0;j<100;j++){
			if(i!=j)t[i][j]=INF;
			else t[i][j]=0;
		}
		maxm=0;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			maxm=max(maxm,max(a,b));
			t[a][b]=c;
			t[b][a]=c;
		}
		maxm++;
		for(int k=0;k<maxm;k++){
			for(int i=0;i<maxm;i++){
				for(int j=0;j<maxm;j++){
					t[i][j]=min(t[i][k]+t[k][j],t[i][j]);
				}
			}
		}
		
		
		minim=INF;
		for(int i=0;i<maxm;i++){
			sum=0;
			for(int j=0;j<maxm;j++)sum+=t[i][j];
			if(minim>sum){
				minim=sum;
				miniNo=i;
			}
		}
		cout<<miniNo<<" "<<minim<<endl;
		
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

// BEGIN_LIBRARY ///////////////////
#define MAX_V (1000)
#define INF (999999)

namespace NLibrary{
	class Dijkstra {
	private:
		int cost[MAX_V][MAX_V];
		int d[MAX_V];
		bool used[MAX_V];
		int V;
	public:
		Dijkstra() {
			for (int i = 0; i < MAX_V; i++) {
			  fill(cost[i], cost[i] + MAX_V, INF);
			}
		}

		void setV(int V) {
			this->V = V;
		}

		void setCost(int a, int b, int c, bool bidirect = false) {
			this->cost[a][b] = c;
			if (bidirect) {
				this->cost[b][a] = c;
			}
		}

		void calc(int s) {
			// s??????????????????????????¢????±???????
			fill(d, d + MAX_V, INF); 
			fill(used, used + MAX_V, false);
			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 getL(int a) {
			return d[a];
		}
	};

}

// END_LIBRARY ////////////////////

int main() {
	NLibrary::Dijkstra dijkstra;
	int n;
	int as[100];
	int bs[100];
	int cs[100];
	while (cin >> n, n != 0) {
	  int V = -1;
		for (int i = 0; i < n; i++) {
			cin >> as[i] >> bs[i] >> cs[i];
		  V = max(V, max(as[i], bs[i]));
		}
		V++;
		dijkstra.setV(V);
		for (int i = 0; i < n; i++) {
			dijkstra.setCost(as[i], bs[i], cs[i], true);
		}
		int m = INF, town = -1;
		for (int i = 0; i < V; i++) {
			int sum = 0;
			dijkstra.calc(i);
			for (int j = 0; j < V; j++) {
				sum += dijkstra.getL(j);
			}

			if (sum < m) {
				town = i;
				m = sum;
			}
		}
		cout << town << " " << m << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <iomanip>
#include <cstring>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;

int N;
#define MV 10
#define INF 0x7F7F7F7F
int G[MV][MV];
bool input() {
    scanf("%d", &N);
    if (N == 0) return false;
    memset(G, 0x7F, sizeof(G));
    for (int i = 0; i < N; i++) {
        int a, b, c; scanf("%d %d %d", &a, &b, &c);
        G[a][b] = G[b][a] = c;
        G[a][a] = 0;
        G[b][b] = 0;
    }
    return true;
}

void solve() {
    for (int k = 0; k < MV; k++) {
        for (int i = 0; i < MV; i++) {
            for (int j = 0; j < MV; j++) {
                if (G[i][k] == INF || G[k][j] == INF) continue;
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
#ifdef DEBUG
    for (int i = 0; i < MV; i++) {
        for (int j = 0; j < MV; j++) {
            if (G[i][j] == INF) {
                cout << setw(5) << "x";
            } else {
                cout << setw(5) << G[i][j];
            }
        }
        cout << endl;
    }
#endif
    int index = 0, min1 = INF; 
    for (int i = 0; i < MV; i++) {
        if (G[i][i] == INF) break;
        int total = 0;
        for (int j = 0; j < MV; j++) {
            if (G[i][j] == INF) break;
            total += G[i][j];
        }
        if (total < min1) {
            index = i;
            min1 = total;
        }
    }
    printf("%d %d\n", index, min1);
}

int main() {
    while (input()) {
        solve();
    }
    return 0;
}

C++: #include<iostream>

#define TOWN_MAX 11
#define ROAD_MAX 46
#define INF 1000000000

int solve(int);

int main(int argc, char const* argv[]) {
    int n;

    while (true) {
        std::cin >> n;
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

int solve(int road_num) {
    long long distances[TOWN_MAX][TOWN_MAX];
    bool used[TOWN_MAX];

    for (int i = 0; i < TOWN_MAX; i++) {
        used[i] = false;
        for (int j = 0; j < TOWN_MAX; j++)
            distances[i][j] = (i == j) ? 0 :INF;
    }

    for (int i = 0; i < road_num; i++) {
        int src, dest, cost;
        std::cin >> src >> dest >> cost;
        distances[src][dest] = cost;
        distances[dest][src] = cost;
        used[src] = used[dest] = true;
    }

    for (int infix_road = 0; infix_road < road_num; infix_road++) {
        for (int begin_town = 0; begin_town < TOWN_MAX; begin_town++) {
            for (int end_town = 0; end_town < TOWN_MAX; end_town++) {
                distances[begin_town][end_town] = std::min(distances[begin_town][end_town],
                        distances[begin_town][infix_road] + distances[infix_road][end_town]);
            }
        }
    }

    int min_cost       = INF;
    int min_cost_index = 0;
    for (int i = 0; i < TOWN_MAX; i++) {
        if (!used[i]) continue;

        int sum_cost   = 0;
        for (int j = 0; j < TOWN_MAX; j++) {
            if (!used[j]) continue;
            sum_cost += distances[i][j];
        }

        if (sum_cost < min_cost) {
            min_cost       = sum_cost;
            min_cost_index = i;
        }
    }

    std::cout << min_cost_index << " " << min_cost << std::endl;

    return 0;
}