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>
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 pair<int,ll> P;

ll cost[15][15];

int main()
{
	int n,max;
	ll sum,min;
	vector<P> vec;
	P min_p;

	while(cin>>n,n){
		min=INF;
		max=0;
		vec.clear();
		
		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];
			}
			vec.push_back(P(i,sum));
		}

		for(vector<P>::iterator it=vec.begin();it!=vec.end();++it){
			if(min>(*it).second){
				min=(*it).second;
				min_p=*it;
			}
		}
		cout<<min_p.first<<" "<<min_p.second<<endl;
	}
	return 0;
}

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

using namespace std;

int main(void){
  int n;
  while(cin>>n,n){
    vector<vector<int> > road(15,vector<int>(15,1<<22));
    int maxn = 0;
    for(int i = 0 ; i < 15 ; i ++)road[i][i] = 0;
    
    for(int i = 0 ; i < n ; i ++){
      int a,b,c;
      cin>>a>>b>>c;
      road[a][b] = c;
      road[b][a] = c;
      if(maxn<max(a,b))maxn=max(a,b);
    }
    
    for(int k = 0 ; k <= maxn ; k ++)
    for(int i = 0 ; i <= maxn ; i ++)
    for(int j = 0 ; j <= maxn ; j ++)
      road[i][j] = min(road[i][j], road[i][k] + road[k][j]);
    
    int min = 1<<22;
    int num = 0;
    
    for(int i = 0 ; i <= maxn ; i ++){
      int sum = 0;
      for(int j = 0 ; j <= maxn ; j ++){
        sum += road[i][j];
      }
      if(min>sum){
        min = sum;
        num = i;
      }
      
    } 
    cout<< num << " " << min << endl;
  }
  
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

#define INF 1<<24
#define MAX_V 999

using namespace std;

struct Node{
	int cost;
	int depart;
	int arrival;
};

vector<Node> dat;
vector<int> cost;

void dijkstra(int s){
	int pos;
	queue<int> q;
	int t;
	cost.at(s)=0;
	
	for(vector<Node>::iterator i=dat.begin();i!=dat.end();i++){
		if((*i).depart==s){
			q.push((*i).arrival);
			cost.at((*i).arrival)=(*i).cost;
		}
	}
	
	while(!q.empty()){
		
		pos=q.front();
		q.pop();
		
		for(vector<Node>::iterator i=dat.begin();i!=dat.end();i++){			if((*i).depart==pos){
				if(cost.at((*i).arrival)==INF){
					q.push((*i).arrival);
				}
				if(cost.at((*i).arrival)>(*i).cost+cost.at(pos)){
					cost.at((*i).arrival)=(*i).cost+cost.at(pos);
				}
			}
		}
		bool f=true;
		rep(i,cost.size()){
			if(cost.at(i)==INF){
				f=false;
			}
		}
		if(f){
			break;
		}
	}
}

int main(){
	int a, b, c, num;
	Node t;
	int n;
	while(cin>>n,n){
		num=0;
		dat.clear();
		cost.clear();
		rep(i,n){
			cin>>a>>b>>c;
			t.depart =a;
			t.cost   =c;
			t.arrival=b;
			dat.push_back(t);
			t.depart =b;
			t.cost   =c;
			t.arrival=a;
			dat.push_back(t);
			num=max(num,max(a,b));
		}
		rep(k,n+1){
			cost.push_back(INF);
		}
		num++;
		int mini=-1, mCost=INF;
		rep(i,num){
			int sum=0;
			cost.clear();
			rep(k,num){
				cost.push_back(INF);
			}
			dijkstra(i);
			rep(j,num){
				sum+=cost.at(j);
			}
			if(sum<mCost){
				mCost=sum;
				mini=i;
			}
		}
		cout<<mini<<" "<<mCost<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
typedef long long ll;

using namespace std;

const int mod=1e9+7;
const int INF=1<<25;

void solve(int n){
  int dp[11][11];
  fill(dp[0],dp[10],INF);
  rep(i,9) dp[i][i]=0;
  int a,b,c;
  int first=10,last=0;
  int ans1;
  ll ans2=INF,temp;
  rep(i,n){
    cin >> a >> b >> c;
    first=min(first,min(a,b));
    last=max(last,max(a,b));
    dp[a][b]=dp[b][a]=c;
  }
  rep(k,n) rep(i,n) rep(j,n){
    dp[j][i]=dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
  }
  REP(i,first,last+1){
    temp=0;
    REP(j,first,last+1){
      temp+=dp[i][j];
    }
    if(temp<ans2){
      ans2=temp;
      ans1=i;
    }
  }
  cout << ans1 << " " << ans2 << endl;

  return ;
}
int main(){
  int n;
  while(true){
    cin >> n;
    if(!n)  break;
    solve(n);
  }
}

C++: #include <iostream>
#include <limits.h>
using namespace std;
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]=INT_MAX;
		for(int i=0;i<10;i++) dp[i][i]=0;
		for(int i=0;i<n;i++){
			int a,b,c; cin >> a >> b >> c ;
			dp[a][b]=dp[b][a]=c;
		}
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					if(dp[k][j]==INT_MAX || dp[i][k]==INT_MAX) continue;
					dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
				}
			}
		}
		int NUM=0, MIN=INT_MAX;
		for(int i=0;i<10;i++){
			int sum=0;
			for(int j=0;j<10;j++){
				if(dp[i][j]==INT_MAX) continue;
				sum+=dp[i][j];
			}
			if(sum==0) continue;
			if(sum<MIN) MIN=sum,NUM=i;
		}
		cout << NUM << ' ' << MIN << '\n' ;
	}
}