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 <cstdio>
#define INF 200000

using namespace std;

const int MAX=11;

int d[MAX][MAX];
int V;

int main()
{
    int n;
    while(~scanf("%d", &n) && n)
    {
        for(int i=0; i<MAX; i++)
        {
            for(int j=0; j<MAX; j++)
            {
                if(i!=j)
                    d[i][j]=INF;    //初始化
            }
        }
        V=0;
        for(int i=0; i<n; i++)
        {
            int x,y,m;
            scanf("%d %d %d", &x, &y, &m);
            d[x][y]=m;
            d[y][x]=m;
            V = max(V, max(x+1, y+1));
        }
   //     printf("%d\n",V);
//        for(int i=0; i<V; i++)
//        {
//            for(int j=0; j<V; j++)
//            {
//                printf("%d ", d[i][j]);
//            }
//            printf("\n");
//        }
//        printf("\n");
        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]);
            }
        }
        int u=0;
        for(int i=0; i<V; i++)
        {
            for(int j=1; j<V; j++)
            {
                if(d[i][j] != INF && i!=j)
                    d[i][0]+=d[i][j];
            }
            if(d[i][0]<d[u][0])
                u=i;
        }
        printf("%d %d\n", u, d[u][0]);
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
typedef long long ll;

using namespace std;

const int mod=1e9+7;
const int INF=1<<25;

void solve(int n){
  int dp[11][11];
  fill(dp[0],dp[10],INF);
  rep(i,9) dp[i][i]=0;
  int a,b,c;
  int first=10,last=0;
  int ans1;
  ll ans2=INF,temp;
  rep(i,n){
    cin >> a >> b >> c;
    first=min(first,min(a,b));
    last=max(last,max(a,b));
    dp[a][b]=dp[b][a]=c;
  }
  rep(k,n) rep(i,n) rep(j,n){
    dp[j][i]=dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
  }
  REP(i,first,last+1){
    temp=0;
    REP(j,first,last+1){
      temp+=dp[i][j];
    }
    if(temp<ans2){
      ans2=temp;
      ans1=i;
    }
  }
  cout << ans1 << " " << ans2 << endl;

  return ;
}
int main(){
  int n;
  while(true){
    cin >> n;
    if(!n)  break;
    solve(n);
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
const int INF = 1 << 20;
const int N = 11;
int tim[N][N];
using namespace std;
int main()
{
	int a, b, ti, n;
	while (1){
		cin >> n;
		if (n == 0)break;

		for (int i = 0; i < N; i++){
			for (int i2 = 0; i2 < N; i2++){
				if (i != i2){
					tim[i][i2] = INF;
				}
				else
					tim[i][i2] = 0;
			}
		}

		int m = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b >> ti;
			tim[a][b] = ti;
			tim[b][a] = ti;
			m = max(m, a);
			m = max(m, b);
		}

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

		int mint = INF;
		vector<int>p;
		//p.clear();
		for (int i = 0; i <= m; i++){
			int mt = 0;
			for (int i2 = 0; i2 <= m; i2++){
					mt += tim[i][i2];
			}
			p.push_back(mt);
			mint = min(mt, mint);
		}

		for (int i = 0; i <= p.size(); i++){
			if (p[i] == mint){
				cout << i << " " << mint << endl;
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

typedef long long int lli;
lli INF = 1000000LL;

int main() {

  array<array<lli, 10>, 10> table;
  
  while( true ){
	int n;
	cin >> n;
	if ( n == 0 ) break;

	for ( int i = 0; i < 10; i++ ) {
	  for ( int j = 0; j < 10; j++ ) {
		table[ i ][ j ] = INF;
	  }
	}
	
	int m = -1;
	for ( int i = 0; i < n; i++ ) {
	  int v1, v2, c;
	  cin >> v1 >> v2 >> c;
	  table[ v1 ][ v2 ] = c;
	  table[ v2 ][ v1 ] = c;
	  m = max( max( v1, v2 ), m );
	}
	for ( int i = 0; i < 10; i++ ) {
	  table[ i ][ i ] = 0LL;
	}

	for ( int k = 0; k <= m; k++ ) {
	  for ( int i = 0; i <= m; i++ ) {
		if ( table[ i ][ k ] >= INF ) continue;
		for ( int j = 0; j <= m; j++ ) {
		  if ( table[ i ][ j ] > table[ i ][ k ] + table[ k ][ j ] ) {
			table[ i ][ j ] = table[ i ][ k ] + table[ k ][ j ];
		  }
		}
	  }
	}
	lli ans = INF;
	int num = -1;
	for ( int i = 0; i <= m; i++ ) {
	  lli sum = 0;
	  for ( int j = 0; j <= m; j++ ) {
		sum += table[ i ][ j ]; 
	  }
	  if ( ans > sum ) {
		ans = sum;
		num = i;
	  }
	}
	cout << num << " " << ans << 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(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;
	}
}