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<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>

#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;
const int MAX = 10;
const int INF = INT_MAX/3;
int main(){
  ios::sync_with_stdio(false);
  int cost[MAX][MAX];
  bool existTown[MAX];
  int n;
  while(cin >> n && n != 0){
    fill(*cost,*(cost+MAX),INF);
    fill(existTown,existTown+MAX,false);
    for(int i = 0;i < n;i++){
      int a,b,c;
      cin >> a >> b >> c;
      cost[a][b] = cost[b][a] = c;
      existTown[a] = existTown[b] = true;
    }

    for (int k = 0; k < MAX; ++k){
      for (int j = 0; j < MAX; ++j){
	for (int i = 0; i < MAX; ++i){
	  int sum = cost[i][k] + cost[k][j];
	  if(cost[i][j] > sum){
	    cost[i][j] = cost[j][i] = sum;
	  }
	}
      }
    }
    /*
    for (int i = 0; i < MAX; ++i){
      for (int j = 0; j < MAX; ++j){
	if(cost[i][j] == INF)cout << INF;
	else cout << cost[i][j];
	cout << ' ';
      }
      cout << endl;
    }
    */
    int ans = 100;
    int mini = INF;
    for(int i = 0;i < MAX;i++){
      if(!existTown[i])continue;
      int sum = 0;
      for(int j = 0;j < MAX;j++){
	if(existTown[j] && j != i)sum += cost[i][j];
      }
      if(mini > sum){
	mini = sum;
	ans = i;
      }
    }
    cout << ans  << ' ' << mini << endl;
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while(cin>>n,n){  //,演算子、最後の式を評価
    
        vector<vector<int>> graph(10,vector<int>(10,99999999));
        int used[10]={0};
        for(int i=0;i<n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            graph[a][b]=c;
            graph[b][a]=c;
            used[a]++;
            used[b]++;
        }
        for(int i=0;i<10;i++){
            graph[i][i]=0;
        }
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<10;k++){
                    if(graph[i][j]>graph[i][k]+graph[k][j])
                        graph[i][j]=graph[i][k]+graph[k][j];
                }
            }
        }
        int min=99999999;
        int minpos;
        for(int i=0;i<10;i++){
            if(used[i]==0) continue;
            int sum=0;
            for(int j=0;j<10;j++){
                if(used[j]>0){
                    sum+=graph[i][j];
                }
            }
            if(min>sum){
                min=sum;
                minpos=i;
            }
        }
        cout<<minpos<<" "<<min<<endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long LL;
#define N 2010
#define INF 0x3f3f3f

int n;
int maps[N][N];
int dist[N], vis[N];

void Init(int m)
{
    for(int i=0; i<=m; i++)
        for(int j=0; j<=m; j++)
        maps[i][j]=i==j ? 0 : INF;
}

void dij(int s, int m)
{
    for(int i=0; i<=m; i++)
        dist[i]=maps[s][i];
    memset(vis, 0, sizeof(vis));
    vis[s]=1;

    for(int i=0; i<=m; i++)
    {
        int Min=INF, index=-1;
        for(int j=0; j<=m; j++)
        {
            if(!vis[j]&&dist[j]<Min)
            {
                Min=dist[j];
                index=j;
            }
        }
        if(index==-1) continue;
        vis[index]=1;
        for(int j=0; j<=m; j++)
        {
            if(!vis[j]&&dist[j]>Min+maps[index][j])
                dist[j]=Min+maps[index][j];
        }
    }
}

int main()
{
    int a, b, c, Max, index, sum;
    while(scanf("%d", &n), n)
    {
        Init(1100);
        Max=-1;
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d%d", &a, &b, &c);
            maps[a][b]=maps[b][a]=min(maps[a][b], c);
            Max=max(Max, a);
            Max=max(Max, b);
        }
        int s;
        sum=INF;
        for(int i=0; i<=Max; i++)
        {
            dij(i, Max);
            s=0;
            for(int j=0; j<=Max; j++)
                s+=dist[j];
            if(s<sum)
            {
                index=i;
                sum=s;
            }
        }
        printf("%d %d\n", index, sum);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = 10+5;
int d[maxn][maxn],idx[maxn];
void warshall_floyd(int n)
{
    for(int k=0; k<n; k++)
        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}

int main()
{
    int N;
    while(scanf("%d",&N)!=EOF&&N)
    {
        memset(idx,0,sizeof(idx));
        for(int i=0; i<N; ++i)
        {
            for(int j=0; j<i; ++j)
            {
                d[i][j]=d[j][i]=inf;
            }
            d[i][i]=0;
        }

        int a,b,c,cnt=0;
        for(int i=1; i<=N; ++i)
        {
            scanf("%d%d%d",&a,&b,&c);
            d[a][b]=d[b][a]=c;
            if(!idx[a])
            {
                idx[a]=1;
                cnt++;
            }
            if(!idx[b])
            {
                idx[b]=1;
                cnt++;
            }
        }

        warshall_floyd(cnt);

        int Min=inf,num;
        for(int i=0; i<cnt; ++i)
        {
            int sum=0;
            for(int j=0; j<cnt; ++j)
            {
                if(d[i][j]!=inf)
                    sum+=d[i][j];
            }
            if(Min>sum)
            {
                Min=sum,num=i;
            }
        }
        printf("%d %d\n",num,Min);
    }
}

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;
}