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++: // 2013/11/25 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

const int INF = 100000000;

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++){
					T[i][j] = min(T[i][j], T[i][k]+T[k][j]);
				}
			}
		}

		int m_min = -1;
		int s_min = 1000000000;

		for(int i=0; i<m; i++){
			int s = 0;

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

			if(s<s_min){
				m_min = i;
				s_min = s;
			}
		}

		cout << m_min << ' ' << s_min << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <utility>

#define dprintf(s,...) printf("%s:%d" s,__func__,__LINE__,__VA_ARGS__)
using namespace std;

typedef pair<int,int> P;
typedef long long int ll;

class Edge{
public:
  int to,cost;
  Edge(int t,int c){
    to = t;
    cost = c;
  }
};

int n,k;
int d[10][10];
vector<Edge> G[10];

void dijekstra(int s){

  priority_queue<P, vector<P>, greater<P> > qu;

  qu.push(P(0,s));
  d[s][s]=0;
  
  while(!qu.empty()){

    P p = qu.top();
    int v = p.second; 
    qu.pop();

    if(d[s][v] < p.first) continue;

    for(int i=0; i<G[v].size(); i++){
      Edge e = G[v][i];
      
      if(d[s][v]+e.cost < d[s][e.to]){
	d[s][e.to] = d[s][v]+e.cost;
	qu.push(P(d[s][e.to], e.to));
      }
    }
    
  }

}

void solve(){

  for(int i=0;i<k;i++)
    for(int j=0;j<k;j++){
      d[i][j]=INT_MAX/3;
    }

  for(int i=0;i<k;i++){
    dijekstra(i);
  }
}


int main(){

  ios_base::sync_with_stdio(false);
  
  while(1){

    k=0;
    
    cin>>n;
    if(n==0) break;
    
    
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b>>c;
      Edge e1(a,c),e2(b,c);
      G[a].push_back(e2);
      G[b].push_back(e1);
      k = max(k,max(a,b));
    }
    k++;
    //cout<<"k="<<k<<endl;
    solve();
    
    int sum[10];
    int ans, min_cost=INT_MAX/3;
    fill(sum,sum+10,0);

    for(int i=k-1;i>=0;i--){
      for(int j=0; j<k; j++){
	sum[i] += d[i][j];
      }
      if(sum[i] < min_cost){
	ans = i;
	min_cost = sum[i];
      }
    }
    cout<<ans<<" "<<min_cost<<endl;
    for(int i=0;i<10;i++){
      G[i].erase(G[i].begin(), G[i].end());
    }    
  }


  
  
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;


struct edge {
	int to, cost;
	edge(int _to, int _cost) :to(_to), cost(_cost){};
};

vector<edge> G[100];

int n, a, b, c;
int d[100];
set<int> si;
set<int>::iterator it;

void dijkstra(int s){
	fill(d, d + 100, INF);
	d[s] = 0;
	priority_queue<P> que;
	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 main(){
	while (cin >> n&&n){
		REP(i, n){
			cin >> a >> b >> c;
			if (si.find(a) == si.end())si.insert(a);
			if (si.find(b) == si.end())si.insert(b);
			G[a].push_back(edge(b, c));
			G[b].push_back(edge(a, c));
		}
		int ans = INT_MAX, index = INT_MAX;
		it = si.begin();
		REP(i, si.size()){
			int sum = 0;
			dijkstra(*it + i);
			REP(i, si.size()){
				sum += d[i];
			}
			if (ans > sum){
				ans = sum;
				index = *it + i;
			}
		}
		cout << index << " " << ans << endl;
		REP(i, si.size()){
			G[*it + i].clear();
		}
		si.clear();
	}
}

C++: #include <iostream>
#include <algorithm>
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 Count[m];
      for (int i = 0; i < m; i++)
	{
	  Count[i] = 0;
	  for (int j = 0; j < m; j++)
	    {
	      Count[i] = Count[i] + T[i][j];
	    }
	}

      int mnum = 0;
      for (int i = 0; i < m; i++)
	{
	  if (Count[0] > Count[i])
	    {
	      Count[0] = Count[i];
	      mnum=i;
	    }
	}
      cout << mnum << ' ' << Count[0] << endl;

    }

  return 0;
}