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 <algorithm>
#include <climits>

const int max_t = 20;
int dist[max_t][max_t];

int main() {
	//freopen("aoj0189.txt", "r", stdin);
	while (1) {
		int n, t = 0;
		scanf("%d", &n);
		if (n == 0) break;
		
		for (int i = 0; i < max_t; i++) {
			std::fill(dist[i], dist[i] + max_t, INT_MAX);
		}
		for (int i = 0; i < n; i++) {
			int from, to, d;
			scanf("%d%d%d", &from, &to, &d);
			t = std::max(t, from);
			t = std::max(t, to);
			dist[from][to] = d;
			dist[to][from] = d;
		}
		for (int i = 0; i <= t; i++) {
			dist[i][i] = 0;
		}

		for (int i = 0; i <= t; i++) {
			for (int j = 0; j <= t; j++) {
				for (int k = 0; k <= t; k++) {
					if (dist[i][k] != INT_MAX && dist[k][j] != INT_MAX)
						dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}

		int min_len = INT_MAX;
		int start = -1;
		for (int i = 0; i <= t; i++) {
			int len = 0;
			for (int j = 0; j <= t; j++) {
				if (j == i) continue;

				len += dist[i][j];
			}
			if (len < min_len) {
				min_len = len;
				start = i;
			}
		}

		printf("%d %d\n", start, min_len);
	}
	return 0;
}

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

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

const int MAXV = 11, INF = 10000;

struct edge{int to, cost;};

typedef pair<int ,int> pp;

int d[MAXV];
int n, a, b, c, t, anst, ansc, minc;

int main()
{
    while(cin >> n && n)
    {
        anst = MAXV;
        ansc = INF;
        t = 0;
        vector<edge> g[MAXV];
        

        REP(n)
        {
            cin >> a >> b >> c;
            g[a].push_back((edge){b, c});
            g[b].push_back((edge){a, c});

            t = max(t, a+1);
            t = max(t, b+1);
        }

        rep(k,t)
        {
            memset(d, INF, sizeof(d));
            d[k] = 0;
            priority_queue<pp, vector<pp>, greater<pp> > que;
            que.push(pp(0, k));

            while(!que.empty())
            {
                pp 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(pp(d[e.to], e.to));
                    }
                }
            }
            minc = 0;
            REP(t) minc += d[i];
            if(minc < ansc) {anst = k; ansc = minc;}
        }
        cout << anst << " " << ansc << endl;
    }

    return 0;
}

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;
    rep(k,n)rep(a,n)rep(b,n)in[a][b]=min(in[a][b],in[a][k]+in[k][b]);
    int out;
    rep(i,n){
      int sum=0;
      rep(j,n){
	if(i==j)continue;
	sum+=in[i][j];
	//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<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define Inf 1000000
int dist[105][105];
int main()
{
    int n,a,b,s;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        for (int i=0; i<100; i++)
        {
            for (int j=0; j<100; j++)
            {
                dist[i][j]=Inf;
                dist[j][i]=Inf;
                if(i==j) dist[i][j]=0;
            }
        }
        int m=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d%d%d",&a,&b,&s);
            dist[a][b]=s;
            dist[b][a]=s;
            m=max(m,max(a,b)+1);
        }
        //printf("%d\n",m);
        for (int i=0; i<m; ++i)
        {
            for (int j=0; j<m; ++j)
            {
                for (int k=0; k<m; ++k)
                {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                    /*if (dist[i][k] + dist[k][j] < dist[i][j] )
                    {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }*/
                }
            }
        }
        int aa[100],weizhi[10000];
        memset(aa,0,sizeof(aa));
        for(int i=0; i<m; i++)
        {
            for(int j=0; j<m; j++)
            {
                aa[i]+=dist[i][j];
            }
            weizhi[aa[i]]=i;//weizhi[aa[0]]
        }
        //sort(aa,aa+m);
        int ans = min_element(aa,aa + m) - aa;
        printf("%d %d\n",ans,aa[ans]);
    }
    return 0;
}