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 <limits.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <utility>

using namespace std;

int N;
int cost[10][10];

pair<int, int> getMinCost() {
  // Flood.
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      for (int k = 0; k < N; ++k) {
        if (k == i || k == j) {
          continue;
        }
        if (cost[i][k] != -1 && cost[k][j] != -1) {
          int c = cost[i][k] + cost[k][j];
          if (cost[i][j] == -1 || cost[i][j] > c) {
            cost[i][j] = cost[j][i] = c;
          }
        }
      }
    }
  }
  int sum[10];
  for (int i = 0; i < N; ++i) {
    sum[i] = 0;
    for (int j = 0; j < N; ++j) {
      sum[i] += cost[i][j];
    }
  }
  pair<int, int> result;
  result.second = INT_MAX;
  for (int i = 0; i < N; ++i) {
    if (sum[i] < result.second) {
      result = make_pair(i, sum[i]);
    }
  }
  return result;
}

int main() {
  //freopen("ConvenientLocation.in", "r", stdin);
  int R;
  while (scanf("%d", &R) == 1 && R != 0) {
    N = 0;
    memset(cost, -1, sizeof(cost));
    for (int i = 0; i < 10; ++i) {
      cost[i][i] = 0;
    }
    int a, b, c;
    for (int i = 0; i < R; ++i) {
      scanf("%d%d%d", &a, &b, &c);
      N = max(N, max(a, b));
      cost[a][b] = cost[b][a] = c;
    }
    N++;
    pair<int, int> result = getMinCost();
    printf("%d %d\n", result.first, result.second);
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

template<class T> bool ChangeMin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }


static const int MAX = 100;
static const long long INF = 1 << 29;

int m;
long long dist[MAX][MAX];

int main()
{
  while (cin >> m) {
    if (m == 0) break;
    for (int i = 0; i < MAX; ++i) {
      for (int j = 0; j < MAX; ++j) {
	dist[i][j] = INF;
      }
    }

    for (int i = 0; i < m; ++i) {
      int u, v, d;
      cin >> u >> v >> d;
      dist[u][v] = d;
      dist[v][u] = d;
      dist[u][u] = 0;
      dist[v][v] = 0;
    }

    for (int k = 0; k < MAX; ++k)
      for (int i = 0; i < MAX; ++i)
	for (int j = 0; j < MAX; ++j)
	  ChangeMin(dist[i][j], dist[i][k] + dist[k][j]);

    long long minDist = INF;
    int minPlace = -1;
    for (int i = 0; i < MAX; ++i) {
      if (dist[i][i] >= INF) continue;
      long long tmpDist = 0;
      for (int j = 0; j < MAX; ++j) {
	if (dist[j][j] >= INF) continue;
	tmpDist += dist[i][j];
	//cout << i << ", " << j << ": " << dist[i][j] << endl;
      }
      if (ChangeMin(minDist, tmpDist)) {
	minPlace = i;
      }
    }
    cout << minPlace << " " << minDist << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <bitset>
#include <string.h>
#include <cmath>
#include <algorithm>
#define N 1000015
#define P pair<int,int>
#define ll long long
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
bool vis[10];
int dis[10];
int g[10][10];
int inf = 0x3f3f3f3f;
int n, sum;
void Dijkstra(int x) {
	mem(vis, false);
	mem(dis, inf);
	dis[x] = 0;
	// dis[1] = inf;
	for (int i = 0; i <= sum; ++i) {
		int MIN = inf, u = -1;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] < MIN) {
				MIN = dis[j];
				u = j;
			}
		}
		if (u == -1)	return;
		vis[u] = true;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] > g[u][j] + MIN) {
				dis[j] = g[u][j] + MIN;
			}
		}
	}
}

int main(){

	ios::sync_with_stdio(false);
	while (cin >> n, n) {
		int s, e, c;
		mem(g, inf);
		sum = -1;
		for (int i = 0; i < n; ++i) {
			cin >> s >> e >> c;
			sum = max(s, sum);
			sum = max(e, sum);
			g[s][e] = g[e][s] = min(g[s][e], c);
		}
		int ans_n, ans_v = inf;
		for (int i = 0; i <= sum; ++i) {
			Dijkstra(i);
			int sum_temp = 0;
			for (int j = 0; j <= sum; ++j) {
				if (dis[j] == inf) {
					sum_temp = inf;
					break;
				}
				sum_temp += dis[j];
			}
			if (sum_temp < ans_v) {
				ans_v = sum_temp;
				ans_n = i;
			}
		}
		cout << ans_n << " " << ans_v << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

struct Edge{
	int to,cost;
	Edge(int t,int c){
		to=t;
		cost=c;
	}
};

typedef vector<vector<Edge> > AdjList;

AdjList graph;

const int INF=10000000;

vector<vector<int> > dist;

bool bellman_ford(int n,int s){
	dist[s][s]=0;
	for(int i=0;i<n;i++){
		for(int v=0;v<n;v++){
			for(int k=0;k<graph[v].size();k++){
				Edge e=graph[v][k];
				if(dist[s][v]!=INF && dist[s][e.to]>dist[s][v]+e.cost){
					dist[s][e.to]=dist[s][v]+e.cost;
				}
				if(i==n-1)return true;
			}
		}
	}
	return false;
}

int main(){
	while(1){
		int num,maximum=0;
		cin>>num;
		graph=AdjList(10);
		if(num==0)break;
		for(int i=0;i<num;i++){
			int from,to,cost;
			cin>>from>>to>>cost;
			graph[from].push_back(Edge(to,cost));
			graph[to].push_back(Edge(from,cost));
			maximum=max(maximum,to);
		}
		int sum[maximum+1];
		for(int i=0;i<=maximum;i++){
			sum[i]=0;
		}
		dist=vector<vector<int> >(maximum+1);
		for(int i=0;i<=maximum;i++){
			dist[i]=vector<int>(maximum+1,INF);
		}
		for(int i=0;i<=maximum;i++){
			bellman_ford(maximum+1,i);
			for(int j=0;j<=maximum;j++){
				sum[i]+=dist[i][j];
			}
		}
		int ansp=0,anssum=sum[0];
		for(int i=1;i<=maximum;i++){
			if(sum[i]<anssum){
				anssum=sum[i];
				ansp=i;
			}
		}
		cout<<ansp<<" "<<anssum<<endl;
	}
	return 0;
}