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++: 
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define vc vector

const int INF = 100000000;

using namespace std;


int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)break;
		vector<vector<int>> v(10, vector<int>(10, INF));

		int maxnum=0;
		rep(i, 0, n) {
			int from, to, cost;
			cin >> from >> to >> cost;
			v[from][to] = cost;
			v[to][from] = cost;

			if (maxnum < to)maxnum = to;
			v[i][i] = 0;
		}
		maxnum++;

		rep(i, 0, maxnum) {
			rep(j, 0,maxnum) {
				rep(k, 0, maxnum) {
					v[j][k] = min(v[j][k], v[j][i] + v[i][k]);
				}
			}
		}

		/*rep(i, 0, maxnum) {
			rep(j, 0, maxnum) cout << i << " " << j << " " << v[i][j] << endl;
		}*/

		int ans = INF, ansnum;
		rep(i, 0, maxnum) {
			int sum = 0;
			rep(j, 0, maxnum) {
				if(i!=j && v[i][j]!=INF)sum += v[i][j];
			}
			if (ans > sum) {
				ans = sum;
				ansnum = i;
			}
		}

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

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
const lnt INF = 0xffffffffffffff;
lnt d[10][10];
lnt n,x,y,z;
lnt used[10];
int main()
{while(1){

	cin>>n;
	if(!n) return 0;
	fill(d[0],d[10]+10,INF);
	fill(used,used+10,0);
	for(lnt i=0;i<n;i++){
		cin>>x>>y>>z;
		used[x]=1;
		used[y]=1;
		d[x][y]=z;
		d[y][x]=z;
	}
	for(lnt i=0;i<10;i++){
		if(used[i]) d[i][i]=0;
	}
	for(lnt k=0;k<10;k++){
		for(lnt i=0;i<10;i++){
			for(lnt j=0;j<10;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	P ans=P(-1,INF);
	lnt sum;
	for(lnt i=0;i<10;i++){
		if(!used[i]) continue;
		sum=0;
		for(lnt j=0;j<10;j++){
			if(!used[j]) continue;
			sum+=d[i][j];
		}
		if(ans.second>sum){
			ans.first=i;
			ans.second=sum;
		}
	}
	cout<<ans.first<<' '<<ans.second<<endl;
}}

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

int main(){
  while(true){
    int n;
    cin >> n;
    if(n==0){
      break;
    }

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

    int a,b,cost,m=0;
    for(int i=0; i<n; i++){
      cin >> a >> b >> cost;
      T[a][b] = T[b][a] = cost;

      if(m<a){
        m=a;
      }
      if(m<b){
        m=b;
      }
    }

    for(int k=0; k<m+1; k++){
      for(int i=0; i<m+1; i++){
        for(int j=0; j<m+1; j++){
            if(T[i][j] > T[i][k] + T[k][j]){
              T[i][j] = T[i][k] + T[k][j];
            }
        }
      }
    }

  //  cout << "ekinokazu " << m << endl;
    int total=0,total2=10000,nummber;

    for(int i=0; i<m+1; i++){   //どこの駅から始まるか
      for(int j=0; j<m+1; j++){   //どこの駅で終わるか
        total = total + T[i][j];
        //cout << i << "駅start" << j << "駅まで " << T[i][j] << endl;
        if(j==m){
          //cout << i << "駅start " << total << endl;
          if(total2>total){
            total2 = total;
            nummber = i;
          }
          total = 0;
        }
      }
    }
    cout << nummber << ' ' << total2 << endl;

  }

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<cstdio>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007
#define ARRAY_MAX 30
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

int n;
int dp[ARRAY_MAX][ARRAY_MAX];

void warshal_floyd(){
    REP(k,10){
        REP(i,10){
            REP(j,10){
                dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
            }
        }
    }
}

int main(){

    while(cin >> n,n){
        int maxi_town_number = -1;
        REP(i,ARRAY_MAX){
            REP(j,ARRAY_MAX){
                dp[i][j] = INF;
                if(i == j){
                    dp[i][j] = 0;
                }
            }
        }
        REP(i,n){
            int a,b,c;
            cin >> a >> b >> c;
            maxi_town_number = max(maxi_town_number,max(a,b));
            dp[a][b] = c;
            dp[b][a] = c;
        }
        warshal_floyd();
        int mini_town = INF;
        int maxi = INF;

        REP(i,maxi_town_number+1){
            int sum = 0;
            //i番目の町に住んでいる
            REP(j,maxi_town_number+1){
                if(dp[i][j] != INF){
                    sum += dp[i][j];
                }
            }
            if(sum < maxi){
                maxi = sum;
                mini_town = i;
            }
        }   
        cout << mini_town << " " << maxi << endl;
    }



    return 0;
}

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

const int INF = 1<<28;

int main(){
    int n,i,j,k,a,b,c;
    while( cin >> n, n ){
        int cost[10][10];
        for(i=0;i<10;i++){
            for(j=0;j<10;j++){
                cost[i][j] = INF;
                if(i==j) cost[i][j] = 0;
            }
        }
        for(i=0;i<n;i++){
            cin >> a >> b >> c;
            cost[a][b] = cost[b][a] = c;
        }
        for(k=0;k<10;k++){
            for(i=0;i<10;i++){
                for(j=0;j<10;j++){
                    cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
                }
            }
        }
        int sumCost, minCost = INF, city;
        for(i=0;i<10;i++){
            sumCost = 0;
            for(j=0;j<10;j++){
                if( cost[i][j] < INF ) sumCost += cost[i][j];
            }
            if( sumCost && sumCost < minCost ){
                minCost = sumCost;
                city = i;
            }
        }
        cout << city << ' ' << minCost << endl;
    }
    return 0;
}