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<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<stack>
#include<sstream>
#include<complex>

#define pb push back
#define clr clear()
#define sz size()
#define fs first
#define sc second

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(int)(a)−1;i>=0;i−−)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)−(b)) < EPS)
#define INIT(a) memset(a,0,sizeof(a))

using namespace std;
typedef double D;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const D EPS = 1e-8;
const int INF = 1e8;
const D PI = acos(-1);

int v; //頂点数
int n;
int a,b,c;
int d[20][20]; //ク&#12441;ラフの隣接行列
void WarshallFloyd(void){ rep(k,v)rep(i,v)rep(j,v)d[i][j] = min(d[i][j],d[i][k]+d[k][j]); }

int main(){
  while(cin >> n,n){
    rep(i,20){
      rep(j,20)d[i][j] = INF;
      d[i][i] = 0;
    }

    v = 0;
    rep(i,n){
      cin >> a >> b >> c;
      v = max(v,max(a,b));
      d[a][b] = d[b][a] = c;
    }
    v++;

    WarshallFloyd();

    int res = -1, dis = INF;
    rep(i,v){
      int tmp = 0;
      rep(j,v)tmp += d[i][j];
      if(dis > tmp){
	dis = tmp; res = i;
      }
    }
    cout << res << " " << dis <<  endl;
  }
    
}

C++: #include<iostream>

using namespace std;
const int INF = 1000000;

int main()
{
  int edge[10][10];
  int n;
  for(;cin>>n,n;)
    {
      for(int i=0;i<10;i++)
	for(int j=0;j<10;j++)
	  {
	    if(i!=j)
	      edge[i][j]=INF;
	    else
	      edge[i][j]=0;
	  }
      int max_num=0;
      for(int i=0;i<n;i++)
	{
	  int a,b,c;
	  cin>>a>>b>>c;
	  edge[a][b]=c;
	  edge[b][a]=c;
	  max_num=max(max_num,max(a,b));
	}
      for(int k=0;k<=max_num;k++)
	for(int i=0;i<=max_num;i++)
	  for(int j=0;j<=max_num;j++)
	    {
	      edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
	    }
      int ans=0,sum=INF*10;
      for(int i=0;i<=max_num;i++)
	{
	  int tmp=0;
	  for(int j=0;j<=max_num;j++)
	    {
	      tmp+=edge[i][j];
	    }
	  if(tmp<sum)
	    {
	      ans=i;
	      sum=tmp;
	    }
	}
      cout<<ans<<" "<<sum<<endl;
    }
}

C++: #include<cstdio>
#include<iostream>

using namespace std;
#define INF 100000

int  road, max = 0, time[10][10] = { 0 }, sum, root[10] = { 0 };

void dijkstra(int a) {

	int i,j,k=INF,used[10],minroot;
	for (i = 0; i <= max; i++) {
		used[i] = 0;
		root[i] = INF;
	}
	root[a] = 0;
	while (1) {
		minroot = INF;
		for (i = 0; i <= max; i++) {
			if (used[i] == 0&&root[i]<minroot) {
				j = i;
				minroot = root[i];
			}
			
		}
		if (k == j) {
			break;
		}
		else {
			k = j;
		}
		used[j] = 1;
		for (i = 0; i <= max; i++) {
			if (root[i] > root[j] + time[j][i]) {
				root[i] = root[j] + time[j][i];
			}

		}
	}
	sum = 0;
	for (i = 0; i <= max; i++)sum += root[i];

	return ;
}






int main() {
	cin >> road;
	int i, j, a, b, c, save_a[45] = { 0 }, save_b[45] = { 0 }, save_c[45] = { 0 }, min_sum = INF, ans_town;

	for (i = 1; i <= road; i++) {
		cin >> a >> b >> c;
		if (max < a) max = a;
		if (max < b) max = b;
		save_a[i] = a;
		save_b[i] = b;
		save_c[i] = c;
	}
	for (i = 0; i <= max; i++) {
		for (j = 0; j <= max; j++) {
			time[i][j] = INF;
		}
		time[i][i] = 0;
	}
	for (i = 1; i <= road; i++) {
		time[save_a[i]][save_b[i]] = save_c[i];
		time[save_b[i]][save_a[i]] = save_c[i];
	}
	for (i = 0; i <= max; i++) {
		dijkstra(i);
		if (sum < min_sum) {
			ans_town = i;
			min_sum = sum;
		}
	}
	cout << ans_town << " " << min_sum << endl;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
const int INF = 1 << 20;
const int N = 11;
int tim[N][N];
using namespace std;
int main()
{
	int a, b, ti, n;
	while (1){
		cin >> n;
		if (n == 0)break;

		for (int i = 0; i < N; i++){
			for (int i2 = 0; i2 < N; i2++){
				if (i != i2){
					tim[i][i2] = INF;
				}
				else
					tim[i][i2] = 0;

			}
		}

		int m = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b >> ti;
			tim[a][b] = ti;
			tim[b][a] = ti;
			m = max(m, a);
			m = max(m, b);
		}

		for (int k = 0; k <= n; k++)
			for (int i = 0; i <= n; i++)
				for (int j = 0; j <= n; j++){
					tim[i][j] = min(tim[i][j], tim[i][k] + tim[k][j]);
				}

		int mint = INF;
		vector<int>p;
		for (int i = 0; i <= m; i++){
			int mt = 0;
			for (int i2 = 0; i2 <= m; i2++){
					mt += tim[i][i2];
			}
			p.push_back(mt);
			mint = min(mt, mint);
		}

		for (int i = 0; i <= p.size(); i++){
			if (p[i] == mint){
				cout << i << " " << mint << endl;
				break;
			}
		}
	}
}

C++: #include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
const int inf = 999999;
int main(){
	int n,a,b,c;
	while(cin >> n, n) {
		int cost[10][10] = {}, ans[10][10] = {};
		rep(i,10) {
			rep(j,10) {
				if(i==j)continue;
				cost[i][j] = inf;
				ans[i][j] = inf;
			}
		}
		int max = 0;
		rep(i,n) {
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			if(max < a) max = a;
			if(max < b) max = b;
		}

		rep(i,max+1) {
			rep(j,max+1) {
				rep(k,max+1) {
					int len = cost[i][j] + cost[j][k];
					if(len < ans[i][k]) {
						ans[i][k] = len;
					}
				}
			}
		}
		int min = inf, rmin = -1;
		rep(i,max+1) {
			int ret = 0;
			rep(j,max+1) {
				ret += ans[i][j];
			}
			if(min > ret) {
				min = ret;
				rmin = i;
			}
		}
		cout << rmin << " " << min << endl;
	}
	return 0;
}