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>

#define MAX 10
#define INF INT_MAX
using namespace std;

int d[MAX][MAX];
int n, num_ver = 0;
int min_t = INF;
int min_ver;

void init();
void input();
void wf();

int main(){

  while(cin >> n, n){
    init();
    input();  
    wf();
    
   
    for(int i = 0; i <= num_ver; i++){
      int tmp = 0;
      for(int j = 0; j <= num_ver; j++){
	tmp += d[i][j];
      }
      if(min_t > tmp) {min_t = tmp; min_ver = i;}
    }
    cout << min_ver << " " << min_t << endl;
  }
}

void init(){
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      d[i][j] = (i==j)? 0: INF;
    }
  }
}

void input(){
  for(int i = 0; i < n; i++){
    int a, b, c;
    cin >> a >> b >> c;
    d[a][b] = c;
    d[b][a] = c;
    if(num_ver < b) num_ver = b;
  }
}

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
const int INF=(1<<21);
int main(){

  int n;
  
  while(cin>> n,n){
    int town[11][11];
    int a,b,c;
    int min_total=INF;
    int min_town=0;
    int s[11]={0};
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
	town[i][j]=(i==j)?0:INF;
      }
    }
 
    int v=0;
    for(int i=0;i<n;i++){
    cin>> a>> b>> c;
    town[a][b]=c;
    town[b][a]=c;
    v=max(max(v,a),b);
  }

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

    for(int i=0;i<=v;i++){
      int total=0;
      for(int j=0;j<=v;j++){
	total+=town[i][j];
      }
      s[i]=total;
      min_total=min(min_total,total);
    }
    for(int i=0;i<=v;i++){
      if(s[i]==min_total){
	cout<< i<< ' ';
	cout<< min_total<< endl;
	break;
      }
    }
  }
}

C++: #include <cstdio>
#include <climits>
#include <cstring>

using namespace std;

int m[11][11];
int n;
int dist[11][11];


void flood()
{
	int i, j, k;
	
	memcpy(dist, m, sizeof(m));
	for (k=0; k<n; k++) {
		for (i=0; i<n; i++) {
			if (i==k || dist[i][k]==INT_MAX) continue;
			for (j=i+1; j<n; j++) {
				if (j==k || dist[k][j]==INT_MAX) continue;
				if (dist[i][j] > dist[i][k]+dist[k][j]) {
					dist[i][j] = dist[j][i] = dist[i][k]+dist[k][j];
				}
			}
		}
	}

}

int main()
{
	//freopen("in.txt", "r", stdin);

	int road;
	while (scanf("%d", &road)==1) {
		if (road==0) break;
		int i, j;
		n = 0;
		for (i=0; i<=10; i++) {
			m[i][i] = 0;
			for (j=i+1; j<=10; j++) {
				m[i][j] = m[j][i] = INT_MAX;
			}
		}

		for (i=0; i<road; i++) {
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			if (m[a][b] > c)
				m[a][b] = m[b][a] = c;
			if (n<a+1) n=a+1;
			if (n<b+1) n=b+1;
		}

		flood();

		int min, min_k;
		min = INT_MAX;
		for (i=0; i<n; i++) {
			int sum = 0;
			for (j=0; j<n; j++) {
				sum += dist[i][j];
			}
			if (sum<min) {
				min = sum;
				min_k = i;
			}
		}

		printf("%d %d\n", min_k, min);

	}

	return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
int cost[10][10];
int main() {
	int n;
	while(scanf("%d",&n),n) {
		for(int i=0;i<10;i++) {
			for(int j=0;j<10;j++) {
				cost[i][j]=cost[j][i]=(i==j)?0:(1<<27);
			}
		}
		int m=0;
		for(int i=0;i<n;i++) {
			int a,b,c;
			scanf("%d %d %d",&a,&b,&c);
			cost[a][b]=cost[b][a]=c;
			m=max(m,max(a,b));
		}
		for(int k=0;k<=m;k++) {
			for(int i=0;i<=m;i++) {
				for(int j=0;j<=m;j++) {
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
				}
			}
		}
		int A,B=(1<<27);
		for(int i=0;i<=m;i++) {
			int sum=0;
			for(int j=0;j<=m;j++) {
				sum+=cost[i][j];
			}
			if(B>sum)A=i,B=sum;
		}
		printf("%d %d\n",A,B);
	}
}

C++: // Warshall-floyd
#include <iostream>
using namespace std;
#define INF 114514810

int n, a, b, c, v, d[11][11];// v: num of nodes

void init()
{
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            if(i==j)// If not exist cost, cost=INF
                d[i][j] = 0;
            else
                d[i][j] = INF;
        }
    }

}

int main(void)
{
    ios::sync_with_stdio(false);
    while(cin >> n) {
        if(n == 0) break;
        init();

        v = -1;
        for(int i=0; i<n; i++) {
            cin >> a >> b >> c;
            d[a][b] = c; d[b][a] = c;
            v = max(max(v, a), b);
        }
        v++;

        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 city, dist = INF;
        for(int i=0; i<v; i++) {
            int sum = 0;
            for(int j=0; j<v; j++) {
                sum += d[i][j];
            }
            if(dist > sum) {
                dist = sum;
                city = i;
            }
        }
        cout << city << " " << dist << endl;
    }

    return 0;
}