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 <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
	int n;
	while (cin >> n, n)
	{
		int cost[15][15];
		REP(i, 15)REP(j, 15) cost[i][j] = (i == j ? 0 : INF);
		int a, b, c;
		int city = 0;
		REP(i, n)
		{
			cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
			city = max({ city, a, b });
		}
		city++;
		REP(k, n)REP(i, n)REP(j, n) cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
		int sum[15] = {};
		REP(i, city)
		{
			REP(j, city) sum[i] += cost[i][j];
		}
		int ans; int anssum = INF;
		REP(i, city)
		{
			if (anssum > sum[i])
			{
				ans = i;
				anssum = sum[i];
			}
		}
		cout << ans << " " << anssum << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                             it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

const int NO = 1000000000;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        vector<pair<pair<int,int>,int> > R;
        int m=0;
        rep(i,n){
            int a,b,c;
            cin >> a >> b >> c;
            m = max(m,max(a,b));
            R.push_back(mp(mp(a,b),c));
        }
        m++;
        vector<vector<int> > V(m,vector<int>(m,NO));

        rep(i,m){
            V[i][i] = 0;
        }

        rep(i,n){
            int a = R[i].first.first;
            int b = R[i].first.second;
            int c = R[i].second;
            V[a][b] = V[b][a] = c;
        }


        cerr << __LINE__ << endl;

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

        int ret = -1;
        int mi = NO;

        for(int i=0;i<m;i++){
            int s = 0;
            for(int j=0;j<m;j++){
                s += V[i][j];
            }
            if(mi > s){
                mi = s;
                ret = i;
            }
        }
        cout << ret << " " << mi << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;

const int MAX_TOWN = 10;
const int INF = 1000000;

int dist[MAX_TOWN][MAX_TOWN];

void minify() {
  for (int k = 0; k < 10; k++)
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int sum_of_dist(int t) {
  int sum = 0;
  for (int i = 0; i < 10; i++)
    sum += (dist[t][i] == INF)? 0:dist[t][i];

  return (sum == 0)? INF:sum;
}

int main() {
  int n;
  while (cin >> n and n != 0) {
    int a, b, c;

    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = (i == j)? 0:INF;

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c;
      dist[a][b] = dist[b][a] = c;
    }

    minify();

    int min_dist = INF, min_town = 0;
    for (int t = 0; t < 10; t++) {
      if (min_dist > sum_of_dist(t)) {
        min_town = t;
        min_dist = sum_of_dist(t);
      } 
    }

    cout << min_town << " " << min_dist << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#define INF 4505

using namespace std;
int n,a,b,c;
int d[10][10];
int main()
{
    while(cin>>n&&n)
    {
        int m=-1;
        for(int i=0;i<10;i++)
            for(int j=0;j<10;j++)
        {
            if(i==j) d[i][j]=0;
            else d[i][j]=INF;
        }
        for(int i=0;i<n;i++)
        {
            cin>>a>>b>>c;
            m=max(m,max(a,b));
            d[a][b]=d[b][a]=c;
        }
        for(int k=0;k<=m;k++)
            for(int i=0;i<=m;i++)
            for(int j=0;j<=m;j++)
        {
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        }
        int p,minsum=INF;
        for(int i=0;i<=m;i++)
        {
            int sum=0;
            for(int j=0;j<=m;j++)
                sum+=d[i][j];
            if(minsum>sum)
            {
                p=i;
                minsum=sum;
            }
        }
        cout<<p<<" "<<minsum<<endl;
    }
    return 0;
}