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> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate

using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
//#define TEST //*******************************************************************************************************************************************

//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
#ifdef TEST
    #define dout cout
#else
    stringstream dummy; //???????????°??????dout?????????????????????????????????
    #define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
    //???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif


#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << (A) << " "
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl









////////////////////////////////////////
//AIZU
//Convenient Location
//
//??????????????????
//
//
////////////////////////////////////////

const int INF = 1e9-1;

int main(void) {
    
    int N = 10; //????????°????????§??§???10
    int M; //?????°
    int a, b, c;
    
    int d[N][N]; //0~9??????????????????
    int sumTotalCost[N]; //sumTotalCost[i] = i????????§?????????????????????????????????????????¢?????????????????????????????????????°???????ans??¨??????
    
    
    while(1) {
        cin >> M;
        if( M== 0 ) break;
        
        //initialization
        rep(i,0,N) {
            rep(j,0,N) {
                d[i][j] = (i==j ? 0 : INF);
            }
        }
        
        rep(i,0,N) {
            sumTotalCost[i] = 0;
        }
        
        
        rep(i,0,M) {
            cin >> a >> b >> c; //??????a??????b?????§????????????t
            
            d[a][b] = d[b][a] = c;
        }
        
        //test display
        rep(i,0,N) {
            disP(i);
            dispAll(d[i], N);
        }
        dout << endl;
        
        //Warshall Floyd Algorithm
        rep(i,0,N) {
            rep(j,0,N) {
                rep(k,0,N) {
                    d[i][j] = min( d[i][j], d[i][k] + d[k][j] );
                }
            }
        }
        
        //test display
        rep(i,0,N) {
            disP(i);
            dispAll(d[i], N);
        }
        dout << endl;
        
        
        //??????????????????????????????????????????????±???????
        rep(i,0,N) {
            rep(j,0,N) {
                sumTotalCost[i] += ( d[i][j]==INF ? 0 : d[i][j] ); //INF???????????????INF??\????????°???????¶?????????????
            }
        }
        
        //test display
        dispAll(sumTotalCost, N);
        dout << endl;
        
        
        //????????????????????????????°???¨?????????????±???????
        int ans = INF;
        int ans_Origin = 0;
        rep(i,0,N) {
            if( ans > sumTotalCost[i] && sumTotalCost[i] != 0 ) { //???????????¨????????????i???sumTotal???0????????§???0?????????????????????
                ans = sumTotalCost[i];
                ans_Origin = i;
            }
        }
        
        disp(ans_Origin);
        dout << "??????????????¨??????????????????????????????????°???¨???????????????????????????????????????\n";
        disp(ans);
        dout << "??¨?????????\n";
        
        cout << ans_Origin << " " << ans << endl;
        
    }
    
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 305
using namespace std;
bool debug=false;

int d[12][12];

void init(){
  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;
    }
  }
}

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

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

void solve(){
  int mini=INF,num;
  for(int i=0;i<=10;i++){
    int sum=0;
    for(int j=0;j<=10;j++){
      if(d[i][j]!=INF)sum+=d[i][j];
    }
    if(sum<=mini&&sum!=0){
      mini=sum;
      num=i;
    }
  }
  cout<<num<<" "<<mini<<endl;
}

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    init();
    make(n);
    wf();
    solve();
  }
  return 0;
}

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

const int INF = 1000000000;

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

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;

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

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

		int minT[m][m];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				minT[i][j]=T[i][j];
			}
		}

		for(int k=0; k<m; k++){
			for(int i=0; i<m; i++){
				for(int j=0; j<m; j++){

					if(minT[i][j]>minT[i][k]+minT[k][j])
						minT[i][j]=minT[i][k]+minT[k][j];
				}
			}
		}

		int d[m];
		for(int i=0; i<m; i++){
			d[i]=0;
			for(int j=0; j<m; j++){
				d[i]=d[i]+minT[i][j];
			}
		}
		

		int min=0;
		for(int i=1; i<m; i++){
			if(d[min]>d[i])
				min=i;
		}

		cout <<min<<' '<<d[min]<<endl;

	}

	return 0;
}