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 <limits.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <utility>

using namespace std;

int N;
int cost[10][10];

pair<int, int> getMinCost() {
  // Flood.
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      for (int k = 0; k < N; ++k) {
        if (k == i || k == j) {
          continue;
        }
        if (cost[i][k] != -1 && cost[k][j] != -1) {
          int c = cost[i][k] + cost[k][j];
          if (cost[i][j] == -1 || cost[i][j] > c) {
            cost[i][j] = cost[j][i] = c;
          }
        }
      }
    }
  }
  int sum[10];
  for (int i = 0; i < N; ++i) {
    sum[i] = 0;
    for (int j = 0; j < N; ++j) {
      sum[i] += cost[i][j];
    }
  }
  pair<int, int> result;
  result.second = INT_MAX;
  for (int i = 0; i < N; ++i) {
    if (sum[i] < result.second) {
      result = make_pair(i, sum[i]);
    }
  }
  return result;
}

int main() {
  //freopen("ConvenientLocation.in", "r", stdin);
  int R;
  while (scanf("%d", &R) == 1 && R != 0) {
    N = 0;
    memset(cost, -1, sizeof(cost));
    for (int i = 0; i < 10; ++i) {
      cost[i][i] = 0;
    }
    int a, b, c;
    for (int i = 0; i < R; ++i) {
      scanf("%d%d%d", &a, &b, &c);
      N = max(N, max(a, b));
      if (cost[a][b] == -1 || cost[a][b] > c) {
        cost[a][b] = cost[b][a] = c;
      }
    }
    N++;
    pair<int, int> result = getMinCost();
    printf("%d %d\n", result.first, result.second);
  }
  return 0;
}

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

using namespace std;

const int MAX_N = 101;
const int INF   = 9999999;
int n;
int w[MAX_N][MAX_N];
bool used[MAX_N];

int main()
{
    while(cin >> n && n) {
        memset(used, false, sizeof(used));
        for(int i = 0; i < MAX_N; i++)
            for(int j = 0; j < MAX_N; j++)
                w[i][j] = INF;

        int a,b,c;
        for(int i = 0; i < n; i++) {
            cin >> a >> b >> c;
            used[a] = used[b] = true;
            w[a][b] = w[b][a] = c;
        }

        for(int i = 0; i < MAX_N; i++)
            w[i][i] = 0;
        
        for(int k = 0; k < MAX_N; k++) {
            for(int i = 0; i < MAX_N; i++) {
                for(int j = 0; j < MAX_N; j++) {
                    if(used[i] && used[j] && used[k]) 
                        w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
                }
            }
        }

        
        int idx, min = INF;
        
        for(int i = 0; i < MAX_N; i++) {
            if(!used[i]) continue;
            
            int tmp = 0;
            for(int j = 0; j < MAX_N; j++) 
                if(used[i] && used[j])
                    tmp += w[i][j];
            
            if(tmp < min) {
                min = tmp;
                idx = i;
            }
        }

        cout << idx << " " << min << endl;
    }
}

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

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d; // グラフの距離を格納した2次元配列（隣接行列）
          // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
	
	while(1){
	
  int n=0, m;

  d = Matrix(10, vector<int>(10, INF));
  for (int i = 0; i < 10; i++) d[i][i] = 0;
  
  
  	
	cin >> m;
	if(m == 0) break;
  
	  for (int i = 0; i < m; i++) {
	    int from, to, cost;
	    cin >> from >> to >> cost;
		n = max(n,from);
		n = max(n,to);
	    d[from][to] = cost;
		d[to][from] = cost;
	  }
	  
	  n++;
	  
	  warshall_floyd(n);
	  
	
	  
	  int sum[100]  ; 
	  int a ;
	  
	  for (int i = 0; i < n ; i++) {
	  	sum[i] = 0;
	    for (int j = 0; j < n; j++) {
			
			
			sum[i] +=  d[i][j];
			
	    }
	  }
	  
	  int ans = sum[0];
	  int num = 0;
	  
	  for(int i = 0; i<n-1 ; i++){
	  	if(sum[i] > sum[i+1]){
			ans = sum[i+1];
			num = i+1;
	  	}
	  }
	  
	  cout << num << " " << ans << endl;
  
  }
  
    
  
  
  return 0;
}

C++: #include<iostream>
#include<climits>
using namespace std;
int g[12][12];
const int INF = INT_MAX/2;
int main(){
  while(true){
    int n;
    cin >> n;
    if(n == 0)break;
    fill(*g,*(g+12),INF);
    for(int i = 0;i < 12;i++)g[i][i] = 0;

    for(int i = 0;i < n;i++){
      int a,b,c;
      cin >> a >> b >> c;
      g[a][b] = g[b][a] = c;
    }
  
    for(int k = 0;k < 12;k++){
      for(int j = 0;j < 12;j++){
        for(int i = 0;i < 12;i++){
          
          g[i][j] = min( g[i][j], g[i][k] + g[k][j]);
        }
      }
    }  
    
    int ans = INF,node = 0;
    for(int i = 0;i < 12;i++){
      int tmp = 0;
      for(int j = 0;j < 12;j++){
        tmp += g[i][j] == INF ? 0 : g[i][j];
      }
      if(tmp > 0 && tmp < ans){
        node = i;
        ans = tmp;
      }
    
    }
    cout << node << ' ' << ans << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1 << 25;
int wf[10][10];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	while(cin >> n, n) {
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				wf[i][j] = (i == j) ? 0 : INF;
			}
		}

		bool use[10] = { false };
		for(int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			wf[a][b] = wf[b][a] = c;
			use[a] = use[b] = true;
		}

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

		int mi = -1, m = INF;
		for(int i = 0; i < 10; i++) {
			if(!use[i]) continue;
			int sum = 0;
			for(int j = 0; j < 10; j++) {
				if(use[j]) sum += wf[i][j];
			}
			if(sum < m) {
				mi = i;
				m = sum;
			}
		}

		cout << mi << " " << m << endl;
	}
}