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<cstdio>
#include<cstdlib>
#include<math.h>
#include<iostream>
#include<cstring>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<algorithm>
#include<queue>
#include<vector>
#include<time.h>
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
const int INF=1<<30;
typedef long long ll;
const double eps = 1e-8;
const int row=3000;
const int cow=220;
const int MAXN=cow*cow;

int n,m;

int dp[20][20];

int main()
{
    //freopen("1","r",stdin);
    int i,j,t;
    while(scanf("%d",&m)!=EOF&&m){
        memset(dp,-1,sizeof(dp));
        n=0;
        for(i=0;i<m;i++){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            dp[a][b]=dp[b][a]=c;
            n=max(n,max(a,b)+1);
        }
        for(i=0;i<n;i++)dp[i][i]=0;
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                for(t=0;t<n;t++){
                    if(dp[i][j]!=-1&&dp[j][t]!=-1){
                        if(dp[i][t]==-1)dp[i][t]=dp[i][j]+dp[j][t];
                        else dp[i][t]=min(dp[i][t],dp[i][j]+dp[j][t]);
                    }
                }
            }
        }
        int ans=INF,ob=0;
        for(i=0;i<n;i++){
            int tem=0;
            for(j=0;j<n;j++){
                if(i==j)continue;
                tem+=dp[i][j];
            }
            //cout<<tem<<endl;
            if(tem<ans){
                ans=tem;
                ob=i;
            }
        }
        printf("%d %d\n",ob,ans);
    }
    return 0;
}

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

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

using namespace std;

int costs[11][11];

int main()
{
	int N;
	while(cin>>N,N)
	{
		rep(i,11)rep(j,11)costs[i][j]=INF;
		rep(i,11)costs[i][i]=0;

		int n_city = 0;
		rep(i,N)
		{
			int a, b, c;
			cin>>a>>b>>c;
			costs[a][b] = costs[b][a] = c;
			n_city = max(n_city, max(a, b));
		}
		n_city++;

		rep(k,n_city)rep(i,n_city)rep(j,n_city)
		{
			costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]);
		}

		int min_cost = INF, min_city = -1;
		rep(i,n_city)
		{
			int sum = 0;
			rep(j,n_city) sum += costs[i][j];
			if (sum < min_cost)
			{
				min_cost = sum;
				min_city = i;
			}
		}
		cout << min_city << " " << min_cost << endl;
	}
	return 0;
}

C++: //2015.6.16 「Convenient Location」
#include<iostream>
using namespace std;

const int INF = 1000000;

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){		//aが大きい数の町の時		
				m=a+1;
			}
			if(b+1>m){		//bが大きい数の町の時	
				m=b+1;
			}
		}
	
		//ワーシャル-フロイト法
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}

	
		int machi=0;
		int time=INF;
		int time2=0;

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


			if(time>time2){
				time=time2;
				machi=i;
			}
			time2=0;
			

		}
		
		cout << machi << ' ' << time << '\n'; 
	
	}
			

		return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define LATTE 1000000000

int main(){
	int N;
	while(cin>>N,N){
		int dp[10][10]={},A,B,C;
		bool latte[10]={};
		for(int i=0;i<10;i++)for(int j=0;j<10;j++) if(i!=j) dp[i][j]=LATTE;
		for(int i=0;i<N;i++){
			cin>>A>>B>>C;
			dp[A][B]=dp[B][A]=C;
			latte[A]=latte[B]=true;
		}
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
				}
			}
		}
		int _min=LATTE,ans;
		for(int i=0;i<10;i++){
			if(!latte[i]) continue;
			int sum=0;
			for(int j=0;j<10;j++){
				if(!latte[j]) continue;
				if(dp[i][j]==LATTE){
					sum=LATTE;
					break;
				}
				else sum += dp[i][j];
			}
			if(_min>sum){
				_min = sum; ans = i;
			}
		}
		printf("%d %d\n",ans,_min);
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

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

const int MAXN = 50, MAXT = 11, INF = (10000);
int d[MAXT][MAXT];
int times[MAXT];
int a, b, c, t;
int anst, ansc;

int main()
{
    int n;
    while(cin >> n && n)
    {
        memset(d, INF, sizeof(d));
        memset(times, 0, sizeof(times));
        t = 0;

        REP(MAXT) d[i][i] = 0;

        REP(n)
        {
            cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
            t = max(t, a + 1);
            t = max(t, b + 1);
        }
        anst = t;
        ansc = INF;
        //cout << "town"<<t << endl;

        rep(k,t)rep(i,t)rep(j,t)
        {
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }

        rep(i,t)rep(j,t)
        {
            times[i] += d[i][j];
            //cout << i << "to" << j << " " << d[i][j] << endl;
        }

        rep(i,t)if( ansc > times[i]) {anst = i; ansc = times[i];}

        cout << anst << " " << ansc << endl;
    }
    return 0;
}