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<set>
#define N 11

const int infty = 1<<28;

using namespace std;

int main(){
  while(true){    
    int w[N][N];
    set<int> town;
    int n;

    cin >> n;
    if( n == 0 ) break;
    fill(&w[0][0],&w[N-1][N],infty);

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

    for(int k = 0; k < N; ++k){
      for(int i = 0; i < N; ++i){
	for(int j = 0; j < N; ++j){
	  w[i][j] = min( w[i][j], w[i][k] + w[k][j] );
	}
      }
    }
    
    int min_cost= infty;
    int answer_town;

    for(int i = 0; i < N; ++i){
      if( town.find(i) == town.end() ) continue;
      int cost = 0;
      for(int j = 0; j < N; ++j){
	if( i == j ) continue;
	if( town.find(j) == town.end() ) continue;
	cost += w[i][j];
      }
      if( min_cost > cost ){
	min_cost = cost;
	answer_town = i;
      }
    }

    cout << answer_town << ' ' << min_cost << endl;
  }
  return 0;
}

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

#define INF 1e+9;

int E, V;
int cost[50][50];
int d[100];

int main(){

    while(cin >> E, E){
        V = 0;
        fill(d, d+100, 0);
        for(int i=0; i < 50; i++){
            cost[i][i] = 0;
            for(int j=0; j < 50; j++){
                if(i != j)cost[i][j] = INF;
            }
        }
        for(int i=0; i < E; i++){
            int a, b, c;
            cin >> a >> b >> c;
            cost[a][b] = c;
            cost[b][a] = c;
            V = max(V, max(a, b));
        }
        for(int k=0; k <= V; k++){
            for(int i=0; i <= V; i++){
                for(int j=0; j <= V; j++){
                    cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
                }
            }
        }

        int minCost = INF;
        for(int i=0; i <= V; i++){
            for(int j=0; j <= V; j++){
                d[i] += cost[i][j];
            }
            if(d[i] != 0) minCost = min(minCost, d[i]);
        }

        for(int i=0; i <= V; i++){
            if(minCost == d[i]) cout << i << " " << d[i] << endl;
        }
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

int d[11][11];
static const int INF = 99999999;

void solve() {
  int n;
  while (cin >> n && n) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        d[i][j] = INF;
      }
      d[i][i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int from, to, dist;
      cin >> from >> to >> dist;
      d[from][to] = dist;
      d[to][from] = dist;
    }
    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]);
        }
      }
    }
    int min_sum_dist = INF;
    int pos = 0;
    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 == 0) continue;
      if (min_sum_dist > sum) {
        min_sum_dist = sum;
        pos = i;
      }
    }
    cout << pos << ' ' << min_sum_dist << endl;
  }
}

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

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

#define INF 1<<20
#define MAX_V 10

bool done[MAX_V];
int d[MAX_V];
int V;
int cost[MAX_V+1][MAX_V+1];

int dijkstra(int s) {
  int total = 0;
  
  fill(done, done+V, false);
  fill(d, d+V, INF);
  
  d[s] = 0;

  while(1) {
    int v = -1;
    for(int u = 0; u < V; u++) {
      if(!done[u] && ( v == -1 || d[u]<d[v] )) {
	v = u;
      }
    }
    if(v == -1) break;

    done[v] = true;

    for(int u = 0; u < V; u++) {
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }

  for(int i=0; i<V; i++) {
    total += d[i];
  }
  
  return total;
}

int main() {
  
  int m;

  while(cin >> m, m) {
    int a, b, c;
    V = 0;
    fill(cost[0], cost[MAX_V], INF);
    
    for(int i=0; i<m; i++) {
      cin >> a >> b >> c;
      cost[a][b] = cost[b][a] = c;
      V = max(V, max(a, b));
    }
    V++;
    //    cout << V << endl << endl;
    
    int res = INF, num;
    for(int i=0; i<V; i++) {
      int temp = res;
      res = min(dijkstra(i), res);

      if(temp>res) {
	num = i;
      }
    }
    
    cout << num << " " << res << endl;
  }
  return 0;
}

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

int main(){
  int n;
  int a,b,c;
  int at[10][10];
  int cost,max,minn;
  int min;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	if(i==j)at[i][j] = 0;
	else at[i][j] = -1;
      }
    }
    max = 0;
    for(int k=0;k<n;k++){
      cin >> a >> b >> c;
      if(max < a)max = a;
      if(max < b)max = b;
      for(int j=0;j<10;j++){
	if(at[j][a] >= 0){
	  if( (at[j][b] < 0) || ( at[j][a] + c < at[j][b]) ){
	    at[j][b] = c + at[j][a];
	    at[b][j] = c + at[a][j];
	  }
	}
	if(at[j][b] >= 0){
	  if( (at[j][a] < 0) || ( at[j][b] + c < at[j][a]) ){
	    at[j][a] = c + at[j][b];
	    at[a][j] = c + at[b][j];
	  }
	}
      }
    }

    min = 2000000000;
    for(int i=0;i<=max;i++){
      cost = 0;
      for(int j=0;j<=max;j++)cost += at[i][j];
      if(min > cost){
	min = cost;
	minn = i;
      }
    }
    cout << minn << " " << min << endl;
  }
}