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 <cstring>
#include <iostream>
#include <utility>

using namespace std;

int n, ncities;
int cities[10][10];

pair<int, int> solve()
{
    for (int k = 0; k <= ncities; ++k)
    {
        for (int i = 0; i <= ncities; ++i)
        {
            for (int j = 0; j <= ncities; ++j)
            {
                cities[i][j] = min(cities[i][j], cities[i][k] + cities[k][j]);
            }
        }
    }
    pair<int, int> result;
    result.second = 1000000000;
    for (int i = 0; i <= ncities; ++i)
    {
        int total = 0;
        for (int j = 0; j <= ncities; ++j)
        {
            total += cities[i][j];
        }
        if (total < result.second)
        {
            result.first = i;
            result.second = total;
        }
    }
    return result;
}

int main()
{
    while (cin >> n, n > 0)
    {
        ncities = -1;
        memset(cities, 0x3f, sizeof cities);
        int a, b, c;
        for (int i = 0; i < n; ++i)
        {
            cin >> a >> b >> c;
            cities[a][b] = cities[b][a] = c;
            ncities = max(ncities, max(a, b));
        }
        for (int i = 0; i <= ncities; ++i)
        {
            cities[i][i] = 0;
        }
        pair<int, int> result = solve();
        cout << result.first << " " << result.second << endl;
    }
    return 0;
}

C++: #include <iostream>
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 ans = INF;
      int t;
      for(int i=0; i<m; i++){
        int sum = 0;
        for(int j=0; j<m; j++){
          sum += T[i][j];
        }
        if(sum<ans){
          ans = sum;
          t=i;
        }
      }
        cout << t << ' ' << ans << endl;
    }

	return 0;
}

C++: #include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
const int maxn = 15;
#define INF 0xfffff
int d[maxn][maxn];
int V, ans_num, ans_dis;
void init(){
    ans_dis = INF;
    for(int i = 0; i < maxn; i++){
        fill(d[i], d[i] + maxn, INF);
        d[i][i] = 0;
    }
}
void Floyd(){
    for(int k = 0; k <= V; k++)
        for(int i = 0; i <= V; i++)
            for(int j = 0; j <= V; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
//                printf("d[%d][%d] = %d\n",i,j,d[i][j]);
            }
}
void solve(){
    Floyd();
    for(int i = 0; i <= V; i++){
        int sum_dis = 0;
        for(int j = 0; j <= V; j++)
            sum_dis += d[i][j];
        if(sum_dis < ans_dis){
            ans_dis = sum_dis;
            ans_num = i;
        }
    }
}
int main(){_
    int n;
    while(~scanf("%d",&n)){
        if(!n) break;
        V = 0;
        init();
        for(int i = 0; i < n; i++){
            int x, y, val;
            scanf("%d%d%d",&x, &y, &val);
            d[x][y] = d[y][x] = val;
//            printf("--d[%d][%d] = %d\n",x, y, d[x][y]);
            V = max(V, max(x, y));
        }
        solve();
        printf("%d %d\n",ans_num, ans_dis);
    }

    return 0;
}

C++: /*
 * 1.cpp
 *
 *  Created on: 2015-10-29
 *      Author: hp
 */
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define mem(a) memset(a,0,sizeof(a))
#define pfn printf("\n")
#define ll __int64
#define pfd(a) printf("%d\n",a)
#define pf2d(a,b) printf("%d %d\n",a,b)
#define pf3d(a,b,c) printf("%d %d %d\n",a,b,c)
#define pfs(a) printf("%s\n",a)
#define sfd(a) scanf("%d",&a)
#define sf2d(a,b) scanf("%d%d",&a,&b)
#define sf3d(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define sf	scanf
#define pf	printf
#define fr(i,n) for(int i=0;i<n;i++)
#define INF 0x7fffffff   //INT_MAX
#define inf 0x3f3f3f3f   //int
const double PI = acos(-1.0);
const double e = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> inline T Min(T a, T b) { return a < b ? a : b; }
template<class T> inline T Max(T a, T b) { return a > b ? a : b; }
bool cmpbig(int a,int b){return a>b;}
bool cmpsmall(int a,int b){return a<b;}
using namespace std;
int dp[20][20];
int n;
void floyd(){
    for(int k=0;k<n;k++)
    	for(int i=0;i<n;i++)
    		for(int j=0;j<n;j++)
    			dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
}
int main()
{
	//freopen("1.txt","r",stdin);

	int x,y;
    int d;
    while(~scanf("%d",&n) &&n){
    	int max_n=-1;
       for(int i=0;i<n;i++)
    	   for(int j=0;j<n;j++)
    		   dp[i][j]=inf;
       for(int i=0;i<n;i++){
    	   scanf("%d %d %d",&x,&y,&d);
    	   dp[x][y]=d;
    	   dp[y][x]=d;
    	   dp[i][i]=0;
    	   int tem=max(x,y);
    	   max_n=max(tem,max_n);
    	  //printf("%d %d d=%d\n",dp[x][y],dp[y][x],d);
       }
        floyd();
        int ans=inf;
        int pos;
        int sum=0;

        for(int i=0;i<=max_n;i++){
            sum=0;
        	for(int j=0;j<=max_n;j++){
        		if(dp[i][j]<inf && i!=j)
        		  sum+=dp[i][j];
        	}
            if(sum<ans){
            	ans=sum;
            	pos=i;
            	//printf("ans=%d i=%d\n",ans,pos);
            }
       }

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

	return 0;
}

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

using namespace std;

const int MAX_V=10;
int d[10][10];
int V;
const int INF=100000000;

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

int main(){

	int n;
	while(cin>>n&&n!=0){
		for(int i = 0; i < n; i++)
			fill(d[i],d[i]+n,INF);
		set<int> s;
		for(int i = 0; i < n; i++){
			int a,b,c;
			cin>>a>>b>>c;
			d[a][b]=c;
			d[b][a]=c;
			s.insert(a);
			s.insert(b);
		}
		V=s.size();
		for(int i = 0; i < V; i++){
			d[i][i]=0;
		}

		warshall_floyd();
		int idx;
		int minValue=INF;
		for(int i = 0; i < V; i++){
			int sum=0;
			for(int j = 0; j < V; j++){
				if(i!=j&&d[i][j]!=INF){
					sum+=d[i][j];
				}
			}
			if(minValue>sum){
				minValue=sum;
				idx=i;
			}
		}
		cout<<idx<<" "<<minValue<<endl;
	}


	return 0;
}