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 <algorithm>
using namespace std;
#define INF 1000000
int C[15][15];
int main()
{
    int n;
    while(scanf("%d",&n),n)
    {
        for(int i=0;i<15;++i){
            for(int j=0;j<15;++j){
                C[i][j]=i==j?0:INF;
            }
        }
        int m=0;
        for(int i=0;i<n;++i){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            m=max(m,max(a,b));
            C[a][b]=C[b][a]=c;
        }
        m++;
        for(int k=0;k<m;++k){
            for(int i=0;i<m;++i){
                for(int j=0;j<m;++j){
                    C[i][j]=min(C[i][j],C[i][k]+C[k][j]);
                }
            }
        }
        int ln=INF,lc=INF;
        for(int i=m-1;i>=0;--i){
            int c=0;
            for(int j=0;j<m;++j){
                c+=C[i][j];
            }
            if(c<=lc){
                ln=i;
                lc=c;
            }
        }
        printf("%d %d\n",ln,lc);
    }
    return 0;
}

C++: /*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
#define INF 10000
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
int Field[10][10];

/*****その他関数置き場*****/
int djikstra(int start,int townnum){
	int sum=0;
	int town;
	int *dis;
	bool *used;
	dis = new int [townnum];
	used = new bool [townnum];
	for(int i=0;i<townnum;i++){
		dis[i] = INF;
		used[i] = 0;
	}
	dis[start] = 0;
	while(true){
		town = -1;
		for(int i=0;i<townnum;i++){
			if(!used[i] && (town == -1 || dis[town] > dis[i])){
				town = i;
			}
		}
		if(town == -1)	break;
		used[town] = true;
		for(int i=0;i<townnum;i++){
			if(dis[i] > dis[town] + Field[town][i]){
				dis[i] = dis[town] + Field[town][i];
			}
		}
	}
	for(int i=0;i<townnum;i++){
		if(dis[i] != INF)	sum += dis[i];
	}
	delete used;
	delete dis;
	return sum;
}
/*****main関数*****/
int main(){
	/*****変数置き場*****/
	int appear[10];
	int townnum;
	int n;
	int from,to,cost;
	int now_cost;
	int min_cost;
	int min_town;
	/*****処理部*****/
	while(1){
		for(int i=0;i<10;i++){
			appear[i] = 0;
			for(int j=0;j<10;j++){
				Field[i][j] = INF;
			}
		}
		townnum = 0;
		
		min_cost = INF;
		min_town = INF;
		cin >> n;
		if(n==0)	break;
		for(int i=0;i<n;i++){
			cin >> from >> to >> cost;
			Field[from][to] = cost;Field[to][from] = cost;
			Field[from][from] = 0;Field[to][to] = 0;
			if(!appear[from]){
				appear[from] = 1;
				townnum++;
				//cout << townnum << endl;
			}
			if(!appear[to]){
				appear[to] = 1;
				townnum++;
				//cout << townnum << endl;
			}
		}
		//cout << "djikstra begin..." << endl;
		for(int start=0;start<townnum;start++){
			//cout << start << " " << townnum << endl;
			now_cost = djikstra(start,townnum);
			if(now_cost < min_cost){
				min_cost = now_cost;
				min_town = start;
			}
		}
		cout << min_town << " " << min_cost << endl;
	}
	/*****処理終了後*****/
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
long n,p[10][10],i,j,k,m,s,ii,ss;
while(cin>>n){
if(n==0)break;
for(i=0;i<10;i++)
for(j=0;j<10;j++)p[i][j]=p[j][i]=-1;
m=0;
for(s=k=0;k<n;k++){
cin>>i>>j;
cin>>p[i][j];
s+=p[i][j];
if(m<i)m=i;if(m<j)m=j;
}
s*=45;
m++;
for(i=0;i<10;i++)p[i][i]=0;
for(i=0;i<10;i++)
for(j=0;j<10;j++)if(p[i][j]<0)p[i][j]=s;
for(k=0;k<m;k++)
for(i=0;i<m;i++)
for(j=0;j<m;j++)p[i][j]=p[j][i]=min(p[i][j],p[i][k]+p[k][j]);
for(ss=s,i=0;i<m;i++){
for(s=j=0;j<m;j++)s+=p[i][j];
if(s<ss){ss=s;ii=i;}
}
cout<<ii<<" "<<ss<<endl;
}
return 0;
}

C++: #include <cstdio>
#include <cstring>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include <map>
#include <algorithm>
using namespace std;
map<string, string>mp;
vector<vector<int> >G;

const int INF=0x3f3f3f3f;
const int maxn=1100;
int maps[maxn][maxn];
int vis[maxn], dist[maxn];
int ans;
int n;
void Init()
{
    memset(vis, 0, sizeof(vis));
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=n; j++)
            maps[i][j]=(i==j)?0:INF;
        dist[i]=INF;
    }
}
int dij()
{
    for(int i=0; i<=ans; i++)
        dist[i]=maps[ans/2][i];

    vis[ans/2]=1;

    for(int i=0; i<=ans; i++)
    {
        int Min=INF, index;
        for(int j=0; j<=ans; j++)
        {
            if(!vis[j]&&dist[j]<Min)
            {
                Min=dist[j];
                index=j;
            }
        }

        if(Min==INF)
            break;
        vis[index]=1;

        for(int j=0; j<=ans; j++)
            if(!vis[j]&&dist[j]>Min+maps[index][j])
                dist[j]=Min+maps[index][j];
    }
    int sum=0;

    for(int i=0; i<=ans; i++)
        sum+=dist[i];
    return sum;
}

int main()
{
    while(scanf("%d", &n), n)
    {
        Init();
        ans=0;
        for(int i=0; i<n; i++)
        {
            int u, v, w;
            scanf("%d %d %d", &u, &v, &w);
            ans=max(ans, max(u, v));
            maps[u][v]=maps[v][u]=w;
        }

        printf("%d %d\n", ans/2, dij());
    }
    return 0;
}

C++: #include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>

#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>
#include<climits>

using namespace std;
const int MAX = 10;
const int INF = INT_MAX/3;
int main(){
  ios::sync_with_stdio(false);
  int cost[MAX][MAX];
  bool existTown[MAX];
  int n;
  while(cin >> n && n != 0){
    fill(*cost,*(cost+MAX),INF);
    fill(existTown,existTown+MAX,false);
    for(int i = 0;i < n;i++){
      int a,b,c;
      cin >> a >> b >> c;
      cost[a][b] = cost[b][a] = c;
      existTown[a] = existTown[b] = true;
    }

    for (int k = 0; k < MAX; ++k){
      for (int j = 0; j < MAX; ++j){
	for (int i = 0; i < MAX; ++i){
	  int sum = cost[i][k] + cost[k][j];
	  if(cost[i][j] > sum){
	    cost[i][j] = cost[j][i] = sum;
	  }
	}
      }
    }
    /*
    for (int i = 0; i < MAX; ++i){
      for (int j = 0; j < MAX; ++j){
	if(cost[i][j] == INF)cout << INF;
	else cout << cost[i][j];
	cout << ' ';
      }
      cout << endl;
    }
    */
    int ans = 100;
    int mini = INF;
    for(int i = 0;i < MAX;i++){
      if(!existTown[i])continue;
      int sum = 0;
      for(int j = 0;j < MAX;j++){
	if(existTown[j] && j != i)sum += cost[i][j];
      }
      if(mini > sum){
	mini = sum;
	ans = i;
      }
    }
    cout << ans  << ' ' << mini << endl;
  }
  
  return 0;
}