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 <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct
{
    int to;
    int cost;
};

int N;
int d[50][50];

int main()
{
    while (cin >> N, N)
    {
        rep(i, 10) rep(j, 10) d[i][j] = iINF;
        rep(i, N)
        {
            int a, b, c;
            cin >> a >> b >> c;
            d[a][b] = c;
            d[b][a] = c;
        }

        rep(i, 10) d[i][i] = 0;

        rep(k, 10) rep(i, 10) rep(j, 10) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

        int ans = iINF, num;

        rep(i, 10)
        {
            int sum = 0;
            rep(j, 10)
            {
                if (d[i][j] == iINF)
                    break;
                sum += d[i][j];
            }

            if (sum < ans && sum != 0)
            {
                num = i;
                ans = sum;
            }
        }

        cout << num << " " << ans << endl;
    }
    return 0;
}

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

const int MAX_V = 10;
const int INF = 1 << 29;
const int MAX_N = 45;

int d[MAX_V + 1][MAX_V + 1];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		
		for(int i = 0; i != MAX_V; ++i){
			for(int j = 0; j != MAX_V; ++j){
				d[i][j] = INF;
				if(i == j)
					d[i][j] = 0;
			}
		}
		
		int v = 0;
		for(int i = 0; i != n; ++i){
			int a, b, c;
			cin >> a >> b >> c;
			v = max({a + 1, b + 1, v});
			d[a][b] = c;
			d[b][a] = c;
		}
		//cout << v << endl;
		//cout << INF*2 << endl;
		
		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]);
					//cout << d[i][j] << endl;
				}
			}
		}
		
		int m = INF;
		int now = -1;
		for(int i = 0; i != v; ++i){
			int sum = 0;
			for(int j = 0; j != v; ++j){
				sum += d[i][j];
			}
			if(m > sum){
				m = sum;
				now = i;
			}
			//cout << sum << endl;
		}
		
		cout << now << " " << m << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;

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

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		
		int dp[111][111]={0};
		rep(i,111)rep(j,111)dp[i][j]=1000000000;
		
		int m=0;
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			dp[a][b]=min(c,dp[a][b]);
			dp[b][a]=min(c,dp[a][b]);
			
			m=max(m,max(a,b));
		}
		m++;
		
		rep(i,111)dp[i][i]=0;
		
		rep(k,m){
			rep(i,m){
				rep(j,m){
					dp[i][j] = min(dp[i][k]+dp[k][j],dp[i][j]);
				}
			}
		}
		
		rep(i,m){
			rep(j,m){
				printf("%d ",dp[i][j]);
			}puts("");
		}
		
		
		int ans=1000000000;
		int minp=-1;
		rep(i,m){
			int sum=0;
			rep(j,m){
				if(dp[i][j]==1000000000)continue;
				sum+=dp[i][j];
			}
			ans = min(ans,sum);
			if(ans==sum){
				minp=i;
			}
		}
		printf("%d %d\n",minp,ans);
	}
}

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 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;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1ll << 60;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

#ifdef WIN32
#define dump(x) cout << #x << " = " << (x) << "\n"
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n"
#else
#define dump(x)
#define debug(x)
#endif

struct edge {
	int to;
	int cost;
	edge( int t, int c ) {
		to = t;
		cost = c;
	}
};
int n;
int r[ 10 ][ 10 ];
vector<edge> e[ 10 ];

void dijkstra( int s ) {
	fill( r[ s ], r[ s ] + 10, INF );
	priority_queue< PII, vector<PII>, greater<PII> > que;
	que.push( PII( s, 0 ) );
	while ( que.size() ) {
		int to = que.top().first;
		int cost = que.top().second;
		que.pop();
		if ( r[ s ][ to ] < cost ) {
			continue;
		}
		r[ s ][ to ] = cost;
		for ( int i = 0; i < e[ to ].size(); i++ ) {
			if ( r[ s ][ e[ to ][ i ].to ] > cost + e[ to ][ i ].cost ) {
				r[ s ][ e[ to ][ i ].to ] = r[ e[ to ][ i ].to ][ s ] = cost + e[ to ][ i ].cost;
				que.push( PII( e[ to ][ i ].to, cost + e[ to ][ i ].cost ) );
			}
		}
	}
}

int main() {
#ifdef WIN32
	printf( "Debug Mode\n" );
#endif
	while ( ~scanf( "%d", &n ) && n ) {
		for ( int i = 0; i < 10; i++ ) {
			e[ i ].clear();
		}
		int m = 0;;
		for ( int i = 0; i < n; i++ ) {
			int s, g, c;
			scanf( "%d %d %d", &s, &g, &c );
			m = max( max( s, g ), m );
			dump( m );
			e[ s ].push_back( edge( g, c ) );
			e[ g ].push_back( edge( s, c ) );
		}
		for ( int i = 0; i < 10; i++ ) {
			if ( e[ i ].size() ) {
				m = i;
			}
			else {
				break;
			}
		}
		int ans_cost = INF;
		int ans_t = 0;
		for ( int i = 0; i <= m; i++ ) {
			dijkstra( i );
		}
		for ( int i = 0; i <= m; i++ ) {
			int cost = 0;
			for ( int j = 0; j <= m; j++ ) {
				cost += r[ i ][ j ];
			}
			if ( ans_cost > cost ) {
				ans_cost = cost;
				ans_t = i;
			}
		}
		printf( "%d %d\n", ans_t, ans_cost );
	}
	return 0;
}