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>
#include <utility>
#include <algorithm>
using namespace std;

struct Node{
    vector<pair<int, int> > to;
    bool isDone;
    int cost;
};

const int MAX_N = 10;
Node nodes[MAX_N + 1];
int n;

void dijkstra(int start) {
    for (int i = 0; i < n; i++) {
        nodes[i].isDone = false;
        nodes[i].cost = -1;
    }
    nodes[start].cost = 0;
    while (true) {
        int min_idx = -1;
        for (int i = 0; i < n; i++) {
            if (nodes[i].isDone == true || nodes[i].cost < 0) {
                continue;
            }
            if (min_idx < 0 || nodes[i].cost < nodes[min_idx].cost) {
                min_idx = i;
            }
        }
        if (min_idx < 0) {
            break;
        }
        nodes[min_idx].isDone = true;
        for (vector<pair<int, int> >::iterator it = nodes[min_idx].to.begin(); it != nodes[min_idx].to.end(); it++) {
            int to = it->first, cost = nodes[min_idx].cost + it->second;
            if (nodes[to].cost < 0 || cost < nodes[to].cost) {
                nodes[to].cost = cost;
            }
        }
    }
}

int main() {
    while (true) {
        int m;
        cin >> m;
        if (m == 0) {
            break;
        }
        n = 0;
        for (int i = 0; i < m; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            nodes[a].to.push_back(make_pair(b, c));
            nodes[b].to.push_back(make_pair(a, c));
            n = max(n, max(a, b));
        }
        n++;
        int mini = -1, min_idx;
        for (int i = 0; i < n; i++) {
            dijkstra(i);
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += nodes[j].cost;
            }
            if (mini < 0 || sum < mini) {
                mini = sum;
                min_idx = i;
            }
        }
        cout << min_idx << " " << mini << endl;
    }
}

C++: #include <cstdio>
#include <algorithm>

const int N = 15;
const int INF = 1 << 25;
int dist[N][N];
void chmin(int &a, int b) {
    a = std::min(a, b);
}

int main() {
    while(1) {
        int M; scanf("%d", &M);
        if(M == 0) break;

        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if(i != j) dist[i][j] = INF;
            }
        }

        int T = 0;
        for(int i=0; i<M; i++) {
            int a, b, c; scanf("%d%d%d", &a, &b, &c);
            chmin(dist[a][b], c);
            chmin(dist[b][a], c);
            T = std::max({T, a+1, b+1});
        }

        for(int k=0; k<T; k++) {
            for(int i=0; i<T; i++) {
                for(int j=0; j<T; j++) {
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }

        int ans = INF, idx = 0;
        for(int i=0; i<T; i++) {
            int sum = 0;
            for(int k=0; k<T; k++) {
                sum += dist[i][k];
            }
            if(ans > sum) {
                ans = sum;
                idx = i;
            }
        }
        printf("%d %d\n", idx, ans);
    }
    return 0;
}

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

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

		int m = 0;		

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}
		
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}
		int count1[m];
		for(int k=0;k<m;k++){
			int count=0;
			for(int i=0;i<m;i++){
				count=T[k][i]+count;
			}
			count1[k]=count;
		}
		int count2=count1[0];
		for(int k=0;k<m;k++){
			if(count1[k]<count2)
				count2=count1[k];
		}
		for(int k=0;k<m;k++){
			if(count1[k]==count2)
				cout<<k<<" "<<count2<<endl;
		}

	}

	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#define N 11
#define inf 10000000
using namespace std;
int d[N][N],V;
void warshall_floyd(void)
{
	for(int k=0;k<=V;k++)
	{
		for(int i=0;i<=V;i++)
		{
			for(int j=0;j<=V;j++)
			d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		}
	}
	return ;
}
void init(void)
{
	for(int i=0;i<N;i++)
	fill(d[i],d[i]+N,inf);
	for(int i=0;i<N;i++)
	d[i][i]=0;
	return ;
}
int main(void)
{
	int n;
	while(scanf("%d",&n)==1)
	{
		if(n==0)
		break;
		init();
		int s,e,c;
		V=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",&s,&e,&c);
			d[s][e]=d[e][s]=c;
			V=max(V,max(s,e));
		}
		warshall_floyd();
		int ans=inf;
		int sum=0;
		int id=0;
		for(int i=0;i<=V;i++)
		{
			sum=0;
			for(int j=0;j<=V;j++)
			sum+=d[i][j];
			if(sum<ans)
			{
				ans=sum;
				id=i;
			}
		}
		printf("%d %d\n",id,ans);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
int fp[15][15];
int m;
void floyd()
{
   for(int i=0;i<m;i++)
      for(int j=0;j<m;j++)
      for(int k=0;k<m;k++)
   {
      fp[i][k]=min(fp[i][k],fp[i][j]+fp[j][k]);
   }
}
int main()
{
   int n;
   while(scanf("%d",&n),n)
   {
      m=0;
      memset(fp,INF,sizeof(fp));
      for(int i=0;i<n;i++)
      {
         int a,b,c;
         scanf("%d%d%d",&a,&b,&c);
         fp[a][b]=fp[b][a]=c;
         m=max(m,max(a,b)+1);
      }
      for(int i=0;i<m;i++)
         fp[i][i]=0;
      floyd();
      int ans,sum=INF;
      for(int i=0;i<m;i++)
      {
         int res=0;
         for(int j=0;j<m;j++)
         {
            res+=fp[i][j];
         }
         if(res<sum)
         {
            sum=res;
            ans=i;
         }
      }
      cout<<ans<<" "<<sum<<endl;
   }
}