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>
using namespace std;
#define MAX 50
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];

int dijkstra(int s){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = minnum ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = minnum; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            if(t < v[i]) v[i] = t;
        }
    }
    
    int sum = 0;
    for(int i = minnum ; i <= maxnum ; i++){
        sum += v[i];
    }
    
    return sum;
}


int main(){
    int a,b,c;
    
    for(int i = 0 ; i < MAX ; i++)
        for(int j = 0 ; j < MAX ; j++)
            r[i][j] = INF;

    while(cin >> n,n){
        maxnum = 0;
        minnum = INF;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = c;
            r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
            minnum = min(minnum,min(a,b));
        }

        int mx = INF, e;
        for(int i = minnum; i <= maxnum ; i++){

            if(dijkstra(i) < mx){
                mx = dijkstra(i);
                e = i;
            }
        }
        cout << e << ' ' << mx << endl;
    }
    
    return 0;
}

C++: // Warshall-floyd
#include <iostream>
#include <algorithm>
using namespace std;
#define INF (1<<20) 

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

void init()
{
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; 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(max(v, 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 <cstdio>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <functional>
#include <string.h>
using namespace std;
const int INF = 1<<28;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,start,end) for(int i=(start);i<(end);++i)
#define pint(i) printf("%d\n",(i))
#define pint2(i,j) printf("%d %d\n",(i),(j))
#define pint3(i,j,k) printf("%d %d %d\n",(i),(j),(k))
#define gint(i) scanf("%d",&(i))
#define gint2(i,j) scanf("%d %d",&(i),&(j))
#define gint3(i,j,k) scanf("%d %d %d",&(i),&(j),&(k))
#define init(tar,val) memset((tar),(val),sizeof((tar)))
#define show(tar,len) for(int i=0;i<(len);++i) \
	cout<<tar[i]<<' ';\
	cout<<endl;




int main(){
	//freopen("a.in", "r", stdin);
	int n;
	while (cin >> n && n){
		int cost[10][10];
		rep(i, 0, 10){
			rep(j, 0, 10){
				cost[i][j] = i == j ? 0 : INF;
			}
		}
		rep(i, 0, n){
			int a, b, c;
			cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
		}
		rep(k, 0, 10){
			rep(i, 0, 10){
				rep(j, 0, 10){
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		int out = INF, id = 0;
		rep(i, 0, 10){
			int tmp = 0;
			rep(j, 0, 10){
				if (cost[i][j] < INF)
					tmp += cost[i][j];
			}
			if (tmp && tmp < out){
				out = tmp;
				id = i;
			}
		}
		cout << id << ' ' << out << endl;
	}
	return 0;
}

C++: #include <stack>
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstdio>
using namespace std;

int main()
{
	int n;
	typedef pair <int, int> p;//????????????????????????
	while (cin >> n, n != 0) {
		vector <p> map[12];
		int a, b, c;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			map[a].push_back(p(b, c));
			map[b].push_back(p(a, c));
		}
		p ans = p(0, 9999999);
		for (int z = 0; z < 10; z++) {
			if (map[z].size() == 0)break;
			int d[12] ;
			for (int i = 0; i < 12; i++)d[i] = 9999999;
			priority_queue<p, vector<p>, greater<p> > que;//??????????????????
			que.push(p(0, z));
			d[z] = 0;
			while (!que.empty()) {
				p now = que.top();
				que.pop();
				if (now.first > d[now.second])continue;
				for (int i = 0; i < map[now.second].size(); i++) {
					p dst = map[now.second][i];
					if (d[dst.first] > now.first + dst.second) {
						que.push(p(now.first + dst.second, dst.first));
						d[dst.first] = now.first + dst.second;
					}
				}
			}int cnt = 0;
			for (int i = 0; i < 10; i++) { if (d[i] != 9999999)cnt += d[i]; }
			if (ans.second > cnt)ans = p(z, cnt);
		}
		cout << ans.first << " " << ans.second << endl;
	}
}