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 <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <iterator>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<28

using namespace std;

typedef long long ll;
typedef pair<int,int> P;


struct edge
{
	int to;
	int cost;

	edge(int to,int cost) : to(to),cost(cost) {}
};


vector<edge> G[10];
ll d[10];

void dijkstra(int s,int n)
{
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+n,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty())
	{
		P p = que.top();
		que.pop();

		int v = p.second;
		if(d[v] < p.first) continue;

		rep(i,G[v].size())
		{
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main()
{
	int n;
	
	while(cin >> n && n)
	{
		vector<int> t;
		rep(i,n)
		{
			int a,b,c;
			cin >> a >> b >> c;

			G[a].push_back(edge(b,c));
			G[b].push_back(edge(a,c));

			vector<int>::iterator ite = find(t.begin(),t.end(),a);
			if(ite == t.end())
			{
				t.push_back(a);
			}

			ite = find(t.begin(),t.end(),b);
			if(ite == t.end())
			{
				t.push_back(b);
			}

		}

		pair<int,ll> ans;
		ans.first = t[0];
		ans.second = INF;
		
		rep(i,t.size())
		{
			dijkstra(t[i],10);

			ll sum = 0;

			rep(j,t.size()) sum += d[t[j]];

			if(ans.second > sum)
			{
				ans.first = i;
				ans.second = sum;
			}	
		}
		cout << ans.first << " " << ans.second << endl;
	}

	return 0;
	
}

C++: #include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
const int inf = 999999999;
int main(){
	int n,a,b,c;
	while(cin >> n, n) {
		int cost[64][64] = {};
		rep(i,64) {
			rep(j,64) {
				if(i==j)continue;
				cost[i][j] = inf;
			}
		}
		int max = 0;
		rep(i,n) {
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			if(max < a) max = a;
			if(max < b) max = b;
		}

		rep(i,max+1) {
			rep(j,max+1) {
				rep(k,max+1) {
					int len = cost[i][j] + cost[j][k];
					if(len < cost[i][k]) {
						cost[i][k] = len;
					}
				}
			}
		}
		int min = inf, rmin = -1;
		rep(i,max+1) {
			int ret = 0;
			rep(j,max+1) {
				ret += cost[i][j];
			}
			if(min > ret) {
				min = ret;
				rmin = i;
			}
		}
		cout << rmin << " " << min << endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;


int maze[50][50];

int tag[20];

int main()
{
    int n;
    while(~scanf("%d",&n) && n){
        memset(tag,0,sizeof(tag));
        memset(maze,0x3f,sizeof(maze));
        for(int i = 0;i <= 9;++i) maze[i][i] = 0;
        int u,v,l;
        for(int i = 1;i <= n;++i){
            scanf("%d%d%d",&u,&v,&l);
            tag[u] = tag[v] = 1;
            maze[u][v] = maze[v][u] = min(maze[u][v],l);
        }
        
        for(int k = 0;k <= 9;++k){
            for(int i = 0;i <= 9;++i){
                for(int j = 0;j <= 9;++j){
                    maze[j][i] = maze[i][j] = min(maze[i][j],maze[i][k] + maze[k][j]);
                }
            }
        }
        int pos = 0;
        long long ans = 0x3f3f3f3f3f3f;
        for(int i = 0;i <= 9;++i){
            long long tmp = 0;
            for(int j = 0;j <= 9;++j){
                if(!tag[j]) continue;
                tmp += maze[i][j];
            }
            if(ans > tmp){
                ans = tmp;
                pos = i;
            }
            
        }
        cout << pos << ' ' << ans << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
typedef pair<int,int> mypair;
int main(){
	while(1){
	int n;
	cin>>n;
	if(n==0)break;
	vector<vector<int> > g(11,vector<int> (11,inf) );
	for(int i=0;i<11;i++)g[i][i] = 0;
	int v=0;
	for(int i=0;i<n;i++){
	int a,b,c;
	cin>>a>>b>>c;
	cmax(v,a);
	cmax(v,b);
	g[a][b] =g[b][a]=c;
	}
	for(int k=0;k<=v;k++)
		for(int i=0;i<=v;i++)
			for(int j=0;j<=v;j++)cmin(g[i][j] ,g[i][k]+g[k][j]);
	vector<int> used(v+1,0);
	for(int i=0;i<=v;i++)for(int j=0;j<=v;j++)used[i]+=g[i][j];

	
	mypair ans = mypair(used[0],0);
	for(int i=1;i<=v;i++)cmin(ans,mypair(used[i],i));
	cout<<ans.second<<' '<<ans.first<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 100000
using namespace std;

int main(){
	//int town[11][11];
	int to,from,cost;
	int n;
	while(1){
		cin>>n;
		if(!n)break;
		int maxsize=0;
		int dt[11][11];
		for(int i=0;i<11;i++){
			for(int j=0;j<11;j++){
				//town[i][j]=INF;
				if(i!=j)dt[i][j]=INF;
				else dt[i][j]=0;
				//out<<"yeah "<<i<<" "<<j<<endl;
			}
		}
		for(int i=0;i<n;i++){
			cin>>to>>from>>cost;
			//cout<<"analize"<<endl;
			dt[to][from]=cost;
			dt[from][to]=cost;
			maxsize=max(maxsize,to);
			maxsize=max(maxsize,from);
		}
		for(int k=0;k<maxsize+1;k++){
			for(int i=0;i<maxsize+1;i++){
				for(int j=0;j<maxsize+1;j++){
					dt[i][j]=min(dt[i][j],dt[i][k]+dt[k][j]);
				}
			}
		}
		int sum[maxsize+1];
		rep(i,maxsize+1){
			sum[i]=0;
			rep(j,maxsize+1){
				sum[i]+=dt[i][j];
			}
			//cout<<sum[i]<<" ";
		}
		int ans[maxsize+1];
		rep(i,maxsize+1)ans[i]=sum[i];
		sort(sum,sum+maxsize+1);
		//cout<<sum[0]<<endl;
		for(int i=0;i<maxsize+1;i++){
			if(ans[i]==sum[0]){
				cout<<i<<" "<<sum[0];
			}
		}
		cout<<endl;
		//cout<<"finish"<<endl;
	}
	return 0;
}