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<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef pair<int,int> P;

struct Graph{
  Graph(int n):E(n),d(n){};
  vector<vector<P>>E;
  vector<int>d;
  void add_edge(int a,int b,int c){
    E[a].push_back({b,c});
  }
  bool bellmanFord(int s){
    int sz=d.size();
    fill(d.begin(),d.end(),INF);
    d[s]=0;
    for(int i=0;i<sz;++i)
      for(int j=0;j<sz;++j)
        for(P& p:E[j])
          if(d[j]!=INF&&d[j]+p.second<d[p.first]){
            d[p.first]=d[j]+p.second;
            if(i==sz-1)return false;
          }
    return true;
  }
};

main(){
  int n,a,b,c,x,y,z,g;
  while(cin>>n,n){
    Graph E(10);
    x=0,z=1e9;
    for(int i=0;i++<n;x=max(x,max(a,b)),E.add_edge(a,b,c),E.add_edge(b,a,c))cin>>a>>b>>c;
    for(int i=0;i<=x;++i){
      E.bellmanFord(i);
      y=0;
      for(int j=0;j<=x;++j)y+=E.d[j];
      if(y<z)z=y,g=i;
    }
    cout<<g<<' '<<z<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF (1<< 28)
#define SIZE 1000

int main(){
  int min_cost[SIZE][SIZE];
  int n,m,a,b,c,mins,minj,sum;
  cin >> m;
  while(m != 0){
    for(int i=0;i<=101;i++){
      for(int j=0;j<=101;j++){
	if(i == j) min_cost[i][j] = 0;
	else min_cost[i][j] = INF;
      }
    }
    n = 0;
    for(int i=0;i<m;i++){
      cin >> a >> b >> c;
      n = max(n,max(a,b));
      min_cost[a][b] = min_cost[b][a] = c;
    }
    for(int k=0;k<=n;k++){
      for(int i=0;i<=n;i++){
	for(int j=0;j<=n;j++){
	  min_cost[i][j] = min(min_cost[i][j],min_cost[i][k]+min_cost[k][j]);
	}
      }
    }
    mins = minj = INF; 
    for(int i=0;i<=n;i++){
      sum = 0;
      for(int j=0;j<=n;j++){
	sum += min_cost[i][j];
      }
      if(mins > sum){
	mins = sum;
	minj = i;
      }
    }
    cout << minj << ' ' << mins << endl;
    
    cin >> m;
  }
  
  return 0;
}

C++: // 2014/06/16 Tazoe

#include <iostream>
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 town = m - 1;
		int value = INF;
		for(int i = m - 1; i >= 0; i--){
			int tempValue = 0;
			for(int j = 0; j < m; j++){
				tempValue += T[i][j];
			}
			if(value >= tempValue){
				value = tempValue;
				town = i;
			}
		}
		cout << town << ' ' << value << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> P;
int INF = 1 << 10;

vector<int> d(10, INF);
struct edge{
  int to;
  int cost;
};

vector<vector<edge> > G(10);
vector<P> ans;

void init(){
  for(int i = 0; i < 10; i++){
	d[i] = INF;
  }
}

void display_d(){
  for(int i = 0; i < 10; i++){
	if(d[i] == INF) cout << "INF ";
	else cout << d[i] << " ";
  }
  cout << endl;
}

void initG(){
  for(int i = 0; i < 10; i++){
	G[i].clear();
  }
}

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  init();
  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 main(){
  int n = 0;
  while(1){
	cin >> n;
	if(n == 0) break;
	int a = 0, b = 0, c = 0;
	for(int i = 0; i < n; i++){
	  cin >> a >> b >> c;
	  edge e1, e2;
	  e1.to = b; e1.cost = c;
	  e2.to = a; e2.cost = c;
	  G[a].push_back(e1);
	  G[b].push_back(e2);
	}

	for(int i = 0; i < 10; i++){
	  dijkstra(i);
	  int sum = 0;
	  for(int i = 0; i < 10; i++){
		if(d[i] == INF) continue;
		sum += d[i];
	  }
	  if(sum != 0) ans.push_back(P(sum, i));
	}

	sort(ans.begin(), ans.end());
	cout << ans[0].second << " " << ans[0].first << endl;
	initG();
  }
  return 0;
}

C++: #include <iostream>
#define INFINITY (1 << 30)

#define MAX_N 10

using namespace std;

int n,road[MAX_N][MAX_N] = {},d[MAX_N][MAX_N] = {};
int main() {
  int temp1,temp2,temp3,city ,alt,mincity ;
  long long int costtime ,cost;
  while(1){
    road[MAX_N][MAX_N] ={};
    d[MAX_N][MAX_N] ={};
      cin >> n;
    if(n == 0) break;
    city = mincity = 0; costtime ;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2>>temp3;
      road[temp1][temp2] = temp3;
      road[temp2][temp1] = temp3;
      if(city < temp1|| city < temp2)  {city = (temp1 > temp2)?  temp1: temp2; }
    }
    //cout << city <<endl;
    city++;

    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j < city; ++j) {
        if(i != j ) d[i][j] = INFINITY;
        if (road [i][j] !=0) d[i][j] =road[i][j];
      }
    }




    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j <city ; ++j) {
        for (int k = 0; k < city; ++k) {
          if(d[i][k] !=INFINITY && d[k][j] != INFINITY){
            alt = d[i][k]+ d[k][j];
            if (alt < d[i][j]) d[i][j] = alt;
          }
        }
      }
    }

    for (int i = 0; i < city; ++i) {
        cost =0;
      for (int j = 0; j < city ; ++j) {
        cost += d[i][j];
        //cout << d[i][j]<<" ";
      }
      //cout<<endl;
      if(i == 0) costtime = cost;
      if (costtime > cost) {costtime = cost;mincity = i;}
    }
    cout<< mincity << " "<<costtime<<endl;

  }


  return 0;
}