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<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<climits>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<fstream>
#include<iomanip>
#define pi 3.14159265358
using namespace std;
#define fout cout
#define fin cin
#define maxn 200000+10

#define clr(a) memset(a,0,sizeof(a))
int dist[100][100];
int jl[100][100];
int main()
{
    int n,u,v,d,i,j,k;
    int exist[100];
   while(cin>>n)
   {
       if(n==0) break;
       clr(exist);
       for(i=0;i<=30;i++)
        for(j=0;j<=30;j++)
       {
        jl[i][j]=dist[i][j]=9999999;
        if(i==j) jl[i][j]=dist[i][j]=0;
       }
       for(i=1;i<=n;i++)
       {

        scanf("%d%d%d",&u,&v,&d);
        exist[u]=exist[v]=1;
        dist[u][v]=dist[v][u]=d;
       }
       for(i=0;i<=10;i++)
        for(j=0;j<=10;j++)
        for(k=0;k<=10;k++)
       {

           dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
       }
       int tot[100];
       clr(tot);
       for(i=0;i<=10;i++)
       {
           if(!exist[i]) continue;
           for(j=0;j<=10;j++)
           {
           if(!exist[j]) continue;

            tot[i]+=dist[i][j];
           }
       }
       int mi=-1;
       for(i=0;i<=10;i++)
       {
           if(tot[i]==0) continue;
           if(mi==-1) mi=i;
           if(tot[mi]>tot[i]) mi=i;
       }

      cout<<mi<<" "<<tot[mi]<<endl;
   }
}

C++: #include <iostream>
#define INF 1000000
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int r[10][10];
		int m = 0;
		for(int i = 0; i < 10;++i)for(int j = 0; j < 10; ++j){
			r[i][j] = INF;
		}
		for(int i = 0; i < n; ++i){
			int a,b,c;
			cin >> a >> b >> c;
			r[a][b] = r[b][a] = c;
			m = max(max(a,b),m);
		}
		++m;
		for(int i = 0; i < m; ++i)r[i][i] = 0;
		for(int k = 0; k < m; ++k){
			for(int i = 0; i < m; ++i){
				for(int j = 0; j < m; ++j){
					r[i][j] = min(r[i][k]+r[k][j],r[i][j]);
				}
			}
		}
		int ans = INF;
		int t = 0;
		for(int i = 0; i < m; ++i){
			int tmp = 0;
			for(int j = 0; j < m; ++j){
				tmp += r[i][j];
			}
			if(ans > tmp){
				ans = tmp;
				t = i;
			}
		}
		cout << t << " " << ans << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#define INF 1 << 16
#define MAX_V 10
using namespace std;
int d[MAX_V+1][MAX_V+1];
int maxv;

void warshall_floyd() {
	for (int i = 0; i <= maxv; ++i) {
		for (int j = 0; j <= maxv; ++j) {
			for (int k = 0; k <= maxv; ++k) {
				d[i][j] = (d[i][k] + d[k][j] < d[i][j]) ? d[i][k] + d[k][j] : d[i][j];
			}
		}
	}
	return;
}

int main() {
	int m, a, b, c, minv, minsum;

	while (cin >> m, m) {
		for (int i = 0; i < MAX_V; ++i) {
			for (int j = 0; j < MAX_V; ++j) {
				d[i][j] = (i == j) ? 0 : INF;
			}
		}

		maxv = 0;
		while (m--) {
			cin >> a >> b >> c;
			maxv = (b > maxv) ? a : maxv;
			maxv = (b > maxv) ? b : maxv;
			d[a][b] = c;
			d[b][a] = c;
		}
		warshall_floyd();

		int sum[MAX_V] = { 0 };
		for (int i = 0; i <= maxv; ++i) {
			for (int j = 0; j <= maxv; ++j) {
				sum[i] += d[i][j];
			}
		}

		minsum = INF;
		for (int i = 0; i <= maxv; ++i) {
			if (sum[i] < minsum) {
				minv = i;
				minsum = sum[i];
			}
		}
		cout << minv << " " << minsum << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define inf 4510
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)
    {
        ///init
        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]=min(d[a][b],c);
            if(!idx[a])
            {
                idx[a]=1;
                cnt++;
            }
            if(!idx[b])
            {
                idx[b]=1;
                cnt++;
            }
        }
//        for(int i=0;i<=cnt;i++)
//            for(int j=0;j<=cnt;j++)
//            printf("d[%d][%d] == %d\n",i,j,d[i][j]);
//        cout<<"cnt == "<<cnt<<endl;
        warshall_floyd(cnt);

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

C++: //2013/11/15(Fri)

#include <iostream>
using namespace std;
int main()
{
	
	while(true){
		int n;
		int a,b,c;
		int INF = -1;
		int time[10][10];
		int m=0;
		int min=0,imin=0;
		cin >> n;
		if(n==0)
			break;
		for(int i=0; i<10; i++)
			for(int j=0; j<10; j++){
				if(i==j)
					time[i][j] = 0;
		
				else
					time[i][j] = INF;
			}

		for(int i=0; i<n; i++){
			cin >> a >> b >> c;
			time[a][b] = c;
			time[b][a] = c;
			if(m<a)
				m=a;
			if(m<b)
				m=b;
		}


		for(int h=0; h<m+1; h++)
			for(int i=0; i<m+1; i++)
				for(int j=0; j<m+1; j++)
					if(time[i][h]==INF||time[h][j]==INF)
                        continue;
                    else if(time[i][j]==INF)
                        time[i][j] = time[i][h]+time[h][j];
                    else if(time[i][j]>time[i][h]+time[h][j])
                        time[i][j] = time[i][h]+time[h][j];

									
		
		for(int i=1; i<m+1; i++)
			min += time[0][i];


		for(int i=1; i<m+1; i++){
            int sum = 0;
            for(int j=0; j<m+1; j++)
                sum += time[i][j];
            if(sum<min){
                imin = i;
                min = sum;
            }
        }

		cout << imin << ' ' << min << endl;
	}
	return 0;
	
}