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++: //C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef pair<int,int> p;
int inf=INT_MAX;
int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0) break;

        int d[50][50];

        for(int i=0;i<50;i++){
            for(int j=0;j<50;j++)d[i][j]=inf;
        }
        for(int i=0;i<50;i++)d[i][i]=0;
        for(int i=0;i<n;i++){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            d[a][b]=c;
            d[b][a]=c;
        }
        for(int k=0;k<50;k++){
            for(int i=0;i<50;i++){
                for(int j=0;j<50;j++){
                    if(d[i][k]!=inf and d[k][j]!=inf) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
        int ans=inf;
        int from;
        for(int i=0;i<50;i++){
            int tmp=0;
            int flag=0;
            for(int j=0;j<50;j++){
                if(d[i][j]!=inf and i!=j){tmp+=d[i][j];flag=1;}
            }
            if(flag==1){
                if (ans>tmp){
                ans=min(ans,tmp);
                from=i;
                }
            }
        }
        printf("%d %d\n",from,ans);

    }


};

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define X first
#define Y second
#define MP make_pair
#define PB push_back

using namespace std;
int table[10][10];


int main(){
	int n;
	while(cin >> n && n != 0){
		for(int i = 0; i < 10; i++){
			fill(table[i], table[i]+10, 10000000);
			table[i][i] = 0;
		}
		for(int i = 0; i < n; i++){
			int node1, node2;
			cin >> node1 >> node2;
			cin >> table[node1][node2];
			table[node2][node1] = table[node1][node2];
		}
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				for(int k = 0; k < 10; k++){
					table[j][k] = min(table[j][k], table[j][i] + table[i][k]);
				}
			}
		}
		int index = -1;
		int min = 1000000;
		for(int i = 0; i < 10; i++){
			if(table[i][0] == 10000000) break;
			int sum = 0;
			for(int j = 0; j < 10; j++){
				if(table[i][j] == 10000000) break;
				sum += table[i][j];
			}
			if(sum<min){
				min = sum;
				index = i;
			}
		}
		cout << index << " " << min << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <limits.h>
using namespace std;
#define INF 100000
int dp[10][10];
int main() {
	int n ;
	while(1){
		cin >> n ; if(!n) break;
		for(int i=0;i<10;i++) for(int j=0;j<10;j++) dp[i][j]=INF;
		for(int i=0;i<10;i++) dp[i][i]=0;
		int V=0;
		for(int i=0;i<n;i++){
			int a,b,c; cin >> a >> b >> c ;
			V=max(V,max(a,b));
			dp[a][b]=dp[b][a]=c;
		}
		for(int i=0;i<=V;i++) for(int j=0;j<=V;j++) for(int k=0;k<=V;k++)
			dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
		int NUM=0, MIN=INF;
		for(int i=0;i<=V;i++){
			int sum=0;
			for(int j=0;j<=V;j++) sum+=dp[i][j];
			if(sum<MIN) MIN=sum,NUM=i;
		}
		cout << NUM << ' ' << MIN << '\n' ;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#define INF 1000000007
#define inf 100000000000000000
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int n,t,d[15][15],cost,x,y,k,i,j;
int main()
{
    while(scanf("%d",&n)!=EOF&&n!=0)
    {
        memset(d,INF,sizeof(d));t=0;
        P mi;mi.second=INF;
        for(i=0;i<n;i++)
        {
            scanf("%d%d%d",&x,&y,&cost);
            d[x][y]=d[y][x]=cost;
            t=max(t,max(x,y));
        }
        for(i=0;i<=t;i++)d[i][i]=0;
        for(k=0;k<=t;k++)
        {
            for(i=0;i<=t;i++)
            {
                for(j=0;j<=t;j++)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
        for(i=0;i<=t;i++)
        {
            P p;p.first=i;p.second=0;
            for(j=0;j<=t;j++)
            {
                if(i==j)continue;
                p.second+=d[i][j];
            }
            if(mi.second>p.second)mi=p;
        }
        printf("%d %d\n",mi.first,mi.second);
    }
    return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<cmath>
#define INF 9999999
using namespace std;
int n,t[10][10],a,b,c,d,flg[10],sum,mini,miniNo;
int main(){
	while(1){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				t[i][j]=INF*(j!=i);
			}
			flg[i]=0;
		}
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			t[a][b]=t[b][a]=c;
			flg[a]=flg[b]=1;
		}
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
				}
			}
		}
		mini=INF;
		for(int i=0;i<10;i++){
			if(flg[i]){
				sum=0;
				for(int j=0;j<10;j++){
					if(t[i][j]!=INF){
						sum+=t[i][j];
					}
				}
				if(mini>sum){
					mini=sum;
					miniNo=i;
				}
			}
		}
		cout<<miniNo<<" "<<mini<<endl;

	}
			return 0;
}

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


#define INF 10000
#define MAX_V 10


int d[MAX_V][MAX_V];
int n, m, a, b, c, num, t;


void Init(){
	t=INF; m=0;//ツ陳ャツづ個青板。
	for(int i=0; i<MAX_V; i++)
			for(int j=0; j<MAX_V; j++)
				i==j ? d[i][j]=0 : d[i][j]=INF;
}


void Input(){
	for(int i=0; i<n; i++){
		cin>>a>>b>>c;
		m = max(a, max(b, m));//ツ陳ャツづ個青板。
		d[a][b]=d[b][a]=c;
	}
}


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



	for(int i=0; i<=m; i++){
		for(int j=0; j<=m; j++){
			if(d[i][j]!=INF || i!=j)tmp+=d[i][j];
		}
		if(tmp<t)t=tmp, num=i;
		tmp=0;
	}
	return;
}



int main(){
	while(cin>>n, n){
		Init();
		Input();
		wf();
		printf("%d %d\n", num, t);
	}
	return 0;
}