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 <algorithm>
#include <cstring>
using namespace std;
#pragma warning(disable:4996)

#define MAX_V 11
int d[MAX_V][MAX_V];//&#26435;&#20540;
int V;//定点数
int x[MAX_V];//x[i]表示以i&#20026;起点&#26102;最短路径之和
#define forn(i,n) for(int i=0;i<(int)n;++i)

void floyd_warshall(){
	forn(k, V)
		forn(i, V)
		forn(j, V)
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("E:\\in.txt", "r", stdin);
#endif // !ONLINE_JUDGE

	int E;
	while (cin >> E, E){
		memset(d, 0x3f, MAX_V*MAX_V*sizeof(int));
		forn(i, MAX_V)
			d[i][i] = 0;
		V = 0;
		forn(i, E){
			int u, v, cost;
			cin >> u >> v >> cost;
			d[u][v] = cost;
			d[v][u] = cost;
			V = max(V, max(v, u) + 1);
		}
		floyd_warshall();
		memset(x, 0, V*sizeof(int));
		forn(i, V)
			forn(j, V)
			x[i] += d[i][j];
		int ans = min_element(x, x + V) - x;
		cout << ans << " " << x[ans] << "\n";
	}
	return 0;
}

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

int main() {
	for (;;)
	{
		int edge[11][11];
		int city = 0;
		for (int i = 0;i < 11;i++) 
		{
			for (int j = 0;j < 11;j++)
			{
				if(i == j)
				{
					edge[i][i] = 0;
					continue;
				}
				edge[i][j] = INF;
			}
		}
		int n;
		cin >> n;
		if (n == 0) break;
		for (int i = 0;i < n;i++)
		{
			int a,b,c;
			cin >> a >> b >> c;
			edge[a][b] = c;
			edge[b][a] = c;
 			city = max (max(a,b)+1,city);
		}
		for (int i = 0;i < city;i++)
		{
			for (int j = 0;j < city;j++)
			{
				for (int k = 0;k < city;k++)
				{
					edge[i][k] = min(edge[i][k],edge[i][j]+edge[j][k]);
				}
			}
		}
		//??????????????§edge?????????????????¢?????\??£?????????(??????????????§?????????)
		int min = INF;
		int minCity;
		for (int i = 0;i < city;i++)
		{
			int sum = 0;
			for (int j = 0;j < city;j++)
			{
				if (i == j) continue;
				sum += edge[i][j];
			}
			if (sum < min)
			{
				min  = sum;
				minCity = i;
			}
		}
		cout << minCity << " " << min << endl;
	}
	return 0;
}

C++: #include <iostream>

#define MAX 10
#define INF 2000000
using namespace std;

int d[MAX][MAX];
int n, num_ver = 0;
int min_t = INF;
int min_ver;

void init();
void input();
void wf();

int main(){

  while(cin >> n, n){
    init();
    input();  
    wf();
    
   
    for(int i = 0; i <= num_ver; i++){
      int tmp = 0;
      for(int j = 0; j <= num_ver; j++){
	tmp += (i<j)? d[i][j] : d[j][i];
      }
      if(min_t > tmp) {min_t = tmp; min_ver = i;}
    }
    cout << min_ver << " " << min_t << endl;
  }
}

void init(){
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      d[i][j] = (i==j)? 0: INF;
    }
  }
}

void input(){
  for(int i = 0; i < n; i++){
    int a, b, c;
    cin >> a >> b >> c;
    d[a][b] = c;
    if(num_ver < b) num_ver = b;
  }
}

void wf(){
  for(int i = 0; i <= num_ver; i++){
    for(int j = 0; j <= num_ver; j++){
      for(int k = 0; k <= num_ver; k++){
	d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

C++: #include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
using namespace std;
#define INF INT_MAX>>1


int main()
{   
    // freopen("in","r",stdin);
    int n;
    while(scanf("%d",&n)&&n){
        int u,v,w,max_v=0;
        int g[15][15];
        memset(g,0x3f3f,sizeof(g));
        for(int i=0;i<n;i++){
            scanf("%d %d %d",&u,&v,&w);
            g[u][v]=g[v][u]=w;
            max_v = max(max_v,u);
            max_v = max(max_v,v);
        }  

        for(int k=0;k<=max_v;k++){
            for(int i=0;i<=max_v;i++){
                for(int j=0;j<=max_v;j++){
                    if(g[i][k]+g[k][j]<g[i][j])
                        g[i][j] = g[i][k]+g[k][j];
                }
            }
        }
        int ans_sum = INF,ans_i;
        for(int i=0;i<=max_v;i++){
            int sum = 0;
            for(int j=0;j<=max_v;j++){
                if(i!=j){
                    sum += g[i][j];
                }
            }
            if(sum < ans_sum){
                ans_sum = sum;
                ans_i = i;
            }
        }
        printf("%d %d\n",ans_i,ans_sum);
    }
    return 0;
}