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<iostream>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		
		
		int dp[111][111]={0};
		rep(i,111)rep(j,111)dp[i][j]=1000000000;
		
		
		int m=0;
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			dp[a][b]=min(c,dp[a][b]);
			dp[b][a]=min(c,dp[a][b]);
			
			m=max(m,max(a,b));
		}
		m++;
		rep(i,111)dp[i][i]=0;
		
		
		rep(k,m){
			rep(i,m){
				rep(j,m){
					dp[i][j] = min(dp[i][k]+dp[k][j],dp[i][j]);
				}
			}
		}
		
		rep(i,m){
			rep(j,m){
				printf("%d ",dp[i][j]);
			}puts("");
		}
		
		
		int ans=1000000000;
		int minp=-1;
		rep(i,111){
			int sum=0;
			rep(j,111){
				if(dp[i][j]==1000000000)continue;
				sum+=dp[i][j];
			}
			if(sum==0)continue;
			
			if(ans>sum){
				minp=i;
				ans = sum;
			}
		}
		printf("%d %d\n",minp,ans);
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>
#include <math.h>
#include<cstdio>
using namespace std;
int a[47][47],inf=999999;
void init()
{
    for(int i=0; i<=47; i++)
        for(int j=0; j<=47; j++)
        {
            if(i==j)
                a[i][j]=0;
            else
                a[i][j]=inf;
        }
}
void floyd(int x)
{
    for(int k=0; k<=x; k++)
        for(int i=0; i<=x; i++)
            for(int j=0; j<=x; j++)
                if(a[i][j]>a[i][k]+a[k][j])
                    a[i][j]=a[i][k]+a[k][j];
}
int main()
{
    int n;
    while(scanf("%d",&n)&&n)
    {
        init();
        int max1=0,x,y,z;
        for(int i=0; i<n; i++)
        {
            scanf("%d%d%d",&x,&y,&z);
            if(x>max1)
                max1=x;
            if(y>max1)
                max1=y;
            if(a[x][y]>z)
                a[x][y]=a[y][x]=z;
        }
        floyd(max1);
        int max2=inf,u,sum;
        for(int i=0; i<=max1; i++)
        {
            sum=0;
            for(int j=0; j<=max1; j++)
            {
                 sum+=a[i][j];
            }
            if(sum<max2)
            {
                max2=sum;
                u=i;
            }
        }
        printf("%d %d\n",u,max2);
    }
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 200000000
int main()
{
	int e;
	while(cin >> e,e)
	{
		int i,j,k,s=INF,v=0,ans=INF;
		cin >> e;
		if(e==0)break;
		int d[10][10];
		int cost_count[10] = {0};
		for(i=0;i<10;i++)
		{
			for(j=0;j<10;j++)
			{
				d[i][j] = INF;
				if(i==j)
				{
					d[i][j] = 0;
				}
			}
		}
		for(i=0;i<e;i++)
		{
			scanf("%d %d %d",&i,&j,&k);
			v = max(v,max(i,j));
			d[i][j] = k;
			d[j][i] = k;
		}
		for(k=0;k<v;k++)
		{
			for(i=0;i<v;i++)
			{
				for(j=0;j<v;j++)
				{
					d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		for(i=0;i<v;i++)
		{
			int cost = 0;
			for(j=0;j<v;j++)
			{
				cost += d[i][j];
			}
			cost_count[i] = cost;
			ans=min(ans,cost_count[i]);

		}
		for(i=0;i<v;i++)
		{
			if(cost_count[i]==ans)
			{
				printf("%d %d\n",i,ans);
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                             it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

const int NO = 1000000000;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        vector<pair<pair<int,int>,int> > R;
        int m=0;
        rep(i,n){
            int a,b,c;
            cin >> a >> b >> c;
            m = max(m,max(a,b));
            R.push_back(mp(mp(a,b),c));
        }
        m++;
        vector<vector<int> > V(m,vector<int>(m,NO));

        rep(i,m){
            V[i][i] = 0;
        }

        rep(i,n){
            int a = R[i].first.first;
            int b = R[i].first.second;
            int c = R[i].second;
            V[a][b] = V[b][a] = c;
        }



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

        int ret = -1;
        int mi = NO;

        for(int i=0;i<m;i++){
            int s = 0;
            for(int j=0;j<m;j++){
                s += V[i][j];
            }
            if(mi > s){
                mi = s;
                ret = i;
            }
        }
        cout << ret << " " << mi << endl;
    }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

typedef struct edge {
	int from;
	int to;
	int time;
} edge;


int main(){
	int n;


	while (cin >> n && n != 0) {
		int min_ = 1000000000;
		int min_num = 1;
		vector<edge> town;
		int cost[50][50];
		int max_ = 0;

		for (int i = 0; i < 50; i++) {
			for (int j = 0; j < 50; j++) {
				cost[i][j] = 100000000;
			}
		}
		for (int i = 0; i < 50; i++) {
			cost[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			edge tmp;
			cin >> tmp.from >> tmp.to >> tmp.time;
			cost[tmp.from][tmp.to] = tmp.time;
			cost[tmp.to][tmp.from] = tmp.time;
			max_ = max(max(tmp.from, tmp.to), max_);
		}
		max_++;
		for (int i = 0; i < max_; i++) {
			for (int j = 0; j < max_; j++) {
				for (int k = 0; k < max_; k++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		for (int i = 0; i < max_; i++) {
			int total = 0;
			for (int j = 0; j < max_; j++) {
				total += cost[i][j];
			}
			if (total < min_) {
				min_ = total;
				min_num = i;
			}
		}
		cout << min_num << " " << min_ << endl;
  }
	return 0;
}