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++: //{Headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<queue>
#include<deque>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<bitset>

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp(x,y) make_pair(x,y)
typedef long long ll;
//}

const int MAXN=10,INF=0x3f3f3f3f;
int N,M,g[MAXN][MAXN];

void init(){
    memset(g,INF,sizeof g);
    for(int i=0;i<MAXN;i++) g[i][i]=0;
}

void solve(){
    for(int k=0;k<N;k++) for(int i=0;i<N;i++) for(int j=0;j<N;j++)
        g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
    int ans=-1,ansT=INF;
    for(int i=0;i<N;i++){
        int sum=0;
        for(int j=0;j<N;j++) sum+=g[i][j];
        if(sum<ansT){
            ans=i;
            ansT=sum;
        }
    }
    printf("%d %d\n",ans,ansT);
}

int main(void){
//    freopen("in.txt","r",stdin);
    int a,b,c;
    while(~scanf("%d",&M) && M!=0){
        init();
        N=1;
        for(int i=0;i<M;i++){
            scanf("%d%d%d",&a,&b,&c);
            N=max(N,1+max(a,b));
            g[a][b]=g[b][a]=c;
        }
        solve();
    }
    return 0;
}

/*
Sample Input
6
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0
Output for the Sample Input
2 240
1 2
*/

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<string.h>
#include<set>
#define MAX_N 50
#define INF 10000
using namespace std;
int d[MAX_N][MAX_N];
int N;
void floyed(int  X) {
	for (int k = 0; k<X; k++) {
		for (int i = 0; i<X; i++) {
			for (int j = 0; j<X; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}
int main() {
	while (true) {
		set<int> s;
		cin >> N;
		if (N <= 0)
			break;
		for (int i = 0; i<MAX_N; i++) {
			for (int j = 0; j<MAX_N; j++) {
				d[i][j] = INF;
				if (i == j)
					d[i][j] = 0;
			}
		}
		
		for (int i = 0; i<N; i++) {
			int from, to, costs;
			cin >> from >> to >> costs;
			d[from][to] = costs;
			d[to][from] = costs;
			s.insert(to);
			s.insert(from);
		}
		floyed(s.size());
		int misum = INF;
		int no;
		for (int i = 0; i<s.size(); i++) {
			int sum = 0;
			for (int j = 0; j<s.size(); j++) {
				if (i != j&&d[i][j]!=INF)
					sum += d[i][j];
			}
			if (sum < misum) {
				misum = sum;
				no = i;
			}
		}
	
		cout << no<<" "<<misum << endl;
		
	}
	
}

C++: #include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#define INF 0xffff
#define lld long long int
#define MAXN 1000002
using namespace std;

//floyd
int d[12][12];


void floyd(int x)
{
	for (int k = 0;k <= x;k++)
		for (int i = 0;i <= x;i++)
			for (int j = 0;j <= x;j++)
			{
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				d[j][i] = d[i][j];
			}
}


int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		if (n == 0)break;
		int v = 0;
		for (int i = 0;i <= 12;i++)
		{
			for (int j = 0;j <= 12;j++)
			{
				if (i == j)d[i][j] = 0;
				else d[i][j] = INF;
			}
			
		}
		for (int i = 0;i < n;i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			scanf("%d", &d[a][b]);
			d[b][a] = d[a][b];
			v = max(a, b);
		}
		floyd(v);
		int t;
		int ans=INF;
		for (int i = 0;i <= v;i++)
		{
			int tmp = 0;
			for (int j = 0;j <= v;j++)
			{
				if (i == j)continue;
				tmp += d[j][i];
			}
			if (ans > tmp)
			{
				t = i;
				ans = tmp;
			}
		}
		printf("%d %d\n", t, ans);

	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#define INF 0x3f3f3f
int max(int a,int b)
{
	return a>b?a:b;
}
int map[110]110],visit[110],vis[110];
int n,m;
int dijkstra(int a)
{
	memset(visit,0,sizeof(visit));
	int i,j,next,sum,min;
	for(i=0;i<m;i++)
	vis[i]=map[a][i];
	visit[a]=1;
	for(i=0;i<m;i++)
	{
		min=INF;
		for(j=0;j<m;j++)
		{
			if(!visit[j]&&min>vis[j])
			{
				next=j;
				min=vis[j];
			}
		}
		visit[next]=1;
		for(j=0;j<m;j++)
			if(!visit[j]&&vis[j]>vis[next]+map[next][j])
			vis[j]=vis[next]+map[next][j];
	}
	sum=0;
	for(i=0;i<m;i++)
	sum+=vis[i];
	return sum;
}
int main()
{
	int i,j,sum;
	int a,b,c;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<110;i++)
		for(j=i;j<110;j++)
		{
			if(i==j)
			map[i][j]=map[j][i]=0;
			else
			map[i][j]=map[j][i]=INF;
		}
		m=0;
		while(n--)
		{
			scanf("%d%d%d",&a,&b,&c);
			map[a][b]=map[b][a]=c;
			m=max(m,max(a,b)+1);
		}
		sum=INF;
		for(i=0;i<m;i++)
		{
			if(sum>dijkstra(i))
			{
				j=i;
				sum=dijkstra(i);
			}			
		}
		printf("%d %d\n",j,sum);
	}
	return 0;
}