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++: #pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e2+5;
const int mod = 1e6;
const double eps = 1e-8;
const double pi = asin(1.0)*2;
const double e = 2.718281828459;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}

int n;
int a, b, c;
int ans;
int city;
int num;
int plat[maxn][maxn];
int sum[maxn];

inline int max(int a, int b, int c) {
	return max(max(a, b), c);
}

void Floyd() {
	for (int k = 0; k <= num; ++k) {
		for (int i = 0; i <= num; ++i) {
			for (int j = 0; j <= num; ++j) {
				if (i == j) {
					plat[i][j] = 0;
					continue;
				}
				plat[i][j] = min(plat[i][j], plat[i][k] + plat[k][j]);
			}
		}
	}
}

int main(int argc, char *argv[]) {
//#ifndef ONLINE_JUDGE
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
//#endif
	while (~scanf("%d", &n), n) {
		mem(plat, INF);
		num = 0;
		for (int i = 1; i <= n; ++i) {
			read(a); read(b); read(c);
			plat[a][b] = c;
			plat[b][a] = c;
			num = max(num, a, b);
		}
		Floyd();
		mem(sum, 0);
		ans = INF;
		for (int i = 0; i <= num; ++i) {
			for (int j = 0; j <= num; ++j) {
				sum[i] += plat[i][j];
			}
			if (sum[i] < ans) {
				ans = sum[i];
				city = i;
			}
		}
		printf("%d %d\n", city, ans);
	}
//#ifndef ONLINE_JUDGE
//	fclose(stdin);
//	fclose(stdout);
//	system("gedit out.txt");
//#endif
    return 0;
}

C++: #include<iostream>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>

using namespace std;


int main(){

    long long n;
    vector< vector<long long> > map(100,vector<long long>(100));
    long long a,b,c;
    vector<long long> v(100);
    fill(v.begin(),v.end(),1<<20);
    while(true){
	fill(map.begin(),map.end(),v);
	cin >> n;
	long long ma=0;
	if(n == 0) break;
	for(long long i=0;i<n;i++){
	    cin >> a >> b >> c;
	    map[a][b] = c;
	    map[b][a] = c;
	    ma = max(ma,b);
	}
	for(long long i=0;i<ma;i++){
	    map[i][i] = 0;
	}
	ma++;
	for(int l = 0;l<2;l++){
	for(long long i=0;i<ma;i++){
	    for(long long j=0;j<ma;j++){
		for(long long k=0;k<ma;k++){
			map[i][j] = min(map[i][j] ,map[i][k] + map[k][j] );
		}
	    }
	}
	}

	long long res = 1<<30,t=0;
	for(long long i=0;i<ma;i++){
	    a =0;
	    for(long long j=0;j<ma;j++){
		a += map[i][j];
	    }
	    if(a!=0 && res>a){
		res = a;
		t = i;
	    }
	}
	cout << t<<" " << res << endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

const int MAXT = 11, MAXN = 45, INF = 10000;

int cost[MAXT][MAXT];
int d[MAXT];
bool used[MAXT];
int a, b, c, t, n, anst, ansc, tcost;

int main()
{
    while(cin >> n && n)
    {
        memset(cost, INF, sizeof(cost));
        t = 0;

        REP(n)
        {
            cin >> a >> b >> c;
            cost[a][b] = cost[b][a] = c;
            t = max(t, a+1);
            t = max(t, b+1);
        }
        anst = MAXT, ansc =INF;

        rep(k,n)
        {
            memset(d, INF, sizeof(d));
            memset(used, false, sizeof(used));

            d[k] = 0;
            tcost = 0;
            
            while(true)
            {
                int v = -1;
                rep(i,t)if(!used[i] && (v == -1 || d[i] < d[v])) v = i;
                
                if(v == -1) break;

                used[v] = true;
                rep(i,t) d[i] = min(d[i], d[v] + cost[v][i]);

            }
            REP(t) tcost += d[i];
            if(tcost < ansc) { anst = k; ansc = tcost;}
        }
        cout << anst <<" " << ansc << endl;

    }

    return 0;
}

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;
			}
		}
		
		int d[m];
		for(int i=0; i<m; i++)
			d[i]=0;
			
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				for(int k=0; k<m; k++){
					if(T[j][k]>T[j][i]+T[i][k]){
						T[j][k]=T[j][i]+T[i][k];
					}
				}
			}
		}
		
		int min,num;
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				d[i]+=T[i][j];
			}
			if(min>d[i] || i==0){
				min=d[i];
				num=i;
			}
		}
		cout<<num<<' '<<min<<endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int G[15][15];
bool solve()
{
    //initialization
    const int INF = 1000000;
    for(int i = 0; i < 15; i++)
        for(int j = 0; j < 15; j++)
        G[i][j] = INF;
    int n = 0, x = 0, y = 0, c = 0;
    cin >> n;
    if(n == 0) return false;
    for(int i = 1; i <= n; i++)
    {
        cin >> x >> y >> c;
        G[x][y] = G[y][x] = c;
    }
    //floyd
    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 = INF, ansmt = 0;
    for(int i = 0; i < 10; i++)
    {
        int tmp = 0;
        for(int j = 0; j < 10; j++)
            if(i != j && G[i][j] != INF) tmp += G[i][j];
        if(tmp != 0 && tmp < ans) {ans = tmp; ansmt = i;}
    }
    cout << ansmt << " " << ans << endl;
    return true;
}
int main()
{
    while(solve()) ;
    return 0;
}