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 <fstream>
#include <string>
#include <sstream>
#include <math.h>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n ; i++)
#define pb push_back
static const int INF = 1000000;
static const int MAX = 100;

struct edge {int st, fin, cost;};

int d[MAX][MAX];

void floyd(int n){
  rep(k,n){
    rep(i,n){
      rep(j,n){
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  rep(i,n){
    rep(j,n){
    //  cout << d[i][j] <<  " ";
    }
  //  cout << endl;
  }
}

int main(void){
  int n;
  cin >> n;

  rep(i,10){
    rep(j,10){
      d[i][j] = ( ( i == j ) ? 0 : INF);
    }
  }

  int a,b,c;
  rep(i,n){
    cin >> a >> b >> c;
    d[a][b] = c;
    d[b][a] = c;
  }

  floyd(10);
  int sum = 0;
  int minsum = INF;
  int min_i = 0;

  rep(i,10){
    rep(j,10){
      if( d[i][j] != INF){
        sum += d[i][j];
      }
    }
    //cout << "from " << i << " " << sum << endl;
    if(minsum > sum && sum != 0){
      min_i = i;
      minsum = sum;
    }
    sum = 0;
  }
  cout << min_i << " " << minsum << endl;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

typedef vector< int > VI;
typedef vector< VI > VVI;
typedef vector< VVI > VVVi;

int main(){
	while(true){
		int n;
		cin >> n;

		if(n == 0){
			break;
		}

		VI start;
		VI goal;
		VI cost;

		int s, g, c;

		for(int i = 0; i < n; i++){
			cin >> s >> g >> c;
			start.push_back(s);
			goal.push_back(g);
			cost.push_back(c);
		}

		int town;

		for(int i = 0; i < n; i++){
			town = max(start[i], goal[i]);
		}
		town++;

		VVI map(town, VI(town, INT_MAX / 2));

		for(int i = 0; i < n; i++){
			map[start[i]][goal[i]] = cost[i];
			map[goal[i]][start[i]] = cost[i];
		}

		for(int i = 0; i < town; i++){
			map[i][i] = 0;
		}

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

		int num;
		int total = INT_MAX / 4;

		for(int i = 0; i < town; i++){
			int sum = 0;
			for(int j = 0; j < town; j++){
				sum += map[i][j];
			}

			if(sum < total){
				num = i;
				total = sum;
			}

		}

		cout << num << " " << total << endl;
	}
}

C++: #include <stdio.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define INF (10000000)


int main(void)
{
	int ans, ans_sum;
	int cost[10][10];
	int n;
	int city_cnt;
	
	while (1){
	scanf("%d", &n);
	
	if (n == 0){
		break;
	}
	
	REP(i, 10){
		REP(j, 10){
			if (i == j){
				cost[i][j] = 0;
			}
			else {
				cost[i][j] = INF;
			}
		}
	}
	
	city_cnt = 0;
	REP(i, n){
		int s, e, c;
		scanf("%d%d%d", &s, &e, &c);
		cost[s][e] = cost[e][s] = c;
		city_cnt = MAX(city_cnt, MAX(s, e));
	}
	city_cnt++;
	
	
	REP(i, city_cnt)REP(j, city_cnt)REP(k, city_cnt) cost[i][j] = MIN(cost[i][j], cost[i][k] + cost[k][j]);
	
	ans = -1;
	ans_sum = INF;
	REP(i, city_cnt){
		int sum = 0;
		REP(j, city_cnt){
			sum += cost[i][j];
		}
		if (ans_sum > sum){
			ans_sum = sum;
			ans = i;
		}
	}
	
	printf("%d %d\n", ans, ans_sum);
	
	}
	return (0);
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;


	while (cin >> n) {
		int min_ = 1000000000; // 答えの最小値
		int min_num = 1; // 答えの町
		int cost[100][100];
		int max_ = 0; // 町がどれだけあるか
		int from, to, time;

		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				cost[i][j] = 100000000;
			}
		}
		for (int i = 0; i < 100; i++) {
			cost[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> from >> to >> time;
			cost[from][to] = time;
			cost[to][from] = time;
			max_ = max(max(from, to), max_);
		}
		for (int i = 0; i <= max_; i++) {
			for (int j = 0; j <= max_; j++) {
				for (int k = 0; k <= max_; k++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		// 答えを求める
		for (int i = 0; i <= max_; i++) {
			int total = 0;
			for (int j = 0; j <= max_; j++) {
				total += cost[i][j];
			}
			if (total < min_) {
				min_ = total;
				min_num = i;
			}
		}
		cout << min_num << " " << min_ << endl;
  }
	return 0;
}

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

typedef vector <int> VI;
typedef vector <VI> VVI;

#define INF ( 1 << 21 )
#define NONE -1
#define NUM 10

VVI L;
VI E;

int get_length( int start, int goal )
{
	VI V( NUM, NONE );
	VI C( NUM, NONE );

	V[start] = 1;
	C[start] = 0;

	while ( 1 )
	{
		/* Cツづーツ更ツ新 */
		for ( int i = 0; i < NUM; i++ )
		{
			if ( E[i] == NONE ) continue;
			if ( V[i] == NONE ) continue;
			for ( int j = 0; j < NUM; j++ )
			{
				if ( E[j] == NONE ) continue;
				if ( V[j] != NONE ) continue;
				if ( L[i][j] == NONE ) continue;
				
				if ( C[j] == NONE )
					C[j] = C[i] + L[i][j];
				else
					C[j] = min( C[j], C[i] + L[i][j] );
			}
		}

		/* Vツづーツ更ツ新 */
		int min_no = NONE;
		int min_value = INF;
		for ( int i = 0; i < NUM; i++ )
		{
			if ( E[i] == NONE ) continue;
			if ( V[i] != NONE ) continue;
			if ( C[i] == NONE ) continue;

			if ( C[i] < min_value )
			{
				min_no = i;
				min_value = C[i];
			}
		}

		if ( min_no == NONE ) break;
		V[min_no] = 1;
	}

	return C[goal];
}

int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		L = VVI( NUM, VI( NUM, NONE ) );
		E = VI( NUM, NONE );

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

		int min_no = -1;
		int min_value = INF;
		for ( int i = 0; i < NUM; i++ )
		{
			if ( E[i] == NONE ) continue;
			int sum = 0;
			for ( int j = 0; j < NUM; j++ )
			{
				if ( i == j || E[j] == NONE ) continue;
				sum += get_length( i, j );
			}
			if ( sum < min_value )
			{
				min_no = i;
				min_value = sum;
			}
		}

		cout << min_no << " " << min_value << endl;
	}
	return 0;
}