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>

// int inf = 1 << 28;
int inf = 100000000;

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;
		used[i]=false;
	}
	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<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++: /*
 * 1.cpp
 *
 *  Created on: 2015-10-29
 *      Author: hp
 */
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define mem(a) memset(a,0,sizeof(a))
#define pfn printf("\n")
#define ll __int64
#define pfd(a) printf("%d\n",a)
#define pf2d(a,b) printf("%d %d\n",a,b)
#define pf3d(a,b,c) printf("%d %d %d\n",a,b,c)
#define pfs(a) printf("%s\n",a)
#define sfd(a) scanf("%d",&a)
#define sf2d(a,b) scanf("%d%d",&a,&b)
#define sf3d(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define sf	scanf
#define pf	printf
#define fr(i,n) for(int i=0;i<n;i++)
#define INF 0x7fffffff   //INT_MAX
#define inf 0x3f3f3f3f   //int
const double PI = acos(-1.0);
const double e = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> inline T Min(T a, T b) { return a < b ? a : b; }
template<class T> inline T Max(T a, T b) { return a > b ? a : b; }
bool cmpbig(int a,int b){return a>b;}
bool cmpsmall(int a,int b){return a<b;}
using namespace std;
int dp[20][20];
int n;
void floyd(){
    for(int k=0;k<n;k++)
    	for(int i=0;i<n;i++)
    		for(int j=0;j<n;j++)
    			dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
}
int main()
{
	//freopen("1.txt","r",stdin);
	
	int x,y;
    int d;
    while(~scanf("%d",&n) &&n){
    	int max_n=-1;
       for(int i=0;i<n;i++)
    	   for(int j=0;j<n;j++)
    		   dp[i][j]=inf;
       for(int i=0;i<n;i++){
    	   scanf("%d %d %d",&x,&y,&d);
    	   dp[x][y]=d;
    	   dp[y][x]=d;
    	   dp[i][i]=0;
    	   int tem=max(x,y);
    	   max_n=max(tem,max_n);
    	  //printf("%d %d d=%d\n",dp[x][y],dp[y][x],d);
       }
        floyd();
        int ans=inf;
        int pos;
        int sum=0;

        for(int i=0;i<=max_n;i++){
            sum=0;
        	for(int j=0;j<=max_n;j++){
        		if(dp[i][j]<inf && dp[i][j]!=0)
        		  sum+=dp[i][j];
        	}
            if(sum<ans){
            	ans=sum;
            	pos=i;
            	//printf("ans=%d i=%d\n",ans,pos);
            }
       }

        printf("%d %d\n",pos,ans);
    }

	return 0;
}