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<algorithm>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<stack>
#include<sstream>
#include<complex>

#define pb push_back
#define clr clear()
#define sz size()
#define fs first
#define sc second

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(int)(a)−1;i>=0;i−−)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)−(b)) < EPS)
#define INIT(a) memset(a,0,sizeof(a))

using namespace std;
typedef double D;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const D EPS = 1e-8;
const int INF = 1e8;
const D PI = acos(-1);

struct edge{
  int to,cost;
  bool operator<(const edge x)const{return cost>x.cost; }
};
int v; //頂点数
int d[20]; //s から i への最短路
vector<edge> G[20]; //ク&#12441;ラフの隣接リスト表現

void AddEdge(int s,int g,int p){
  G[s].pb((edge){g,p});
}


void dijkstra(int s){
  fill(d,d+v,INF);
  d[s] = 0;
  priority_queue<P ,vector<P> ,greater<P> > q; q.push(P(0,s));
  while(q.sz){
    P p = q.top();q.pop();
    int u = p.second;
    if(d[u] < p.first)continue; rep(i,G[u].sz){
      edge e = G[u][i]; if(d[e.to] > d[u] + e.cost){
	d[e.to] = d[u] + e.cost;
	q.push(P(d[e.to],e.to));
      }
    }
  }
}

int n;
int a,b,c;

int main(){
  while(cin >> n,n){
    rep(i,20){
      G[i].clear();
    }

    v = 0;
    rep(i,n){
      cin >> a >> b >> c;
      v = max(v,max(a,b));
      AddEdge(a,b,c);
      AddEdge(b,a,c);
    }
    v++;

    int res = -1, dis = INF;
    rep(i,v){
      int tmp = 0;
      dijkstra(i);
      rep(j,v)tmp += d[j];
      if(dis > tmp){
	dis = tmp; res = i;
      }
    }
    cout << res << " " << dis <<  endl;
  }
    
}

C++: #include<cstdio>
#include<algorithm>
#define N 11
#define inf 10000000
using namespace std;
int d[N][N],V;
void warshall_floyd(void)
{
	for(int k=0;k<=V;k++)
	{
		for(int i=0;i<=V;i++)
		{
			for(int j=0;j<=V;j++)
			d[i][j]=d[i][j]<d[i][k]+d[k][j]?d[i][j]:d[i][k]+d[k][j];
		}
	}
	return ;
}
void init(void)
{
	for(int i=0;i<N;i++)
	fill(d[i],d[i]+N,inf);
	for(int i=0;i<N;i++)
	d[i][i]=0;
	return ;
}
int main(void)
{
	int n;
	while(scanf("%d",&n)==1)
	{
		if(n==0)
		break;
		init();
		int s,e,c;
		V=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",&s,&e,&c);
			d[s][e]=d[e][s]=c;
			V=s>e?s:e;
		}
		warshall_floyd();
		int ans=inf;
		int sum=0;
		int id=0;
		for(int i=0;i<=V;i++)
		{
			sum=0;
			for(int j=0;j<=V;j++)
			sum+=d[i][j];
			if(sum<ans)
			{
				ans=sum;
				id=i;
			}
		}
		printf("%d %d\n",id,ans);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXT = 11, MAXN = 45, INF = 10000;
int cost[MAXT][MAXT];
int d[MAXT];
bool used[MAXT];
int a, b, c, t, n, anst, ansc, tcost;

int main()
{
    while(cin >> n && n)
    {
        memset(cost, INF, sizeof(cost));
        t = 0;
        REP(n)
        {
            cin >> a >> b >> c;
            cost[a][b] = cost[b][a] = c;
            t = max(t, a + 1); t = max(t, b + 1);
        }
        anst = MAXT; ansc = INF;
        rep(k, t)
        {
            memset(d, INF, sizeof(d));
            memset(used, false, sizeof(used));
            d[k] = 0;
            tcost = 0;
            while(true)
            {
                int v = -1;
                rep(i, t)if(!used[i] && (v == -1 || d[i] < d[v])) v = i;
                if(v == -1) break;
                used[v] = true;
                rep(i,t) d[i] = min(d[i], d[v] + cost[v][i]);
            }
            REP(t) tcost += d[i];
            if(tcost < ansc){ anst = k; ansc = tcost;}
        }
        cout << anst << " "<< ansc << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;
const int MAX_E = 45;
const int MAX_V = 10;
const int INF = 1024 * 1024 * 1024;
struct edge {int to, cost; };
vector<edge> G[MAX_V];
vector<string> result;

int main() {
    int n;
    while(1) {
        cin >> n;
        if (n == 0) break;
        int max_v = -1;
        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            edge e, e1;
            e.to = to;
            e.cost = cost;
            G[from].push_back(e);
            e1.to = from;
            e1.cost = cost;
            G[to].push_back(e1);
            max_v = max(max(max_v, from), to);
        }

        int dps[max_v + 1];
        for(int i = 0; i <= max_v; i++) {
            int d[max_v] = {0};
            for(int k = 0; k <= max_v; k++) {
                d[k] = INF;
            }
            priority_queue<pair<int, int>> que;
            d[i] = 0;
            que.push(pair<int, int>(0, i));
            while(!que.empty()) {
                pair<int, int> p = que.top();
                que.pop();
                if(p.first > d[p.second]) continue;
                for(int j = 0; j < G[p.second].size(); j++) {
                    edge e1 = G[p.second][j];
                    if(d[e1.to] > d[p.second] + e1.cost) {
                        d[e1.to] = min(d[e1.to], d[p.second] + e1.cost);
                        que.push(pair<int, int>(d[e1.to], e1.to));
                    }
                }
            }


            int sum = 0;
            for(int j = 0; j <= max_v; j++) {
                sum += d[j];
            }

            dps[i] = sum;
        }

        int min_i = 0;
        for(int i = 1; i <= max_v; i++) {
            if(dps[min_i] > dps[i]) {
                min_i = i;
            }
        }

        result.push_back(to_string(min_i) + " " + to_string(dps[min_i]));
    }

    for(int i = 0; i < result.size(); i++) {
        cout << result[i] << endl;
    }
    return 0;
}