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 <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime> 

using namespace std;
const int INF=10000000;
int maps[11][11];
int f,t,h;

void root(){
	int a,b;
	if(maps[f][t]>h)maps[f][t]=h;
	if(maps[t][f]>h)maps[t][f]=h;
	for(b=0;b<=10;b++){
		for(a=0;a<=10;a++){
			maps[a][b]=min(maps[a][b],maps[a][f]+maps[f][t]+maps[t][b]);
			maps[b][a]=min(maps[b][a],maps[a][f]+maps[f][t]+maps[t][b]);
		}
	}
}

int main(void){
	int a,b;
	int n;
	int town[11];
	int ans=INF*10;
	int ans3=0;
	while(1){
		for(b=0;b<=10;b++){
			town[b]=0;
			for(a=0;a<=10;a++){
				maps[a][b]=INF;
				if(a==b)maps[a][b]=0;
			}
		}
		ans=INF*10;
		ans3=0;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> f >> t >> h;
			town[f]=1;
			town[t]=1;
			root();
		}
		for(b=0;b<=10;b++){
			int ans2=0;
			if(town[b]==1){
				for(a=0;a<=10;a++){
					if(town[a]==1)ans2+=maps[a][b];
				}
				if(ans>ans2)ans3=b,ans=min(ans,ans2);
			}
		}
		cout << ans3 << ' ' << ans << endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;


	while (cin >> n && n != 0) {
		int min_ = 1000000000; // 答えの最小値
		int min_num = 1; // 答えの町
		int cost[100][100];
		int max_ = 0; // 町がどれだけあるか
		int from, to, time;

		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				cost[i][j] = 100000000;
			}
		}
		for (int i = 0; i < 100; i++) {
			cost[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> from >> to >> time;
			cost[from][to] = time;
			cost[to][from] = time;
			max_ = max(max(from, to), max_);
		}
		for (int i = 0; i <= max_; i++) {
			for (int j = 0; j <= max_; j++) {
				for (int k = 0; k <= max_; k++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		// 答えを求める
		for (int i = 0; i <= max_; i++) {
			int total = 0;
			for (int j = 0; j <= max_; j++) {
				total += cost[i][j];
			}
			if (total < min_) {
				min_ = total;
				min_num = i;
			}
		}
		cout << min_num << " " << min_ << endl;
  }
	return 0;
}

C++: #include<algorithm>
#include<limits.h>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>

using namespace std;

int C = 0;
int N = 0;
int R[10][10] = { 0 };
int M[10] = { 0 };

bool solve() {
	int sum = INT_MAX,ans = 0;
	for (int i = 0; i <= C; i++) {
		queue<int> q;
		q.push(i);
		M[i] = 0;
		while (!q.empty()) {
			for (int j = 0; j <= C; j++) {
				if (R[q.front()][j] != -1 && (M[j] == -1 || M[q.front()] + R[q.front()][j] < M[j])) {
					
					M[j] = R[q.front()][j] + M[q.front()];
					q.push(j);
				}
			}
			q.pop();
		}
		int s = 0;
		for (int j = 0; j <= C; j++)
			s += M[j];
		if (sum > s) {
			sum = s;
			ans = i;
		}
		memset(M, -1, sizeof(int) * 10);
	}
	printf("%d %d\n", ans,sum);
}

int main(void) {
	while(true){
		C = 0;
		memset(R, -1, sizeof(int) * 100);
		memset(M, -1, sizeof(int) * 10);
		scanf("%d", &N);
		if (N == 0)
			break;
		for (int j = 0; j < N; j++) {
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			R[a][b] = c;
			R[b][a] = c;
			C = max(C, max(a, b));
		}
		solve();
	}
}

C++: #include <iostream>
#include <map>
using namespace std;
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x>y?y:x)
#define INF 1000000
typedef map<int,int> M;

int cost[15][15];

int main()
{
	int n,sum;
	int max=0;
	M d;
	while(cin>>n,n){
		max=0;

		for(int i=0;i<15;i++){
			for(int j=0;j<15;j++){
				cost[i][j]=(i==j?0:INF);
			}
		}
		
		for(int i=0;i<n;++i){
			int a,b,c;
			cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
			if(max<MAX(a,b))max=MAX(a,b);

		}
		
		for(int i=0;i<=max;i++){
			for(int j=0;j<=max;j++){
				for(int k=0;k<=max;k++){
					cost[i][j]=MIN(cost[i][j],cost[i][k]+cost[k][j]);
				}
			}
		}
		
		for(int i=0;i<=max;i++){
			sum=0;
			for(int j=0;j<=max;j++){
				sum+=cost[i][j];
			}
			d[sum]=i;
		}
		M::iterator it=d.begin();
		cout<<(*it).second<<" "<<(*it).first<<endl;
		d.clear();
	}
	return 0;
}

C++: //2013/11/15(Fri)

#include <iostream>
using namespace std;
int main()
{
	
	while(true){
		int n;
		int a,b,c;
		int INF = 12001;
		int time[45][45];
		int dtime[45][45]={0};
		int sam[10] = {0};
		int min=12000,imin=0;
		cin >> n;
		if(n==0)
			break;
		for(int i=0; i<45; i++)
			for(int j=0; j<45; j++){
				if(i==j)
					time[i][j] = 0;
		
				else
					time[i][j] = INF;
			}

		for(int i=0; i<n; i++){
			cin >> a >> b >> c;
			time[a][b] = c;
			time[b][a] = c;
		}

		for(int i=0; i<45; i++)
			for(int j=0; j<45; j++)
				dtime[i][j] = time[i][j];

		for(int h=0; h<b+1; h++)
			for(int i=0; i<b+1; i++)
				for(int j=0; j<b+1; j++)
					if(dtime[i][j] > dtime[i][h] + dtime[h][j])
						dtime[i][j] = dtime[i][h] + dtime[h][j];
				
		
		for(int i=0; i<b+1; i++)
			for(int j=0; j<b+1; j++)
				sam[i] += dtime[i][j];


		for(int i=0; i<b+1; i++)
			if(sam[i] < min){
				min = sam[i];
				imin = i;
			}
			cout << imin << ' ' << min << endl;
	}
	return 0;
	
}

C++: #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 count1[m];
		for(int k=0;k<m;k++){
			int count=0;
			for(int i=0;i<m;i++){
				count=T[k][i]+count;
			}
			count1[k]=count;
		}
		int count2=count1[0];
		for(int k=0;k<m;k++){
			if(count1[k]<count2)
				count2=count1[k];
		}
		for(int k=0;k<m;k++){
			if(count1[k]==count2)
				cout<<k<<" "<<count2<<endl;
		}

	}

	return 0;
}