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 <vector>
using namespace std;
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x>y?y:x)
#define INF 1000000
typedef long long ll;
typedef pair<int,ll> P;

ll cost[15][15];

int main()
{
	int n;
	ll sum,min=INF;
	vector<P> vec;
	P min_p;
	int max=0;
	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;
			ll 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];
			}
			vec.push_back(P(i,sum));
		}
		for(vector<P>::iterator it=vec.begin();it!=vec.end();++it){
			if(min>(*it).second){
				min=(*it).second;
				min_p=*it;
			}
		}
		cout<<min_p.first<<" "<<min_p.second<<endl;
		vec.clear();
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;

#define N 150
int inf=99999999;
int e[N][N];
int mark[N];
int m;
void init(int n)
{
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
        {
            if(i==j)e[i][j]=0;
            else
                e[i][j]=inf;
        }
}

void floyd(int n)
{
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
            for(int k=0; k<=n; k++)
            {
                    if(e[j][k]>e[j][i]+e[i][k])
                    {
                        e[j][k]=e[j][i]+e[i][k];
                    }
            }
}

int main()
{
    while(scanf("%d",&m),m!=0)
    {
        int n=-1;
        int a,b,c;
        init(150);
        memset(mark,0,sizeof(mark));
        while(m--)
        {
            scanf("%d%d%d",&a,&b,&c);
            e[a][b]=e[b][a]=c;
            if(a>n)n=a;
            if(b>n)n=b;
            mark[a]=1;
            mark[b]=1;
        }

        floyd(n);
        int ans1,ans2;
        ans1=ans2=inf;
        for(int i=0; i<=n; i++)
        {
            int sum=0;
            if(mark[i]==1)
            {

                for(int j=0; j<=n; j++)
                {
                    if(mark[j]==1&&e[i][j]!=inf)
                    {
                        sum+=e[i][j];
                    }
                }
            }
            if(sum<ans2)
            {
                ans2=sum;
                ans1=i;
            }
        }
        printf("%d %d\n",ans1,ans2);
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
const int INF = 1 << 20;
const int N = 11;
int tim[N][N];
using namespace std;
int main()
{
	int a, b, ti, n;
	while (1){
		cin >> n;
		if (n == 0)break;

		for (int i = 0; i < N; i++){
			for (int i2 = 0; i2 < N; i2++){
				if (i != i2){
					tim[i][i2] = INF;
				}
				else
					tim[i][i2] = 0;

			}
		}

		int m = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b >> ti;
			tim[a][b] = ti;
			tim[b][a] = ti;
			m = max(m, a);
			m = max(m, b);
		}

		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++){
					tim[i][j] = min(tim[i][j], tim[i][k] + tim[k][j]);
				}

		int mint = INF;
		vector<int>p;
		for (int i = 0; i <= m; i++){
			int mt = 0;
			for (int i2 = 0; i2 <= m; i2++){
					mt += tim[i][i2];
			}
			p.push_back(mt);
			mint = min(mt, mint);
		}

		for (int i = 0; i <= p.size(); i++){
			if (p[i] == mint){
				cout << i << " " << mint << endl;
				break;
			}
		}
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int ans=987654;
		int cnt[2]={0};
		int	dp[11][11];
		int memo[11]={};
		for(int i=0;i<11;i++){
			for(int j=0;j<11;j++){
				dp[i][j]=987654;
			}
		}
		if(n==0)break;
		int a,b,c;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			dp[a][b]=c;
			dp[b][a]=c;
			memo[a]++;
			memo[b]++;
		}
		int N=0;
		for(int i=0;i<10;i++){
			if(memo[i]>0){
				N++;
			}
		}
		for(int m=0;m<N;m++){
		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]);
				}
			}
		}
		cnt[1]=0;
		for(int i=0;i<N;i++){
			cnt[1]+=dp[m][i];
		}
		cnt[1]-=dp[m][m];
		if(ans>cnt[1]){
			cnt[2]=m;
			ans=cnt[1];
		}
		}
		cout<<cnt[2]<<" "<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>  
#include<algorithm>  
#include<string.h>  
#include<math.h>  
#include<stdio.h>  
#include<queue>  
#define INF 0x3f3f3f3f  
typedef long long ll;  
using namespace std;  
  
#define  N 15  
int n;  
int dis[N],maps[N][N];  
int main()  
{  
    int i,a,b,c,j,k;  
    while(scanf("%d",&n),n)  
    {  
        for(i=0;i<N;i++)  
        {  
            for(j=0;j<N;j++)  
            {  
                maps[i][j]=(i==j)?0:INF;  
            }  
        }  
  
        int m=-1;  
        for( i=0; i<n; i++)  
        {  
            scanf("%d%d%d",&a,&b,&c);  
            m=max(a,m);  
            m=max(b,m);  
            maps[a][b]=maps[b][a]=c;  
        }  
  
        for(k=0;k<=m;k++)  
        {  
            for(i=0;i<=m;i++)  
            {  
                for(j=0;j<=m;j++)  
                {  
                    if(maps[i][j]>maps[i][k]+maps[k][j])  
                        maps[i][j]=maps[i][k]+maps[k][j];  
                }  
            }  
        }  
  
        int  Min=INF;  
        int index=-1;  
        memset(dis,0,sizeof(dis));  
        for(i=0;i<=m;i++)  
        {  
            for(j=0;j<=m;j++)  
            {  
                dis[i]=dis[i]+maps[i][j];  
            }  
            if(Min>dis[i])  
            {  
                index=i;  
                Min=dis[i];  
            }  
        }  
        printf("%d %d\n",index,Min);  
    }  
    return 0;  
}