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 <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#define MAX_V 10
#define INF 1000000
#define NIL -1
using namespace std;

struct edge {int to,cost;};
typedef pair<int,int> P;	//first:最短距離 second:頂点番号


int d[MAX_V];

void dijkstra(int s,vector<edge> G[]){
	//greater<P>を指定することでfirstが小さい順に取り出せるようになる
	priority_queue<P,vector<P>,greater<P> > que;
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()){
		P p = que.top();que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;//最短距離でなければ無視する
		for(int i = 0;i < G[v].size();i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
	
}

int E;
bool cities[MAX_V];//その番号の町が出てくるか否か

int main(){
	cin >>E;
	while(E != 0){
		vector<edge> G[MAX_V];		//隣接リスト
		fill(cities,cities + MAX_V,false);
		int a,b,cost;
		for(int i = 0;i < E;i++){
			cin >>a >>b >>cost;
			cities[a] = true;cities[b] = true;
			edge e;e.to = b;e.cost = cost;
			G[a].push_back(e);
			e.to = a;
			G[b].push_back(e);
		}
		int mini = INF;int num = NIL;
		for(int i = 0;i < MAX_V;i++){
			fill(d,d+MAX_V,INF);
			for(int j = 0;j < MAX_V;j++){
				if(!cities[j])d[j] = 0;}
			dijkstra(i,G);
			int min_tmp= 0;
			for(int k = 0;k < MAX_V;k++)min_tmp += d[k];
			if(min_tmp < mini){mini = min_tmp;num = i;}
		}
		cout <<num <<" " <<mini <<endl;
		cin >>E;
	}
	return 0;
}

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

#define MAX_V 10
#define INF (INT_MAX/2)
void floydwarshall(int V, vector< vector<int> > &dist){
  for(int k = 0; k < V; k++){
    for(int i = 0; i < V; i++){
      for(int j = 0; j < V; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
  }
}

int main(void){
  int E;
  while(cin >> E && E != 0){
    int V, s, d, c;
    vector< vector<int> > dist(MAX_V, vector<int>(MAX_V, INF));
    V = -INF;

    while(E--){
      cin >> s >> d >> c;
      dist[s][d] = c;
      dist[d][s] = c;
      V = max(V, max(s, d));
    }
    V += 1;

    for(int i = 0; i < V; i++) dist[i][i] = 0;
    floydwarshall(V, dist);

    int ans = 0, min_cost = INF;
    for(int i = 0; i < V; i++){
      int cost = 0;
      for(int j = 0; j < V; j++){
        if(j == i) continue;
        cost += dist[i][j];
      }
      if(min_cost < cost) continue;
      min_cost = cost;
      ans = i;
    }

    cout << ans << " " << min_cost << endl;
  }
  return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int MAX_V = 50;
LL d[MAX_V][MAX_V];//d[i][j]???e={u,v}????????????(?????¨???????????¨??????INF,i==j?????¨??????0)
int v;

void warshall_floyd() {
	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]);
			}
		}
	}
}

bool used[50];

int main() {
	while (cin >> v&&v) {
		REP(i, MAX_V)REP(j, MAX_V) {
			if (i == j)d[i][j] = 0;
			else d[i][j] = INF;
		}
		REP(i, MAX_V)used[i] = false;
		int a, b, c;
		for (int i = 0; i < v; i++) {
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
			used[a] = used[b] = true;
		}
		warshall_floyd();
		LL ans = INF;
		int ans2;
		REP(i, MAX_V) {
			if (!used[i])continue;
			LL num = 0;
			REP(j, MAX_V) {
				if (!used[j])continue;
				num += d[i][j];
			}
			//cout << num << endl;
			if (ans > num) {
				//cout << 1 << endl;
				ans = num;
				ans2 = i;
			}
		}
		cout <<ans2<<" "<< 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;
}