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;
int main(void){
    int n;
    while(cin>>n,n){  //,演算子、最後の式を評価
        vector<vector<int>> graph(10,vector<int>(10,99999999));
        int used[10]={0};
        for(int i=0;i<n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            graph[a][b]=c;
            graph[b][a]=c;
            used[a]++;
            used[b]++;
        }
        for(int i=0;i<10;i++){
            if(used[i])
                graph[i][i]=0;
        }
        for(int k=0;k<10;k++){
            for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                    if(graph[i][j]>graph[i][k]+graph[k][j])
                        graph[i][j]=graph[i][k]+graph[k][j];
                }
            }
        }
        int min=99999999;
        int minpos;
        for(int i=0;i<10;i++){
            if(used[i]==0) continue;
            int sum=0;
            for(int j=0;j<10;j++){
                if(used[j]>0){
                    sum+=graph[i][j];
                }
            }
            if(min>sum){
                min=sum;
                minpos=i;
            }
        }
        cout<<minpos<<" "<<min<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>

using namespace std;

struct edge{
	int to,cost;
};
typedef pair<int,int> P;//firstがcost,secondがnodeを表す

vector<edge> G[20];//町から出る道を管理
int N;
int d[20];
const int INF=100000000;
bool flag=true;


void djikstra(int s){
	for(int i=0;i<N;i++){
		d[i]=INF;
	}
	
	priority_queue<P,vector<P>,greater<P> > que;//greater修正必要かも
	d[s]=0;
	//P np={0,s};
	que.push(P(0,s));
	
	while(que.size()){//確定したらそこから到達できるnodeをqueに登録する
		P p=que.top(); que.pop();
		int v=p.second;
		if(d[v]!=p.first) continue;//一度d[v]<p.totalになったらそのvはもう確定している
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			if(d[v]+e.cost<d[e.to]){
				d[e.to]=d[v]+e.cost;
				//P np1={d[e.to],e.to};間違い
				que.push(P(d[e.to],e.to));
			}
		}
	}
}
int A[10000][2];
int counter=0;
void solve(){
	int R,mind=INF,ans;N=0;
	cin>>R;
	if(R==0) {flag=false; return;}
	for(int i=0;i<R;i++){
		int x,y,c;
		cin>>x>>y>>c;
		N=max(N,max(x,y));
		edge ne1={y,c},ne2={x,c};
		G[x].push_back(ne1);
		G[y].push_back(ne2);
	}
	N++;
	int D[20]={0};
	for(int i=0;i<N;i++){
		djikstra(i);
		for(int j=0;j<N;j++){
			D[i]+=d[j];
		}
	}
	for(int i=0;i<N;i++){
		if(mind>D[i]){
			ans=i;
			mind=D[i];
		}
	}
	A[counter][0]=ans;A[counter][1]=mind;
	counter++;
	//cout<<ans<<" "<<mind<<endl;
}

int main(){
	while(flag){
		solve();
	}
	for(int i=0;i<counter;i++){
		cout<<A[i][0]<<" "<<A[i][1]<<endl;
	}
}

C++: #include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem0189 : Convenient Location **/
int d[10][10];
int E;


int main()
{
	int a, b, c, sum[10], minSum, minN;
	while (cin >> E, E!=0) {
		rep(i, 10) rep(j, 10) d[i][j]=INF;
		memset(sum, 0, sizeof(sum));
		minSum=INF;
		
		rep(i, E) {
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
		}
		
		rep(k, 10)
			rep(i, 10)
				rep(j, 10)
					d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
		
		rep(i, 10) {
			rep(j, 10) {
				if (d[i][j]<INF && i!=j)
					sum[i] += d[i][j];
			}
			if (minSum > sum[i]) {
				if (sum[i]<=0) continue;
				minSum = sum[i];
				minN = i;
			}
		}
		cout << minN << " " << minSum << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x>y?y:x)
#define INF 1000000
typedef long long ll;
typedef map<ll,int> M;

ll cost[15][15];

int main()
{
	int n;
	ll sum;
	int max=0;
	M d;
	while(cin>>n,n){
		max=0;

		for(int i=0;i<15;i++){
			for(int j=0;j<15;j++){
				cost[i][j]=(i==j?0:INF);
			}
		}
		
		for(int i=0;i<n;++i){
			int a,b
			ll c;
			cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
			if(max<MAX(a,b))max=MAX(a,b);

		}
		
		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++){
			sum=0;
			for(int j=0;j<=max;j++){
				sum+=cost[i][j];
			}
			d[sum]=i;
		}
		M::iterator it=d.begin();
		cout<<(*it).second<<" "<<(*it).first<<endl;
		d.clear();
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define INF 10000000
int d[11][11];
int min(int a,int b){
	if(a<b){
		return a;
	}else{
		return b;
	}
}
void warsall_floyd(){
	for(int i=0;i<11;i++){
		for(int j=0;j<11;j++){
			for(int k=0;k<11;k++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}	
		}
	}
	return;
}
int main(){
	while(1){
		int n,a,b,c,ans;
		ans=INF;
		for(int i=0;i<11;i++){
			for(int j=0;j<11;j++){
				d[i][j]=INF;
			}
			d[i][i]=0;
		}
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			d[a][b]=c;d[b][a]=c;
		}
		warsall_floyd();
		b=INF;
		for(int i=0;i<11;i++){
			a=0;
			for(int j=0;j<11;j++){
				if(d[i][j]<INF)a+=d[i][j];
			}
			if(a<ans&&a!=0){
				ans=a;b=i;
			}
		}
		cout<<b<<' '<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

const int INF=1<<21;

int main()
{
	int n;
	int f=0;
	while(cin>>n,n)
	{
		if(f)cout<<endl;
		f=1;
		int m[10][10]={};
		for(int i=0;i<10;i++)for(int j=0;j<10;j++)if(i!=j)m[i][j]=INF;
		int a,b,w,maxn=0;
		for(int i=0;i<n;i++)
		{
			cin>>a>>b>>w;
			m[a][b]=m[b][a]=w;
			maxn=max(maxn,max(a,b));
		}
		maxn++;
		for(int k=0;k<maxn;k++)
			for(int i=0;i<maxn;i++)
				for(int j=0;j<maxn;j++)
					m[i][j]=min(m[i][j],m[i][k]+m[k][j]);
		
		int d[10];
		for(int i=0;i<maxn;i++)d[i]=0;
		for(int i=0;i<maxn;i++)
		{
			for(int j=0;j<maxn;j++)
			{
				d[i]+=m[i][j];
			}
		}
		int mini=0;
		for(int i=1;i<maxn;i++)if(d[i-1]>d[i])mini=i;
		
		cout<<mini<<" "<<d[mini];
	}
	return 0;
}