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 <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;
const int MAX_E = 45;
const int MAX_V = 10;
const int INF = 1024 * 1024 * 1024;
struct edge {int to, cost; };
vector<edge> G[MAX_V];
vector<string> result;

int main() {
    int n;
    while(1) {
        cin >> n;
        if (n == 0) break;
        int max_v = -1;
        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            edge e, e1;
            e.to = to;
            e.cost = cost;
            G[from].push_back(e);
            e1.to = from;
            e1.cost = cost;
            G[to].push_back(e1);
            max_v = max(max(max_v, from), to);
        }

        int dps[max_v + 1];
        for(int i = 0; i <= max_v; i++) {
            int d[max_v + 1] = {0};
            for(int k = 0; k <= max_v; k++) {
                d[k] = INF;
            }
            priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
            d[i] = 0;
            que.push(pair<int, int>(0, i));
            while(!que.empty()) {
                pair<int, int> p = que.top();
                que.pop();
                if(p.first > d[p.second]) continue;
                for(int j = 0; j < G[p.second].size(); j++) {
                    edge e1 = G[p.second][j];
                    if(d[e1.to] > d[p.second] + e1.cost) {
                        d[e1.to] = d[p.second] + e1.cost;
                        que.push(pair<int, int>(d[e1.to], e1.to));
                    }
                }
            }


            int sum = 0;
            for(int j = 0; j <= max_v; j++) {
                sum += d[j];
            }

            dps[i] = sum;
        }

        int min_i = 0;
        for(int i = 1; i <= max_v; i++) {
            if(dps[min_i] > dps[i]) {
                min_i = i;
            }
        }

        result.push_back(to_string(min_i) + " " + to_string(dps[min_i]));
    }

    for(int i = 0; i < result.size(); i++) {
        cout << result[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
#define foreach(i,n) for (int i = 0; i < n; ++i)
#define foreach1(i,n) for (int i = 1; i < n; ++i)
#define foreach_from(i,m,n) for (int i = m; i < n; ++i)

#define MAX_TOWN 10
#define MAX_N 45

int N; // the number of the pathes
int A[MAX_N];
int B[MAX_N];
int C[MAX_N];

int dt[MAX_N+1][MAX_N][MAX_N];

int main () {
    while (true) {
        cin >> N;
        if (N == 0) return 0;
        foreach (i,N) cin >> A[i] >> B[i] >> C[i];

        foreach (i,MAX_TOWN) foreach (j,MAX_TOWN) { dt[0][i][j] = i == j ? 0 : 0xffff; }
        foreach (i,N) { dt[0][A[i]][B[i]] = dt[0][B[i]][A[i]] = min(C[i], dt[0][A[i]][B[i]]); }
        foreach (i,MAX_TOWN) {
            foreach (j,MAX_TOWN) {
                foreach (k,MAX_TOWN) {
                    dt[i+1][j][k] = min(dt[i][j][k], dt[i][j][i] + dt[i][i][k]);
                }
            }
        }
        int town = -1, cost = 0xffff;
        foreach (n,MAX_TOWN) {
            int sum = 0;
            foreach (i,MAX_TOWN) { if (dt[MAX_TOWN][n][i] != 0xffff) sum += dt[MAX_TOWN][n][i]; }
            if (sum != 0 && sum < cost) { town = n; cost = sum; }
        }

        cout << town << " " << cost << endl;
    }
}

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

using namespace std;

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

void floyd() {
  for(int i = 0; i < m; ++i) {
    for(int j = 0; j < m; ++j) {
      for(int k = 0; k < m; ++k) {
        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;
    ans = 0x7fffffff;
    for(i = 0; i < m; ++i) {
      tmp = 0;
      for(j = 0; j < m; ++j) {
        if(i == j) continue;
        tmp += d[i][j];
      }
      if(tmp < ans) {
        ans = tmp;
        p = i;
      }
    }
    printf("%d %d\n", p, ans);
  }
  return 0;
}