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 <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int INF=1<<20;
const int maxn=50;
int d[maxn][maxn];
int r;
int main()
{
    while(cin>>r)
	{
		if(r==0) break;
		for(int i=0;i<=11;i++)
			for(int j=0;j<=11;j++){
				if(i!=j)
					d[i][j]=INF;
				else
					d[i][j]=0;
			}
		int n;
		n=0;
		for(int i=0;i<r;i++)
		{
			int a,b,num;
			scanf("%d%d%d",&a,&b,&num);
			int t=max(a,b);
			n=max(t,n);
			d[a][b]=num;
			d[b][a]=num;
		}
		for(int k=0;k<=n;k++)
			for(int i=0;i<=n;i++)
				for(int j=0;j<=n;j++)
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++)
					cout<<d[i][j]<<" ";
					cout<<endl;
		}
		int minx=INF;
		int k;
		for(int i=0;i<=n;i++){
			int res=0;
			for(int j=0;j<=n;j++)
				res+=d[i][j];
			if(res<minx){
				minx=res;
				k=i;
			}
		}
		cout<<k<<" "<<minx<<endl;


	}
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <bitset>
#include <string.h>
#include <cmath>
#include <algorithm>
#define N 1000015
#define P pair<int,int>
#define ll long long
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
bool vis[10];
int dis[10];
int g[10][10];
int inf = 0x3f3f3f3f;
int n, sum;
void Dijkstra(int x) {
	mem(vis, false);
	mem(dis, inf);
	dis[x] = 0;
	// dis[1] = inf;
	for (int i = 0; i <= sum; ++i) {
		int MIN = inf, u = -1;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] < MIN) {
				MIN = dis[j];
				u = j;
			}
		}
		if (u == -1)	return;
		vis[u] = true;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] > g[u][j] + MIN) {
				dis[j] = g[u][j] + MIN;
			}
		}
	}
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	while (cin >> n, n) {
		int s, e, c;
		mem(g, inf);
		sum = -1;
		for (int i = 0; i < n; ++i) {
			cin >> s >> e >> c;
			sum = max(s, sum);
			sum = max(e, sum);
			g[s][e] = g[e][s] = min(g[s][e], c);
		}
		int ans_n, ans_v = inf;
		for (int i = 0; i <= sum; ++i) {
			Dijkstra(i);
			int sum_temp = 0;
			for (int j = 0; j <= sum; ++j) {
				if (dis[j] == inf) {
					sum_temp = inf;
					break;
				}
				sum_temp += dis[j];
			}
			if (sum_temp < ans_v) {
				ans_v = sum_temp;
				ans_n = i;
			}
		}
		cout << ans_n << " " << ans_v << endl;
	}

	return 0;
}

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

using namespace std;

#define N 10
#define INF (1e9)

int main(){
    int M,a,b,c;
    while(cin >> M, M){
        int d[N][N],mx = 0;
        fill(d[0],d[N],INF);
        for(int i = 0 ; i < M ; i++){
            cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
            mx = max(mx,max(a,b));
        }
        mx++;
        for(int i = 0 ; i < mx ; i++){
            d[i][i] = 0;
        }
        for(int k = 0 ; k < mx ; k++){
            for(int i = 0 ; i < mx ; i++){
                for(int j = 0 ; j < mx ; j++){
                    d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
        int res = INF,vnum = -1;
        for(int i = 0 ; i < mx ; i++){
            int sum = 0;
            for(int j = 0 ; j < mx ; j++){
                sum += d[i][j];
            }
            if(sum < res){
                res = sum;
                vnum = i;
            }
        }
        cout << vnum << " " << res << endl;
    }
    return 0;
}

C++: #include <iostream>
int d[10][10];
void init(){
    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 10;j++){
            d[i][j] = (i == j)? 0 : 10000;
        }
    }
}
int main(){
    int n;
    while(std::cin >> n){
        if(n == 0){
            break;
        }
        init();
        for(int i = 0;i < n;i++){
            int a , b , cost;
            std::cin >> a >> b >> cost;
            d[a][b] = std::min(d[a][b] , cost);
            d[b][a] = std::min(d[b][a] , cost);
        }
        for(int k = 0;k < 10;k++){
            for(int i = 0;i < 10;i++){
                for(int j = 0;j < 10;j++){
                    d[i][j] = std::min(d[i][j] , d[i][k] + d[k][j]);
                }
            }
        }
        int ans = -1 , ans_d = 10000;
        for(int i = 0;i < 10;i++){
            int sum = 0;
            bool tf = false;
            for(int j = 0;j < 10;j++){
                sum += (d[i][j] == 10000)? 0 : d[i][j];
                tf = (d[i][j] == 10000 || i == j)? tf : true;
            }
            if(sum < ans_d && tf){
                ans = i , ans_d = sum;
            }
        }
        std::cout << ans << " " << ans_d << "\n";
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <cstring>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int wf[10][10];
set <int> town;
int main(){
    int e;
    cin >> e;
    rep(i, 10) rep(j, 10)
      if(i == j) wf[i][j] = 0; else wf[i][j] = INF;
    rep(i, e){
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        wf[x][y] = wf[y][x] = z;
        town.insert(x); town.insert(y);
    }
    int n = town.size();
    rep(k, n) rep(i, n) rep(j, n)
      wf[i][j] = min(wf[i][j], wf[i][k] + wf[j][k]);
    int nans = 0, tans = INF;
    rep(i, n){
        int temp = 0;
        rep(j, n) temp += wf[i][j];
        if(tans > temp){
            tans = temp;
            nans = i;
        }
    }
    cout << nans << " " << tans << endl;
    return 0;
}