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++: // Warshall-floyd
#include <iostream>
#include <algorithm>
using namespace std;
#define INF (1 << 21) 

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(1) {
        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(v, max(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(sum < dist) {
                dist = sum;
                city = i;
            }
        }
        cout << city << " " << dist << endl;
    }

    return 0;
}

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

const int INF = 1 << 29;
const int MAX = 10;
int as[MAX][MAX];
int n, m;

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

int main() {
    while (cin >> n, n) {
        for (int i = 0; i < MAX; i++) {
            for (int j = 0; j < MAX; j++) {
                as[i][j] = (i == j) ? 0 : INF;
            }
        }
        m = 0;
        for (int i = 0; i < n; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            as[a][b] = as[b][a] = c;
            m = max(m, a);
            m = max(m, b);
        }
        m++;
        floyd();
        int ans = INF, ans_i;
        for (int i = 0; i < m; i++) {
            int sum = 0;
            for (int j = 0; j < m; j++) {
                sum += as[i][j];
            }
            if (ans > sum) {
                ans = sum;
                ans_i = i;
            }
        }
        cout << ans_i << " " << ans << endl;
    }
}

C++: #include <iostream>

// int inf = 1 << 28;
int inf = 1000000000;

int dijk(int n,int s, int **g) {
	int sum = 0;
	bool *used = new bool[n];
	int *d = new int[n];

	// std::cout << "n = " << n << " " << "s = " << s << std::endl;

	for(int j=0;j<n;j++){
		for(int i=0;i<n;i++){
			std::cout << g[j][i] << ",";
		}
		std::cout << std::endl;
	}

	for(int i = 0; i < n; i++)
		d[i] = inf;
	d[s] = 0;

	while(true) {
		int u = -1;
		for(int v = 0; v < n; v++)
			if(!used[v] && (u == -1 || d[v] < d[u]))
				u = v;

		// std::cout << "u = " << u << std::endl;

		if(u == -1) break;
		used[u] = true;

		for(int v = 0; v < n; v++)
			if(d[v] > d[u] + g[u][v])
				d[v] = d[u] + g[u][v];
	}

	for(int i = 0; i < n; i++) {
		sum += d[i];
	}

	// for(int i = 0; i < n; i++) {
	// std::cout << d[i] << std::endl;
	// }

	return sum;
}

int main() {
	do {
		int **g; // adjacency matrix, ?
		int *d;
		int *a, *b, *c;
		int edge = 0, min = 0, max = 0;
		int tmp = 0;

		std::cin >> edge;
		if(!edge) break;

		a = new int[edge];
		b = new int[edge];
		c = new int[edge];

		for(int i = 0;i < edge;i++) {
			std::cin >> a[i];
			std::cin >> b[i];
			std::cin >> c[i];
		}

		for(int i = 0; i < edge; i++) {
			if(max < a[i])
				max = a[i];
		}
		for(int i = 0; i < edge; i++) {
			if(max < b[i])
				max = b[i];
		}
		max++;

		g = new int*[max];
		d = new int[max];

		for(int i = 0; i < max; i++) {
			g[i] = new int[max];
		}

		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				g[i][j] = inf;

		for(int i = 0; i < edge; i++)
			g[b[i]][a[i]] = g[a[i]][b[i]] = c[i];

		for(int i=0;i<max;i++){
			g[i][i]=0;
		}

		
		for(int k=0;k<max;k++){
			for(int j=0;j<max;j++){
				for(int i=0;i<max;i++){
					if(g[i][k]+g[k][j]<g[i][j]){
						g[i][j]=g[i][k]+g[k][j];
					}
				}
			}
		}
		

		for(int i = 0; i < max; i++)
			d[i] = dijk(max, i, g);

		for(int i = 0; i < max; i++){
			d[i]=0;
			for(int j=0;j<max;j++){
				d[i] += g[i][j];
			}
		}

		min = d[0];
		for(int i = 1; i < max; i++) {
			if(min > d[i]) {
				min = d[i];
				tmp = i;
			}
		}

		std::cout << tmp << " " << min << std::endl;
		for(int i = 0; i < max; i++)
			delete[] g[i];
		delete[] g;
		delete[] a;
		delete[] b;
		delete[] c;
		delete[] d;

	}while(true);
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
typedef pair<int,int> P;

#define INF 10000000
struct road{int to,cost;};
vector<road> roads[10];
int d[10];
int n,m;

int main(){
  while(1){
    cin >> n;
    if(!n)break;
    m = 0;
    for(int i=0;i<n;i++){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      if(m<x||m<y){
        m = max(x,y);
      }
      roads[x].push_back((road){y,z});
      roads[y].push_back((road){x,z});
    }
    m++;

    int minIndex;
    int mini = INF;
    for(int i=0;i<m;i++){
      priority_queue<P, vector<P>, greater<P> > que;
      que.push(P(0,i));
      fill(d,d+m,INF);
      d[i] = 0;
      while(que.size()){
        P p = que.top(); que.pop();
        int dist = p.first;
        int pos = p.second;
        if(d[pos]<dist){
          continue;
        }
        for(int j=0;j<roads[pos].size();j++){
          int to = roads[pos][j].to;
          int cost = roads[pos][j].cost;
          if(d[to]>d[pos]+cost){
            d[to] = d[pos] + cost;
            que.push(P(d[to],to));
          }
        }
      }
      int sum = 0;
      for(int j=0;j<m;j++){
        sum += d[j];
      }
      if(mini>sum){
        mini = sum;
        minIndex = i;
      }
    }
    cout << minIndex << " " << mini << endl;
  }
}