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>
#define INFINITY 1000000
#define MAX_N 10

using namespace std;

int n,d[MAX_N][MAX_N] = {};

int main() {
  int city, mincity;
  int  temp1, temp2, temp3, alt,costtime, cost;
  while (1) {
    d[MAX_N][MAX_N] = {};
    cin >> n;
    if (n == 0) break;
    city = mincity = 0;
    for (int i = 0; i < MAX_N; ++i)
      for (int j = 0; j < MAX_N; ++j)
        if (i != j) d[i][j] = INFINITY;

    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2 >> temp3;

        d[temp1][temp2] = temp3;
        d[temp2][temp1] = temp3;
      if (city < temp1 || city < temp2) { city = (temp1 > temp2) ? temp1 : temp2; }
    }
    //cout << city <<endl;
    city++;




    for (int i = 0; i < city; ++i)
      for (int j = 0; j < city; ++j)
        for (int k = 0; k < city; ++k) {
          if (d[j][i] != INFINITY && d[i][k] != INFINITY) {
            alt = d[j][i] + d[i][k];
            if (alt < d[j][k]) d[j][k] = alt;
          }
        }


    for (int i = 0; i < city; ++i) {
      cost = 0;
      for (int j = 0; j < city; ++j) {
        if(d[i][j] != INFINITY)
        cost += d[i][j];
        //cout << d[i][j] << " ";
      }
      //cout << endl;
      if (i == 0) costtime = cost;
      if (costtime > cost) {
        costtime = cost;
        mincity = i;
      }
    }
    cout << mincity << " " << costtime << endl;

  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;

static int N;

/*
求某一?公室到其他?公室的最短距?。
多??入，n表示n条?系，下面n次?次?入 x y d表示x到y的距?是d。需要注意的是n没有?定，需要根据?入来求。
?出?公室的?号和距?
*/
static int x, y, distances;
static int n;
//static int vis[100];
static const int INF = 1 << 10;
static int dist[100][100];


void floyd()
{
	for (int k = 0; k <= n; k++)
	{
		for (int i = 0; i <= n; i++)
		{
			for (int j = 0; j <= n; j++)
			{
				if (dist[i][k] + dist[k][j] < dist[i][j])
				{
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}


}




int main()
{
	while (scanf("%d", &N) != EOF)
	{
		if (N == 0) break;
		n = -1;
		fill(dist[0], dist[0] + 100 * 100, INF);
		for (int i = 0; i < N; i++)
		{
			scanf("%d%d%d", &x, &y, &distances);
			n = max(n, x);
			n = max(n, y);
			dist[x][y] = dist[y][x] = min(dist[x][y], distances);
		}
		floyd();
		int u = -1, ans = 1<<30, sum = 0;
		for (int i = 0; i <= n; i++)
		{
			sum = 0;
			for (int j = 0; j <= n; j++)
			{
				if (i != j) sum += dist[i][j];
				//printf("j:%d dist:%d", j, dist[i][j]);
			}
			if (sum < ans)
			{
				u = i;
				ans = sum;
			}
			//printf("\ni:%d sum:%d\n", i, sum);
		}

		printf("%d %d\n", u, ans);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
typedef pair<int,int> P;

#define INF 1000000
int cost[10][10];
int n,m;

int main(){
  while(1){
    cin >> n;
    if(!n)break;

    m = 0;
    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;
        }
      }
    }
    for(int i=0;i<n;i++){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      if(m<x||m<y){
        m = max(x,y);
      }
      cost[x][y] = z;
      cost[y][x] = z;
    }
    m++;

    for(int k=0;k<m;k++){
      for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
          cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
        }
      }
    }

    /*for(int i=0;i<m;i++){
      for(int j=0;j<m;j++){
        printf("%d%c",cost[i][j],j==m-1?'\n':' ');
      }
    }*/

    int mini = INF;
    int index;
    for(int i=0;i<m;i++){
      int sum = 0;
      for(int j=0;j<m;j++){
        sum += cost[i][j];
      }
      if(mini>sum){
        mini = sum;
        index = i;
      }
    }
    cout << index << " " << mini << endl;
  }
}

C++: #include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
using namespace std;
const int INF=100000000;
int main(){
  int n;
  while(cin>>n,n!=0){
    int dp[100][100];
    rep(i,n){
      rep(j,n){
	dp[i][j]=i==j?0:INF;
      }
    }
    int k[100]={};
    vector<int> vec;
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      dp[a][b]=c;
      dp[b][a]=c;
      k[a]++;
      k[b]++;
    }
    int city=0;
    rep(i,11){
      if(k[i]>0){
	city++;
	vec.push_back(i);
      }
    }
    rep(k,city){
      rep(i,city){
	rep(j,city){
	  dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
	}
      }
    }
    int minsum=INF,num;
    rep(i,vec.size()){
      int sum=0;
      rep(j,vec.size()){
	sum+=dp[vec[i]][vec[j]];
      }
      if(minsum>sum){
	minsum=sum;
	num=vec[i];
      }    
    }
    cout<<num<<" "<<minsum<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f

int map[15][15];
void floyd(int n)
{
	for(int k=0;k<=n;k++)
	{
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				map[i][j]=min(map[i][j],map[i][k]+map[k][j]);
			}
		}
	}
}
int main()
{
	int n,i,j,a,b,t;
	while(scanf("%d",&n),n)
	{
		int m=0;		
//		for(i=1;i<=n;i++)
//		{
//			for(j=1;j<=n;j++)
//			{
//				if(i==j) map[i][j]=0;
//				else	map[i][j]=INF;
//			}
//		}
		memset(map,INF,sizeof(map));
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d",&a,&b,&t);
			map[a][b]=map[b][a]=min(map[a][b],t);
			if(a>m) m=a;
			if(b>m) m=b;
		}
		floyd(m);
		int tmp=0,ans=INF,k;
		for(i=0;i<=m;i++)
		{
			for(j=0;j<=m;j++)
			{
				if(i==j)
					continue;
				tmp+=map[i][j];
			}
			if(tmp<ans)	
			{
				ans=tmp;
				k=i;
			}
			tmp=0;
		}
		printf("%d %d\n",k,ans);
	}
	return 0;
}