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<bits/stdc++.h>
using namespace std;

enum { maxn = 50, INF = 1000000000 };

int G[maxn][maxn];
int vis[maxn];
int d[maxn][maxn];
int inq[maxn];
int m;

void spfa(int src)
{
    memset(inq, 0, sizeof inq);
    for(int i = 0; i < maxn; i++) d[src][i] = INF;
    d[src][src] = 0;
    queue< int > q;
    q.push(src);
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(int i = 0; i < maxn; i++)
        {
            if(G[u][i])
            {
                if(d[src][u] + G[u][i] < d[src][i])
                {
                    d[src][i] = d[src][u] + G[u][i];
                }
                if(!inq[i])
                {
                    inq[i] = 1;
                    q.push(i);
                }
            }
        }
    }
}

int main()
{
    while(~scanf("%d", &m), m)
    {
        memset(vis, 0, sizeof(vis));
        memset(G, 0, sizeof(G));
        memset(d, 0, sizeof(d));
        for(int i = 0; i < m; i++)
        {
            int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
            G[a][b] = G[b][a] = c;
            vis[a] = vis[b] = 1;
        }
        for(int i = 0; i < maxn; i++)
            if(vis[i])
                spfa(i);
        int ans = INF, pt = -1;
        for(int i = 0; i < maxn; i++)
        {
            int sum = 0;
            if(vis[i])
            {
                for(int j = 0; j < maxn; j++)
                {
                    if(vis[j])
                    {
                        sum += d[i][j];
                    }
                }
                if(sum < ans)
                {
                    ans = sum;
                    pt = i;
                }
            }
        }
        printf("%d %d\n", pt, ans);
    }
    return 0;
}

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

const int INF = 10000;
int cost[10][10];

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

int main()
{
	int n;
	while(cin >> n){
		if(n==0)
			break;
		init();
		int a,b,c,m=0;
		for(int i=0;i<n;i++){
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			if(m < max(a,b))
				m = max(a,b);
		}
		m++;
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				for(int k=0;k<m;k++){
					int cdis = cost[j][i] + cost[i][k];
					if(cdis < cost[j][k]){
						cost[j][k] = cdis;
					}
				}
			}
		}
		int mati,min_cost=100000000;
		for(int i=0;i<m;i++){
			int costs = 0;
			for(int j=0;j<m;j++){
				costs += cost[i][j];
			}
			if(min_cost > costs){
				min_cost = costs;
				mati = i;
			}
		}
		cout << mati << " " << min_cost << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
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 Count[m];
      for (int i = 0; i < m; i++)
	{
	  Count[i] = 0;
	  for (int j = 0; j < m; j++)
	    {
	      Count[i] = Count[i] + T[i][j];
	    }
	}

      int mnum = 0;
      for (int i = 0; i < m; i++)
	{
	  if (Count[0] > Count[i])
	    {
	      Count[0] = Count[i];
	      mnum++;
	    }
	}
      cout << mnum << ' ' << Count[0] << endl;

    }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

enum { maxn = 20, INF = 10000000000000LL };

typedef long long LL;
LL G[maxn][maxn];
int vis[maxn];
LL d[maxn][maxn];
int inq[maxn];
int m;

void spfa(int src)
{
    memset(inq, 0, sizeof inq);
    for(int i = 0; i < maxn; i++) d[src][i] = INF;
    d[src][src] = 0LL;
    queue< int > q;
    while(!q.empty()) q.pop();
    q.push(src);
    inq[src] = 1;
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(int i = 0; i < maxn; i++)
        {
            if(G[u][i] != -1)
            {
                if(d[src][u] + G[u][i] < d[src][i])
                {
                    d[src][i] = d[src][u] + G[u][i];
                    if(!inq[i])
                    {
                        inq[i] = 1;
                        q.push(i);
                    }
                }
            }
        }
        inq[u] = 0;
    }
}

int main()
{
    while(~scanf("%d", &m), m)
    {
        memset(vis, 0, sizeof(vis));
        memset(G, -1, sizeof(G));
        memset(d, 0, sizeof(d));
        for(int i = 0; i < m; i++)
        {
            int a, b;
            LL c;
            scanf("%d%d%lld", &a, &b, &c);
            G[a][b] = G[a][b] == -1? c : min(G[a][b], c);
            G[b][a] = G[b][a] == -1? c: min(c, G[b][a]);
            vis[a] = vis[b] = 1;
        }
        for(int i = 0; i < maxn; i++)
            if(vis[i])
                spfa(i);
        LL ans = INF;
        int pt = -1;
        for(int i = 0; i < maxn; i++)
        {
            LL sum = 0;
            if(vis[i])
            {
                for(int j = 0; j < maxn; j++)
                {
                    if(vis[j])
                    {
                        sum += d[i][j];
                    }
                }
                if(sum < ans)
                {
                    ans = sum;
                    pt = i;
                }
            }
        }
        printf("%d %lld\n", pt, ans);
    }
    return 0;
}
/*

6     
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0


*/