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 = 2 << 35;

int main()
{

	int data[11][11];
	int n;
	int a, s, d;
	int ans, anssum;
	int sum = 0;

	while (true)
	{

		for (int i = 0; i<10; i++)
		{
			for (int k = 0; k<10; k++)
			{
				data[i][k] = INF;
			}
		}

		cin >> n;

		if (n == 0)return 0;

		for (int i = 0; i< n; ++i)
		{
			cin >> a >> s >> d;
			data[a][s] = d;
			data[s][a] = d;
		}

		for (int i = 0; i<10; i++)
		{
			for (int k = 0; k<10; k++)
			{
				for (int m = 0; m<10; m++)
				{
					if (data[i][k] > data[i][m] + data[m][k])
					{
						data[i][k] = data[i][m] + data[m][k];
						data[k][i] = data[i][m] + data[m][k];
					}
				}
			}
		}
		anssum = INF;
		for (int i = 0; i<10; ++i)
		{
			sum = 0;
			for (int k = 0; k < 10; ++k)
			{
				sum += data[i][k];
			}
			if (sum < anssum)
			{
				ans = i;
				anssum = sum;
			}
		}
		cout << ans << " " << anssum << "\n";
	}

}

C++: #include <iostream>  
#include <vector>  
#include<algorithm>
using namespace std; 

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d; // ??°??????????????¢???????´???????2?¬???????????????£??\?????????
          // d[u][v]??????e=(u,v)??????????????????????????¨???????????´??????INF????????????d[i][i]=0???

void warshall_floyd(int n) { // n???????????°
  for (int i = 0; i < n; i++)      // ?????±????????????
    for (int j = 0; j < n; j++)    // ????§???????
      for (int k = 0; k < n; k++)  // ??????
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
    int n;
    int ans_min = 100000;
    int ans[10];
    int number; 

    while(1){    
        for(int i=0; i<10; i++){
            ans[i] = 0;
        }

        d = Matrix(10, vector<int>(10, INF));
        for (int i = 0; i < 10; i++) d[i][i] = 0;
        
        cin >> n;
        if(n == 0){
            break;
        }

        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            d[from][to] = cost;
            d[to][from] = cost;
        }
        
        warshall_floyd(10);
        
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
            if (i != j && d[i][j] != INF)
                //cout << i << "??????" << j << "???????????????: " << d[i][j] << endl;
                ans[i] += d[i][j];
            }
            //cout<< ans[i]<<endl;
            if(ans_min>ans[i] &&ans[i] !=0){
                ans_min = ans[i];
                number = i;
            }
        }

        cout << number << " " << ans_min << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int N;
int D[10][10];
int a,b,c;
int M[10];
bool F[10];
int town;
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)break;
		for(int i=0;i<10;i++)for(int j=0;j<10;j++)D[i][j]=10000001;
		
		town=0;
		for(int i=0;i<N;i++){
			scanf("%d%d%d",&a,&b,&c);
			D[a][b]=c;
			D[b][a]=c;
			town=max(town,max(a,b));
		}
		int ans=100000001;
		int ansm;
		town++;
		for(int s=0;s<town;s++){
			for(int i=0;i<town;i++)F[i]=false;
			for(int i=0;i<town;i++)M[i]=10000001;
			M[s]=0;
			while(true){
				for(int i=0;i<town;i++){
					if(!F[i])goto a;
				}
				break;
a:;
				int v=-1;
				int mi=10000001;
				for(int i=0;i<town;i++){
					if(!F[i]){
						if(mi>=M[i]){
							mi=M[i];
							v=i;
						}
					}
				}
				F[v]=true;
				
				for(int i=0;i<town;i++){
					M[i]=min(M[i],M[v]+D[v][i]);
				}
			}
			int sum=0;
			for(int i=0;i<town;i++){
				sum+=M[i];
			}
			if(ans>sum){
				ans=sum;
				ansm=s;
			}
		}
		printf("%d %d\n",ansm,ans);
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 200000000
int main()
{
	int e;
	while(cin >> e&&e)
	{
		int i,j,t,k,v=0,ans=INF;
		int d[10][10];
		int cost_count[10] = {0};
		for(i=0;i<10;i++)
		{
			for(j=0;j<10;j++)
			{
				d[i][j] = INF;
				if(i==j)
				{
					d[i][j] = 0;
				}
			}
		}
		for(t=0;t<e;t++)
		{
			scanf("%d %d %d",&i,&j,&k);
			v = max(v,max(i,j));
			d[i][j] = k;
			d[j][i] = k;
		}
		for(k=0;k<=v;k++)
		{
			for(i=0;i<=v;i++)
			{
				for(j=0;j<=v;j++)
				{
					d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		for(i=0;i<=v;i++)
		{
			int cost = 0;
			for(j=0;j<=v;j++)
			{
				cost += d[i][j];
			}
			cost_count[i] = cost;
			ans=min(ans,cost_count[i]);

		}
		for(i=0;i<=v;i++)
		{
			if(cost_count[i]==ans)
			{
				printf("%d %d\n",i,ans);
				break;
			}
		}
	}
	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
const lnt INF = 0xffffffffffffff;
lnt d[10][10];
lnt n,x,y,z;
lnt used[10];
int main()
{while(1){
	cin>>n;
	if(!n) return 0;
	fill(d[0],d[10]+10,INF);
	fill(used,used+10,0);
	for(lnt i=0;i<n;i++){
		cin>>x>>y>>z;
		used[x]=1;
		used[y]=1;
		d[x][y]=z;
		d[y][x]=z;
	}
	for(lnt i=0;i<10;i++){
		if(used[i]) d[i][i]=0;
	}
	for(lnt i=0;i<10;i++){
		for(lnt j=0;j<10;j++){
			for(lnt k=0;k<10;k++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
				d[j][i]=min(d[j][i],d[j][k]+d[k][i]);
			}
		}
	}
	P ans=P(-1,INF);
	lnt sum;
	for(lnt i=0;i<10;i++){
		if(!used[i]) continue;
		sum=0;
		for(lnt j=0;j<10;j++){
			if(!used[i]) continue;
			sum+=d[i][j];
		}
		if(ans.second>sum){
			ans.first=i;
			ans.second=sum;
		}
	}
	cout<<ans.first<<' '<<ans.second<<endl;
}}

C++: 
#include <iostream>
#include <cmath>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

typedef long long ll;

const int M = 10;
const int INF = 1000000000;
ll w[M+1][M+1];

int main()
{
    int n, m;
    while(cin >> n && n) {

        int a, b, c;
        m = 0;

        for(int i = 0; i <= M; i++) {
            for(int j = 0; j <= M; j++) {
                if(i == j) w[i][j] = 0;
                else w[i][j] = INF;
            }
        }

        for(int i = 0; i < n; i++) {
            cin >> a >> b >> c;
            w[a][b] = w[b][a] = c;
            m = max(m, max(a,b)); 
        }
        
        for(int i = 0; i <= m; i++) 
            for(int k = 0; k <= m; k++) 
                for(int j = 0; j <= m; j++) 
                    w[i][j] = min(w[i][j], w[i][k] + w[k][j]);

        ll sum = INF * 10, idx = 0, tmp = 0;
        for(int i = 0; i <= m; i++) {
            tmp = 0;
            for(int j = 0; j <= m; j++) tmp += w[i][j];
            if(tmp < sum) {
                idx = i;
                sum = tmp;
            }
        }

        cout << idx << " " << sum << endl;
        
    }
    return 0;
}