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 <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	const int INF = 0xfffffff;

	for(int n; cin >> n, n;) {
		int m = 0;
		vector<vector<long long> > dist(10, vector<long long>(10, LLONG_MAX / 4));
		for(int i = 0; i < 10; ++i)
			dist[i][i] = 0;

		for(int i = 0; i < n; ++i) {
			int a, b, c;
			cin >> a >> b >> c;
			chmax(m, max(a, b));

			dist[a][b] = c;
			dist[b][a] = c;
		}

		++m;
		for(int i = 0; i < m; ++i)
			for(int j = 0; j < m; ++j)
				for(int k = 0; k < m; ++k)
					chmin(dist[i][j], dist[i][k] + dist[k][j]);

		int city;
		long long ans = LLONG_MAX;
		for(int i = 0; i < m; ++i) {
			long long sum = 0;
			for(int j = 0; j < m; ++j)
				sum += dist[i][j];

			if(ans > sum) {
				ans = sum;
				city = i;
			}
		}

		cout << city << " " << ans << endl;
	}


	return EXIT_SUCCESS;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#define inf 1000000000
using namespace std;
unsigned long long d[10][10],sum[10];
int v;

int main()
{
	int n;
	while(cin>>n,n)
	{
		bool used[10];
		memset(used,0,sizeof(used));
		memset(d,0,sizeof(d));
		memset(sum,0,sizeof(sum));
		for(int i=0;i<n;i++)
		{
			int s,t,c;
			cin>>s>>t>>c;
			used[s]=used[t]=true;
			d[s][t]=d[t][s]=c;
		}
		v=0;
		for(int i=0;i<10;i++)
		{
			if(used[i]) v++;
			for(int j=0;j<10;j++)
			{
				if(d[i][j]==0&&i!=j) d[i][j]=inf;
			}
		}

		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 ans;
		for(int i=0;i<v;i++)
		{
			for(int j=0;j<v;j++)
			{
				sum[i]+=d[i][j];
			}
		}
		ans=min_element(sum,sum+v)-sum;
		cout<<ans<<" "<<sum[ans]<<endl;

	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#define rep(i,a) for(int i=0;i<(a);++i)
const int INF = 1<<30;
#define _m_ 1
struct edge{int from, to, cost; };
typedef std::pair<int, int> P;

int V;
std::vector<edge> es;
int d[11];

int SP(int s){
	rep(i,11)d[i] = INF;
	d[s] = 0;
	while(_m_){
		bool update = false;
		rep(i, es.size()){
			edge e = es[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if(!update)break;
	}
	int res = 0;
	rep(i, 11){
		//if(i == s)continue;
		if(d[i] != INF)res += d[i];
	}
	return res;
}

int main(){
	int n;
	while(scanf("%d",&n) && n){
		for(int i = 0 ; i < n; ++i){
			int a, b, c;
			scanf("%d %d %d",&a, &b, &c);
			edge ac;
			ac.from = a, ac.to = b, ac.cost = c;
			edge bc;
			bc.from = b, bc.to = a, bc.cost = c;
			es.push_back(ac);
			es.push_back(bc);
		}
		V = n;
		P ans=P(0, SP(0));
		for(int i = 0; i < 11; ++i){
			if(ans.second > SP(i) && SP(i) != 0){
				ans.second = SP(i);
				ans.first = i;
			}
			//printf("%d %d\n", i,SP(i));
		}
		printf("%d %d\n", ans.first, ans.second);
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
const int INF=100000000;
int d[15][15];
void init()
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<i;j++)
		{
			d[i][j]=d[j][i]=INF;
		}
		d[i][i]=0;
	}
}
void floy(int s)
{
	for(int i=0;i<=s;i++)
	{
		for(int j=0;j<=s;j++)
		{
			for(int k=0;k<=s;k++)
			{
				d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
			}
		}
	}
}
int main()
{
	while(scanf("%d",&n)!=EOF&&n)
	{
		init(); 
		int m=0;
		for(int i=0;i<n;i++)
		{
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			d[x][y]=d[y][x]=min(d[x][y],z);
			m=max(max(m,x),y);
		}
		floy(m);
		int q=INF,p=0;
		for(int i=0;i<=m;i++)
		{
			int s=0;
			for(int j=0;j<=m;j++)
			{
				if(d[i][j]!=INF)
				s+=d[i][j];
			}
			if(s<q)
			{
				q=s;
				p=i;
			}
		}
		printf("%d %d\n",p,q);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
using namespace std;
#define inf 999999
int main(void)
{
    int x[110][110],y[110];
    int a,b,c,d,e,f,g,h,i,min;
    while(cin>>a)
    {
        b=0;
        if(a==0)
            break;
        for(c=0; c<110; c++)
            for(d=0; d<110; d++)
            {
                if(c==d)
                    x[c][d]=0;
                else
                    x[c][d]=inf;
            }
        for(c=0; c<110; c++)
            y[c]=0;
        for(c=0; c<a; c++)
        {
            cin>>d>>e>>f;
            if(d>b)
                b=d;
            if(e>b)
                b=e;
            x[d][e]=f;
            x[e][d]=f;
        }
        for(g=0; g<a; g++)
            for(h=0; h<a; h++)
                for(i=0; i<a; i++)
                    if(x[h][i]>x[h][g]+x[g][i])
                        x[h][i]=x[h][g]+x[g][i];
        for(g=0; g<=b; g++)
            for(h=0; h<=b; h++)
                y[g]=y[g]+x[g][h];
        min=y[0];
        for(g=1; g<=b; g++)
        {
            if(y[g]<min)
                min=y[g];
        }
        for(g=0; g<=b; g++)
        {
            if(y[g]==min)
                break;
        }
        printf("%d %d\n",g,min);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,l,r) for(int i = l; i <= r; i++)
#define TR(e,x) for(auto e = x.begin(); e != x.end(); e++)
#define DEBUG(x) cout << #x << "=" << x << endl;
#define SHOW1(A,n) { REP(i,n-1) printf("%d ", A[i]); printf("%d\n", A[n-1]); }
#define SHOW2(A,m,n) { REP(i,m) { REP(j,n-1) printf("%d ", A[i][j]); printf("%d\n", A[i][n-1]); } }
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)((x).size())
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN  = 50, INF = ~0U>>1, MOD = ~0U>>1;

int n, m, a[MAXN][MAXN];

int main()
{
#ifdef LOCAL
    //freopen("i.txt", "r", stdin);
    //freopen("o.txt", "w", stdout);
#endif //LOCAL

    while (scanf("%d", &n), n) {
        m = 0;
        REP(i,50)REP(j,50) a[i][j] = i==j ? 0:1e9;
        REP(i,n) {
            int x,y,z; scanf("%d%d%d", &x,&y,&z);
            a[x][y] = a[y][x] = z;
            m = max(m, x); m = max(m, y);
        }
        m++;
        REP(k,m)REP(i,m)REP(j,m) a[i][j] = min(a[i][j], a[i][k]+a[k][j]);
        int ans = 0, sum = INF;
        REP(i,m) {
            int cnt = 0;
            REP(j,m) cnt += a[i][j];
            if (cnt < sum) sum = cnt, ans = i;
        }
        printf("%d %d\n", ans, sum);
    }

    return 0;
}