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<algorithm>
#include<string.h>
#include<set>
#define MAX_N 6
#define INF 10000
using namespace std;
int d[MAX_N][MAX_N];
int N;
void floyed(int  X) {
	for (int k = 0; k<X; k++) {
		for (int i = 0; i<X; i++) {
			for (int j = 0; j<X; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}
int main() {
	while (true) {
		set<int> s;
		cin >> N;
		if (N <= 0)
			break;
		for (int i = 0; i<MAX_N; i++) {
			for (int j = 0; j<MAX_N; j++) {
				d[i][j] = INF;
				if (i == j)
					d[i][j] = 0;
			}
		}
		
		for (int i = 0; i<N; i++) {
			int from, to, costs;
			cin >> from >> to >> costs;
			d[from][to] = costs;
			d[to][from] = costs;
			s.insert(to);
			s.insert(from);
		}
		floyed(s.size());
		int misum = INF;
		int no;
		for (int i = 0; i<s.size(); i++) {
			int sum = 0;
			for (int j = 0; j<s.size(); j++) {
				if (i != j&&d[i][j]!=INF)
					sum += d[i][j];
			}
			if (sum < misum) {
				misum = sum;
				no = i;
			}
		}
	/*	for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++)
				cout << d[i][j] << " ";
			cout << endl;
		}*/
		cout << no<<" "<<misum << endl;
		
	}
	
}

C++: // AOJ 0189
#include<cstdio>
#include<algorithm>
#include<numeric>
#define rep(i,a) for( int i = 0; i != (a); ++i )

const int INF = 1 << 29;

int d[10][10];

int main()
{
	int n;
	while( scanf( "%d", &n ), n )
	{
		rep( i, 10 )
			rep( j, 10 )
				d[i][j] = i==j?0:INF;

		int v = 0;
		rep( i, n )
		{
			int a, b, c;
			scanf( "%d%d%d", &a, &b, &c );
			d[a][b] = d[b][a] = c;
			v = std::max( v, std::max( a, b ) );
		}

		rep( k, v+1 )
			rep( i, v+1 )
				rep( j, v+1 )
					d[i][j] = std::min( d[i][j], d[i][k]+d[k][j] );
	
		int ans = INF, id;
		rep( i, v+1 )
		{
			int s = std::accumulate( d[i], d[i]+v+1, 0 );

			if( ans > s )
				ans = s, id = i;
		}

		printf( "%d %d\n", id, ans );
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };


int n, s, g, c;

VVI _map;

void warshall_floyd( VVI &root ) {
	for ( int i = 0; i < root.size(); i++ ) {
		for ( int j = 0; j < root.size(); j++ ) {
			for ( int k = 0; k < root.size(); k++ ) {
				root[ j ][ k ] = root[ k ][ j ] = min( root[ j ][ k ], root[ j ][ i ] + root[ i ][ k ] );
			}
		}
	}
}

int gcd( int n, int m ) {
	if ( m == 0 ) {
		return n;
	}
	return gcd( m, n % m );
}

void make_prime( VI &pm, int max ) {
	vector<bool> is_pm( max + 1, true );
	is_pm[ 0 ] = is_pm[ 1 ] = false;
	for ( int i = 2; i * i <= max; i += 2 ) {
		if ( is_pm[ i ] ) {
			for ( int j = i * i; j <= max; j += i ) {
				is_pm[ j ] = false;
				if ( i != 2 ) {
					j += i;
				}
			}
			if ( i == 2 ) {
				--i;
			}
		}
	}
	for ( int i = 2; i <= max; i += 2 ) {
		if ( is_pm[ i ] ) {
			pm.push_back( i );
			if ( i == 2 ) {
				--i;
			}
		}
	}
}


int main() {
	while ( ~scanf( "%d", &n ) && n ) {
		_map.resize( 100 );
		for ( int i = 0; i < 100; i++ ) {
			_map[ i ].resize( 100 );
			for ( int j = 0; j < 100; j++ ) {
				if ( i == j ) {
					_map[ i ][ j ] = 0;
				}
				else {
					_map[ i ][ j ] = INF;
				}
			}
		}
		int max_town = 0;
		for ( int i = 0; i < n; i++ ) {
			scanf( "%d %d %d", &s, &g, &c );
			_map[ s ][ g ] = _map[ g ][ s ] = c;
			max_town = max( max_town, max( g, s ) + 1 );
		}
		warshall_floyd( _map );
		int ans_cost = INF, ans_town;
		for ( int i = 0; i < max_town; i++ ) {
			int cost = 0;
			for ( int j = 0; j < max_town; j++ ) {
				cost += _map[ i ][ j ];
			}
			if ( ans_cost > cost ) {
				ans_cost = cost;
				ans_town = i;
			}
		}
		printf( "%d %d\n", ans_town, ans_cost );
	}
	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 15;
int inf = 0x3fffffff;
int dist[N][N];

int main(void){
  int n;
  while(cin >> n) {
    int nt = 0;
    if (n == 0) { break; }
    REP(i, 0, N) {
      REP(j, 0, N) {
	dist[i][j] = i == j ? 0 : inf;
      }
    }
    REP(i, 0, n) {
      int a, b, c;
      cin >> a >> b >> c;
      nt = max(nt, max(a, b) + 1);
      dist[a][b] = min(dist[a][b], c);
      dist[b][a] = min(dist[b][a], c);
    }
    REP(k, 0, nt) {
      REP(i, 0, nt) {
	REP(j, 0, nt) {
	  dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	}
      }
    }
    int mi = inf, mini = -1;
    REP(i, 0, n) {
      int tot = 0;
      REP(j, 0, nt) {
	tot += dist[i][j];
      }
      if (mi > tot) {
	mi = tot;
	mini = i;
      }
    }
    cout << mini << " " << mi << endl;
  }
}