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 <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int INF = 0x3f3f3f3f;

int d[10][10];
int m;

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


int main() {
  int i, j, a, b, c, n;
  while (scanf("%d", &n) != EOF && n) {
    memset(d, 0x3f, sizeof(d));
    m = 0;
    while (n--) {
      scanf("%d%d%d", &a, &b, &c);
      d[a][b] = d[b][a] = c;
      m = max(m, max(a + 1, b + 1));
    }
    floyd();
    int ans, p, tmp;
    p = 0;
    ans = INF;
    for (i = 0; i < m; ++i) {
      tmp = 0;
      for (j = 0; j < m; ++j) {
        if (i == j) continue;
        tmp += d[i][j];
        if (tmp >= INF) break;
      }
      if (tmp < ans) {
        ans = tmp;
        p = i;
      }
    }
    printf("%d %d\n", p, ans);
  }
  return 0;
}

C++: // Warshall-floyd
#include <iostream>
#include <algorith>
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;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define MAX_VIL_NUM 10

using namespace std;

int main(void){
	int n, a, b, c, i, j, con[MAX_VIL_NUM][MAX_VIL_NUM], used[MAX_VIL_NUM], distance[MAX_VIL_NUM], sum, ans_time, ans_vil, vil_num;
	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}
		vil_num = 0;
		memset(con,-1,sizeof(con));
		for(i = 0;i < n;i++){
			scanf("%d%d%d",&a,&b,&c);
			con[a][b] = c;
			con[b][a] = c;
			vil_num = max(vil_num,a + 1);
			vil_num = max(vil_num,b + 1);
		}
		ans_time = -1;
		for(i = 0;i < vil_num;i++){
			memset(used,0,sizeof(used));
			memset(distance,-1,sizeof(distance));
			distance[i] = 0;
			while(1){
				int min_el = -1;
				for(j = 0;j < vil_num;j++){
					if(used[j] == 0 && distance[j] != -1 && (min_el == -1 || distance[min_el] > distance[j])){
						min_el = j;
					}
				}
				if(min_el == -1){
					break;
				}
				for(j = 0;j < vil_num;j++){
					if(con[min_el][j] != -1 && (distance[j] == -1 || distance[min_el] + con[min_el][j] < distance[j])){
						distance[j] = distance[min_el] + con[min_el][j];
					}
				}
				used[min_el] = 1;
			}
			sum = 0;
			for(j = 0;j < vil_num;j++){
				if(distance[j] != -1){
					sum += distance[j];
				}
			}
			if(ans_time == -1 || ans_time > sum){
				ans_time = sum;
				ans_vil = i;
			}
		}
		printf("%d %d\n",ans_vil,ans_time);
	}
	return 0;
}

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

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

		int m = 0;		// ????????°

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

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

		int min=0;
		int total,num;

		for(int i=0;i<m;i++){
			min+=T[0][i];
		}

		for(int i=1;i<m;i++){
			total=0;
			for(int j=0;j<m;j++){
				total+=T[i][j];
			}
			if(min>total){	
				min=total;
				num=i;
			}
		}
		
		cout<<num<<' '<<min<<endl;

	}

	return 0;
}

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

const int INF = 100000000;

int main() {
  int n, p, a, b, c;
  int m[10][10];
  while (1) {
    cin >> n;
    if (!n) break;
    for (int i=0; i<10; i++) {
      for (int j=0; j<10; j++) {
        m[i][j] = INF;
      }
      m[i][i] = 0;
    }
    p = 0;
    for (int i=0; i<n; i++) {
      cin >> a >> b >> c;
      p = max(p, a);
      p = max(p, b);
      m[a][b] = c;
      m[b][a] = c;
    }
    for (int i=0; i<=p; i++) {
      for (int j=0; j<=p; j++) {
        for (int k=0; k<=p; k++) {
          m[j][k] = min(m[j][k], m[j][i] + m[i][k]);
        }
      }
    }
    a = INF;
    b = -1;
    for (int i=0; i<=p; i++) {
      c = 0;
      for (int j=0; j<=p; j++) {
        c += m[i][j];
      }
      if (a > c) {
        a = c;
        b = i;
      }
    }
    cout << b << " " << a << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX 11
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];

int dijkstra(int s){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = 0 ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = 0; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            if(t < v[i]) v[i] = t;
        }
    }
    
    int sum = 0;
    for(int i = 0 ; i <= maxnum ; i++){
        sum += v[i];
    }
    
    return sum;
}


int main(){
    int a,b,c;
    
    for(int i = 0 ; i < MAX ; i++)
        for(int j = 0 ; j < MAX ; j++)
            r[i][j] = INF;

    while(cin >> n,n){
        maxnum = 0;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = c;
            r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
        }

        int mx = INF, e;
        for(int i = 0 ; i <= maxnum ; i++){
            int val = mx;
            mx = min(mx,dijkstra(i));
            if(val > mx) e = i;
        }
        cout << e << ' ' << mx << endl;
    }
    
    return 0;
}