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>
using namespace std;

const int INF = 1000000000;

int main()
{
	int n;
	while(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 M[10];
		for(int i = 0;i < m;i++){
			M[i]=0;
			for(int j = 0;j < m;j++){
				M[i] += T[i][j];
			}
		}
		
		int index = 0;
		for(int i = 1;i < m;i++){
			if(M[index] > M[i]){
				index = i;
			}
		}
		cout << index << ' ' << M[index] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define INF (1<<29)

int main(){
	int m,n;//町,道
	int d[10][10];
	while(cin>>n,n){
		fill_n((int*)d,10*10,INF);
		m=0;
		for(int i=0;i<n;i++){
			int a,b,c;
			cin>>a>>b>>c;
			m=max(m,max(a,b)+1);
			d[a][b]=d[b][a]=c;
		}
		for(int i=0;i<m;i++){
			d[i][i]=0;
		}
		for(int k=0;k<m;k++)
			for(int i=0;i<m;i++)
				for(int j=0;j<m;j++)
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		int a=0,b=INF;
		for(int i=0;i<m;i++){
			int sum=0;
			for(int j=0;j<m;j++)sum += d[i][j];
			if(sum<b){
				a=i;
				b=sum;
			}
		}
		cout<<a<<' '<<b<<endl;
	}
}

C++: #include <iostream>

int inf = 1 << 28;

int dijk(int n,int s, int **g) {
	int sum = 0;
	bool *used = new bool[n];
	int *d = new int[n];

	// std::cout << "n = " << n << " " << "s = " << s << std::endl;

	for(int j=0;j<n;j++){
		for(int i=0;i<n;i++){
			std::cout << g[j][i] << ",";
		}
		std::cout << std::endl;
	}

	for(int i = 0; i < n; i++)
		d[i] = inf;
	d[s] = 0;

	while(true) {
		int u = -1;
		for(int v = 0; v < n; v++)
			if(!used[v] && (u == -1 || d[v] < d[u]))
				u = v;

		// std::cout << "u = " << u << std::endl;

		if(u == -1) break;
		used[u] = true;

		for(int v = 0; v < n; v++)
			if(d[v] > d[u] + g[u][v])
				d[v] = d[u] + g[u][v];
	}

	for(int i = 0; i < n; i++) {
		sum += d[i];
	}

	// for(int i = 0; i < n; i++) {
	// std::cout << d[i] << std::endl;
	// }

	return sum;
}

int main() {
	do {
		int **g; // adjacency matrix, ?
		int *d;
		int *a, *b, *c;
		int edge = 0, min = 0, max = 0;
		int tmp = 0;

		std::cin >> edge;
		if(!edge) break;

		a = new int[edge];
		b = new int[edge];
		c = new int[edge];

		for(int i = 0;i < edge;i++) {
			std::cin >> a[i];
			std::cin >> b[i];
			std::cin >> c[i];
		}

		for(int i = 0; i < edge; i++) {
			if(max < a[i])
				max = a[i];
		}
		for(int i = 0; i < edge; i++) {
			if(max < b[i])
				max = b[i];
		}
		max++;

		g = new int*[max];
		d = new int[max];

		for(int i = 0; i < max; i++) {
			g[i] = new int[max];
		}

		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				g[i][j] = inf;

		for(int i = 0; i < edge; i++)
			g[b[i]][a[i]] = g[a[i]][b[i]] = c[i];

		for(int i=0;i<max;i++){
			g[i][i]=0;
		}

		for(int k=0;k<max;k++){
			for(int j=0;j<max;j++){
				for(int i=0;i<max;i++){
					if(g[i][k]+g[k][j]<g[i][j]){
						g[i][j]=g[i][k]+g[k][j];
					}
				}
			}
		}

		//for(int i = 0; i < max; i++)
		//	d[i] = dijk(max, i, g);

		for(int i = 0; i < max; i++){
			d[i]=0;
			for(int j=0;j<max;j++){
				d[i] += g[i][j];
			}
		}

		min = d[0];
		for(int i = 1; i < max; i++) {
			if(min > d[i]) {
				min = d[i];
				tmp = i;
			}
		}

		std::cout << tmp << " " << min << std::endl;
		for(int i = 0; i < max; i++)
			delete[] g[i];
		delete[] g;
		delete[] a;
		delete[] b;
		delete[] c;
		delete[] d;

	}while(true);
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

#define INF 1<<24
#define MAX_V 999

using namespace std;

int dat[10][10];

int main(){
	int a, b, c, num;
	int n;
	while(cin>>n,n){
		num=0;
		rep(i,10){
			rep(j,10){
				if(i==j){
					dat[i][j]=0;
				}else{
					dat[i][j]=INF;
				}
			}
		}
		rep(i,n){
			cin>>a>>b>>c;
			dat[a][b]=c;dat[b][a]=c;
			num=max(num,max(a,b));
		}
		num++;
		rep(i,num){
			rep(j,num){
				rep(k,num){
					dat[j][k]=min(dat[j][k],dat[j][i]+dat[i][k]);
				}
			}
		}
		
		
		int sum, mC=INF,id;
		rep(i,num){
			sum=0;
			rep(j,num){
				sum+=dat[i][j];
			}
			if(sum<mC){
				mC=sum;id=i;
			}
		}
		cout<<id<<" "<<mC<<endl;
	}
	return 0;
}

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

#define INF 1000000

using namespace std;

int main(void){
	int n;
	while(cin >> n && n){
		int f[10][10];
		fill((int*)f, (int*)f+10*10, INF);
		int s,t,cost;
		int maxi=0;
		for(int i=0;i<n;i++){
			cin >> s >> t >> cost;
			maxi = max(max(maxi,s),t);
			f[s][t] = cost;
			f[t][s] = cost;
		}
		for(int i=0;i<=maxi;i++) f[i][i] = 0;
		//WF
		for(int k=0;k<=maxi;k++){
			for(int i=0;i<=maxi;i++){
				for(int j=0;j<=maxi;j++){
					f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
				}
			}
		}
		int tmp,index;
		int ret = INF;
		for(int i=0;i<=maxi;i++){
			tmp = 0;
			for(int j=0;j<=maxi;j++){
				tmp += f[i][j];
			}
			if(tmp < ret){
				ret = tmp;
				index = i;
			}
		}
		cout << index << " " << ret << endl;
	}
}