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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:>
 問題文============================================================
 
 =================================================================
 
 解説=============================================================
 
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    ll G[10][10];
    bool used[10];
    while(cin >> n){
        if(n==0) break;
        for(int i = 0; i < 10;i++)for(int j = 0;j < 10;j++) G[i][j] = INF;
        for(int i = 0; i < 10;i++) used[i] = false;
        for(int i = 0; i < n;i++){
            ll a,b,c; cin >> a >> b >> c;
            G[a][b] = min(G[a][b],c);
            G[b][a] = min(G[b][a],c);
            used[a] = used[b] = true;
        }
        for(int i = 0; i < 10;i++){
            for(int j = 0;j <10;j++){
                for(int k = 0;k < 10;k++){
                    G[i][j] = min(G[i][j],G[i][k]+G[k][j]);
                }
            }
        }
        ll id = -1,sum = INF;
        for(int i = 0; i < 10;i++){
            if(used[i] == false)continue;
            ll tmp = 0;
            for(int j = 0; j < 10;j++){
                if(i == j)continue;
                if(used[j] == false)continue;
                tmp += G[i][j];
            }
            if(tmp < sum){
                sum = tmp;
                id = i;
            }
        }
        cout << id << " " << sum << endl;
    }
    return 0;
}

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


using namespace std;

const int inf = 100000;

int dis[10][10];
int m;

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

int main()
{
	int n, a, b, c;
	int tmp, ans, p;
	
	while (cin >> n && n)
	{
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				dis[i][j] = inf;
		m = 0;
		ans = inf;
		while (n--)
		{
			cin >> a >> b >> c;
			dis[a][b] = c;
			dis[b][a] = c;
			m = max(m, max(a + 1, b + 1));
		}
		
		floyd();
		for (int i = 0; i < m; i++)
		{
			tmp = 0;
			for (int j = 0; j < m; j++)
			{
				if (i == j)
					continue;
				tmp += dis[i][j];
				if (tmp > inf)
					break;
			}
			if (tmp < ans)
			{
				ans = tmp;
				p = i;
			}
		}
		cout << p << ' ' << ans << endl;
	}
	

	return 0;
}

C++: // 2011/08/24 Tazoe

#include <iostream>
#include <climits>
using namespace std;

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] = INT_MAX;

		int m = -1;	// ¬Ì
		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;
			T[a][b] = T[b][a] = c;
			if(m<a)
				m = a;
			if(m<b)
				m = b;
		}
		m = m+1;

		// tChÌASY
		for(int k=0; k<m; k++){
			for(int i=0; i<m; i++){
				for(int j=0; j<m; j++){
					if(T[i][k]==INT_MAX||T[k][j]==INT_MAX)	// «·ÆI[ot[·éÌÅ
						continue;
					if(T[i][j]>T[i][k]+T[k][j])
						T[i][j] = T[i][k]+T[k][j];
				}
			}
		}

		int m_min = INT_MAX;
		int s_min = INT_MAX;
		for(int i=0; i<m; i++){
			int sum = 0;
			for(int j=0; j<m; j++)
				sum += T[i][j];
			if(sum<s_min){
				m_min = i;
				s_min = sum;
			}
		}

		cout << m_min << ' ' << s_min << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>

#define SIZE 100
#define INF 10000000

typedef struct {
  int data;
  int pos;
} DAT;


using namespace std;

int main(){

  DAT ans;
  int i,j,k;
  int a,b,c;
  int n;
  int time[SIZE][SIZE];

  while(1){

    int sum[SIZE]={0};
    cin>>n;

  for(i=0;i<n+1;i++){
    for(j=0;j<n+1;j++){
      if(i==j){
	time[i][j]=0;
      } else {
	time[i][j]=INF;
      }
    }
  }

  int max=0;
    for(i=0;i<n;i++){
      cin>>a>>b>>c;
      time[a][b]=c;
      time[b][a]=c;
      if(max<a)max=a;
      if(max<b)max=b;
    }

    for(i=0;i<max+1;i++){
      for(j=0;j<max+1;j++){
	for(k=0;k<max+1;k++){
	  time[j][k]=min(time[j][k],time[j][i]+time[i][k]);
	}
      }
    }

    for(i=0;i<max+1;i++){
      for(j=0;j<max+1;j++){
	sum[i]+=time[i][j];
      }
    }

    ans.data=INF;
    ans.pos=-1;
    for(i=0;i<max+1;i++){
      if(sum[i]<ans.data){
	ans.data=sum[i];
	ans.pos=i;
      }
    }

    printf("%d %d\n",ans.pos,ans.data);

  }
  
  return 0;
}

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

typedef long long ll;
const int N = 55;
const int M = 1000000007;

int n, m;
int a[N][N];

int main() {
  while (scanf("%d", &m), m) {
    memset(a, 0x3f, sizeof(a)); n = 0;
    for (int i = 0, u, v, w; i < m; i++) {
      scanf("%d%d%d", &u, &v, &w); a[u][v] = a[v][u] = w;
      n = max(n, max(u, v) + 1);
    }
    for (int k = 0; k < n; k++) {
      a[k][k] = 0;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
        }
      }
    }
    int ans = 0, mnd = 0x3f3f3f3f;
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = 0; j < n; j++) { sum += a[i][j]; }
      if (mnd > sum) { ans = i; mnd = sum; }
    }
    printf("%d %d\n", ans, mnd);
  }
}

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

using namespace std;

int map[10][10];

int cmp(int i,int j,int k){
  if(map[i][j]==-1){
    if(map[i][k]>=0 && map[k][j]>=0)
      return map[i][k]+map[k][j];
    else
      return -1;
  }else
    if(map[i][k]==-1 || map[k][j]==-1)
      return map[i][j];
    else
      return min(map[i][j],map[i][k]+map[k][j]);
}

int main(){
  for(int n;scanf("%d",&n),n;){
    int m=0;
    memset(map,-1,sizeof(map));

    for(;n--;){
      int a,b,c;
      scanf("%d %d %d",&a,&b,&c);
      m=m>a?m:a;m=n>b?m:b;
      map[a][b] = map[b][a] = c;
    }

    for(int i=0; i<=m; i++)
      map[i][i] = 0;

    for(int k=0; k<=m; k++)
      for(int i=0; i<=m; i++)
	for(int j=0; j<=m; j++)
	  map[i][j] = cmp(i,j,k);

    // for(int i=0; i<=m; i++){
    //   for(int j=0; j<=m; j++)
    // 	printf("%3d ",map[i][j]);
    //   putchar('\n');
    // }

    int num,sum=-1;
    for(int i=0; i<=m; i++){
      int tsum=0;
      for(int j=0; j<=m; j++)
	tsum += map[i][j];
      if(sum==-1||tsum<sum){
	num=i; sum=tsum;
      }
    }

    printf("%d %d\n",num,sum);
  }

  return 0;
}