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<algorithm>

const int MAX_V = 10, INF = 1 << 24;
int V;
int d[MAX_V], used[MAX_V], cost[MAX_V][MAX_V];

void dijkstra(int s){
	std::fill(d, d+MAX_V, INF);
	std::fill(used, used+MAX_V, 0);

	d[s] = 0;

	while(true){
		int v = -1;
		for(int u=0;u<V;u++){
			if(!used[u] && (v == -1 || d[u] < d[v])){
				v = u;
			}
		}

		if(v == -1){
			break;
		}

		used[v] = 1;
		for(int u=0;u<V;u++){
			d[u] = std::min(d[u], d[v] + cost[v][u]);
		}
	}
}

int getCost(int s){
	dijkstra(s);
	int res = 0;
	for(int i=0;i<V;i++){
		if(i != s){
			res += d[i];
		}
	}

	return res;
}

int main(){
	int n = 0;
	while(std::cin >> n, n){
		for(int i=0;i<MAX_V;i++){
			std::fill(cost[i], cost[i]+MAX_V, INF);
		}
		V = 0;

		for(int i=0;i<n;i++){
			int a, b, c;
			std::cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			V = std::max(V, std::max(a+1, b+1));
		}

		int res = INF, town = 0;
		for(int i=V-1;i>=0;i--){
			int v = getCost(i);
			if(v <= res){
				res = v;
				town = i;
			}
		}
		std::cout << town << " " << res << std::endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
const int inf=1e9;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int in[11][11];
    rep(i,11)rep(j,11)in[i][j]=inf;
    int maax=0;
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      in[a][b]=c;
      in[b][a]=c;
      maax=max(maax,a);
      maax=max(maax,b);
    }
    n=maax+1;
    int mini=inf;
    int out;
    rep(i,n){
      int sum=0;
      rep(j,n){
	if(i==j)continue;
	vector<vector<int> >tmp(n,vector<int>(n));
	rep(a,n)rep(b,n)tmp[a][b]=in[a][b];
	rep(k,n)rep(a,n)rep(b,n)tmp[a][b]=min(tmp[a][b],tmp[a][k]+tmp[k][b]);
	sum+=tmp[i][j];
	//cout<<" "<<i<<" "<<j<<" "<<sum<<endl;
      }
      if(mini>sum){
	mini=sum;
	out=i;
      }
      //cout<<i<<" ! "<<sum<<endl;
    }
    cout<<out<<" "<<mini<<endl;
  }
}

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,first,last+1) REP(i,first,last+1) REP(j,first,last+1){
    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);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <set>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
int dis[50][50];
int main()
{
    int m,a,ans,b,oop,n,op;
    while(~scanf("%d",&n)&&n)
    {
        m = 0;
        for(int i = 0 ;i < 20; i++)
        {
            for(int j = 0 ; j <20 ;j++)
                dis[i][j] = INF;
        }
        for(int i = 0; i < n; i++)
        {
            scanf("%d%d",&a,&b);
            scanf("%d",&dis[a][b]);
            dis[b][a] = dis[a][b];
            if(m < a||m < b)
            {
                if(a<b)  m = b;
                else    m = a;
            }
        }
        for(int i = 0; i <= m; i++)  dis[i][i] = 0;
        for(int k = 0; k <= m; k++)
            for(int i = 0; i <= m; i++)
                for(int j = 0; j <= m; j++)
                {
                    if(dis[i][j] > dis[i][k] + dis[k][j])
                   {
                       dis[i][j] = dis[i][k] + dis[k][j];
                       dis[j][i] = dis[i][k] + dis[k][j];
                   }
                }
        oop = INF;
        for(int i = 0 ; i <= m;i++)
        {
            ans = 0;
            for(int u = 0 ; u <= m; u++)
            {
                if(dis[i][u] != INF)
                    ans += dis[i][u];
            }
            if(ans<oop)
            {
                op = i;
                oop = ans;
            }
        }
        printf("%d %d\n",op,oop);
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
int cost[11][11];
#define INF 10e6

using namespace std;

int main(void){
	int n,a,b,d;
	int cmax;
	int t,rmin,tmin;
	while(cin >> n,n){
		tmin=INF;
		cmax=0;
		for(int i=0;i<11;i++)
				for(int j=0;j<11;j++)
					cost[i][j]=INF;
					
		for(int i=0;i<11;i++)
			cost[i][i]=0;
			
		for(int i=0;i<n;i++){
			cin >> a >> b >> d;
			if(cmax<a)
				cmax=a;
			if(cmax<b)
				cmax=b;
			cost[a][b]=cost[b][a]=d;
		}
		for(int i=0;i<=cmax;i++)
			for(int j=0;j<=cmax;j++)
				for(int k=0;k<=cmax;k++)
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
		
		for(int i=0;i<=cmax;i++){
			t=0;
			for(int j=0;j<=cmax;j++)
					t+=cost[i][j];
			if(t<tmin)
				tmin=t,rmin=i;
		}
		cout << rmin << ' ' << tmin << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 305
using namespace std;
bool debug=false;

int d[12][12];

void init(){
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(i==j) d[i][j]=0;
      else d[i][j]=INF;
    }
  }
}

void make(int n){
  int a,b,c;
  for(int i=0;i<n;i++){
    cin>>a>>b>>c;
    d[a][b]=c;d[b][a]=c;
  }
}

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

void solve(){
  int mini=INF,num;
  for(int i=0;i<=10;i++){
    int sum=0;
    for(int j=0;j<=10;j++){
      if(d[i][j]!=INF)sum+=d[i][j];
    }
    if(sum<mini&&sum!=0){
      mini=sum;
      num=i;
    }
  }
  cout<<num<<" "<<mini<<endl;
}

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    init();
    make(n);
    wf();
    solve();
  }
  return 0;
}