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<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

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

const int TOWN = 11;
const int ROAD = 50;
const int INF = 10000;

int d[TOWN][TOWN] ;

int n,a,b,c;
int main()
{
	while(cin >> n && n)
	{
		memset(d,INF,sizeof(d));
		int townnum = 0;
		REP(n)
		{
			cin>> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
			d[i][i] = 0;
			townnum = max(townnum,a);
			townnum = max(townnum,b);
		}
		//cout << "town "<<townnum << endl;
		rep(k,townnum+1)rep(i,townnum+1)rep(j,townnum+1)//if(d[i][j] != INF)
		{
			d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			d[j][i] = d[i][j];
		}
		int time = 1000000,town = 0;
		
		rep(i,townnum+1)//town i
		{
			int sum = 0;
			rep(j,townnum+1) sum += d[i][j];//i to j
			//cout << sum << endl;
			if(sum < time){ time = sum; town = i;}
		}
		cout << town << " " << time << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int dp[50][50];
int main()
{
    int n;
    while(scanf("%d", &n), n)
    {
        memset(dp, 50, sizeof(dp));
        for(int i = 0; i < n; i++)
        {
            int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
            dp[a][b] = dp[b][a] = min(dp[a][b], c);
        }
        for(int k = 0; k <= 15; k++)
            for(int i = 0; i <= 15; i++)
                for(int j = 0; j <= 15; j++)
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
        int a = 0, b = 10000;
        for(int i = 0; i <= 15; i++)
        {
            int tmp = 0;
            for(int j = 0; j <= 15; j++)
            {
                if(dp[i][j] < 1000000 && j != i)
                    tmp += dp[i][j];
            }
            if(tmp && tmp < b)
            {
                a = i;
                b = tmp;
            }
        }
        printf("%d %d\n", a, b);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1e9 + 5
using namespace std;
const int maxn = 15;
const int maxm = 50;
int mp[maxn][maxn];
int a[maxm],b[maxm],c[maxm];
int n,m;

void init()
{
	for(int i = 0;i <= n;i++)
	for(int j = 0;j <= n;j++)
	if(i == j) mp[i][j] = 0;
	else       mp[i][j] = INF;
}

void floyd()
{
	for(int k = 0;k <= n;k++)
	for(int i = 0;i <= n;i++)
	for(int j = 0;j <= n;j++)
	mp[i][j] = min(mp[i][j],mp[i][k] + mp[k][j]);
}

int main()
{
	while(scanf("%d",&m) != EOF && m){
		n = 0;
		for(int i = 0;i < m;i++){
			scanf("%d %d %d",&a[i],&b[i],&c[i]);
			n = max(n,max(a[i],b[i]));
		}
		init();
		for(int i = 0;i < m;i++){
			mp[a[i]][b[i]] = min(mp[a[i]][b[i]],c[i]);
			mp[b[i]][a[i]] = min(mp[b[i]][a[i]],c[i]);
		}
		floyd();
		int minsum,nowsum,pos;
		minsum = nowsum = INF;
		for(int i = 0;i <= n;i++){
			nowsum = 0;
			for(int j = 0;j <= n;j++){
				nowsum += mp[i][j];
			}
			if(minsum > nowsum){
				minsum = nowsum;
				pos = i;
			}
		}
		printf("%d %d\n",pos,minsum);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, a, b, c, dp[111][111], eki, an[3], ans;
	while (1) {
		eki = 0;
		cin >> n;
		if (n == 0) {
			goto a;
		}
		for (int i = 0; i <= 88; i++) {
			for (int z = 0; z <= 88; z++) {
				dp[i][z] = 9999999;
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> a >> b >> c;
			dp[a][b] = c;
			dp[b][a] = c;
			eki = max(eki, max(a, b));
		}
		for (int i = 0; i <= eki; i++) {
			dp[i][i] = 0;
		}
		for (int i = 0; i <= eki; i++) {
			for (int z = 0; z <= eki; z++) {
				for (int m = 0; m <= eki; m++) {
					dp[i][z] = min(dp[i][z], dp[i][m] + dp[m][z]);
				}
			}
		}
		ans = 0;
		an[2] = 9999999;
		for (int i = eki; i >= 0; i--) {
			ans = 0;
			for (int z = 0; z <= eki; z++) {
				if (i == z) {

				}
				else {
					ans += dp[i][z];
				}
			}
			if (an[2] >= ans) {
				an[2] = ans;
				an[1] = i;
			}
		}
		cout << an[1] << " " << an[2] << endl;
	}
a:;
}

C++: #include <iostream>

using namespace std;

int main() {
	int M;
	while (cin >> M, M) {
		bool v[10] = {0};
		int n = 10;
		int m[20][20]; fill(&m[0][0], &m[0][0]+20*20, 1e9);
		for (int i = 0; i < M; ++i) {
			int a, b, c; cin >> a >> b >> c;
			m[a][b] = m[b][a] = c;
			v[a] = v[b] = true;
		}
		for (int i = 0; i < n; ++i) m[i][i] = 0;

		for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
			m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
		}

		int ans = 1e9, aid = -1;
		for (int i = 0; i < n; ++i) {
			if (v[i]) {
				int s = 0;
				for (int j = 0; j < n; ++j) if (v[j]) s += m[i][j];
				if (s < ans) ans = s, aid = i;
			}
		}
		cout << aid << " " << ans << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<bits//stdc++.h>
#include<functional>
using namespace std;
struct P{
	long long cost,pos;
};
struct B{
	long long cost,to;
};
bool operator<(P a,P b){
	return a.cost<b.cost;
}
bool operator>(P a,P b){
	return a.cost>b.cost;
}
vector<B>e[10];
int main() {
	int n;
	while(cin>>n&&n!=0){
		for(int i=0;i<10;i++) e[i].clear();
		long long a,b,c,ma=0;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			e[a].push_back(B{c,b});
			e[b].push_back(B{c,a});
			ma=max(a,max(b,ma));
		}
		P sum;
		sum.cost=1000000;
		for(int i=0;i<=ma;i++){
			priority_queue<P, vector<P>, greater<P>>p;
			long long b[10];
			for(int j=0;j<10;j++) b[j]=1000000;
			b[i]=0;
			p.push(P{0,i});
			while(!p.empty()){
				P t=p.top();p.pop();
				for(int j=0;j<(int)e[t.pos].size();j++){
					if(b[t.pos]+e[t.pos][j].cost<b[e[t.pos][j].to]){
						b[e[t.pos][j].to]=b[t.pos]+e[t.pos][j].cost;
						p.push(P{b[e[t.pos][j].to],e[t.pos][j].to});
					}
				}
			}
			long long sum2=0;
			for(int j=0;j<=ma;j++){
				sum2+=b[j];
			}
			if(sum.cost>sum2){
				sum.cost=sum2;
				sum.pos=i;
			}
		}
		cout<<sum.pos<<" "<<sum.cost<<endl;
	}
}