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;

enum { maxn = 50, INF = 1000000000 };

int G[maxn][maxn];
int vis[maxn];
int d[maxn][maxn];
int inq[maxn];
int m;

void spfa(int src)
{
    memset(inq, 0, sizeof inq);
    for(int i = 0; i < maxn; i++) d[src][i] = INF;
    d[src][src] = 0;
    queue< int > q;
    while(!q.empty()) q.pop();
    q.push(src);
    inq[src] = 1;
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(int i = 0; i < maxn; i++)
        {
            if(G[u][i])
            {
                if(d[src][u] + G[u][i] < d[src][i])
                {
                    d[src][i] = d[src][u] + G[u][i];
                    if(!inq[i])
                    {
                        inq[i] = 1;
                        q.push(i);
                    }
                }
            }
        }
        inq[u] = 0;
    }
}

int main()
{
    while(~scanf("%d", &m), m)
    {
        memset(vis, 0, sizeof(vis));
        memset(G, 0, sizeof(G));
        memset(d, 0, sizeof(d));
        for(int i = 0; i < m; i++)
        {
            int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
            G[a][b] = G[b][a] = c;
            vis[a] = vis[b] = 1;
        }
        for(int i = 0; i < maxn; i++)
            if(vis[i])
                spfa(i);
        int ans = INF, pt = -1;
        for(int i = 0; i < maxn; i++)
        {
            int sum = 0;
            if(vis[i])
            {
                for(int j = 0; j < maxn; j++)
                {
                    if(vis[j])
                    {
                        sum += d[i][j];
                    }
                }
                if(sum <= ans)
                {
                    ans = sum;
                    pt = i;
                }
            }
        }
        printf("%d %d\n", pt, ans);
    }
    return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#define MAX 100
#define INF 0x3f3f3f3f
using namespace std;
struct edge {
	int from, to, cost;
	edge(int a,int b,int c) {
		from = a;
		to = b;
		cost = c;
	}
};
typedef pair<int, int> P;
P fun(int s, int V, int E, vector<edge> es) {
	int d[MAX];
	fill(d, d + V, INF);
	d[s] = 0;
	while (true) {
		bool update = false;
		for (int i = 0; i<es.size(); i++) {
			edge e = es[i];
			if (d[e.from] != INF && d[e.to]>d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update)
			break;
	}
	int sum = 0;
	for (int i = 0; i<V; i++)
		sum += d[i];
	return P(sum, s);
}
P cmp(P a, P b) {
	if (a.first == b.first)
		return a.second<b.second ? a : b;
	return a.first<b.first ? a : b;
}
int  main() {
	ios::sync_with_stdio(0);
	vector<edge> es;
	int n;
	while (cin >> n && n) {
		es.clear();
		P res = P(INF, INF);
		int a, b, c, V=0;
		for (int i = 0; i< n; i++) {
			cin >> a >> b >> c;
			es.push_back(edge(a, b, c));
			es.push_back(edge(b, a, c));
			V = max(max(a, b), V);
		}
		for (int j = 0; j<n; j++)
			res = cmp(res, fun(j, V+1, es.size(), es));
		cout << res.second << " " << res.first << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<set>
#define inf 1000000000
using namespace std;
unsigned long long d[10][10],sum[10];
int v;

int main()
{
	int n;
	while(cin>>n,n)
	{
		memset(d,0,sizeof(d));
		memset(sum,0,sizeof(sum));
		set<int> ss;
		for(int i=0;i<n;i++)
		{
			int s,t,c;
			cin>>s>>t>>c;
			ss.insert(s);
			ss.insert(t);
			d[s][t]=d[t][s]=c;
		}
		v=ss.size();
		for(int i=0;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				if(d[i][j]==0&&i!=j) d[i][j]=inf;
			}
		}

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

		int ans;
		for(int i=0;i<v;i++)
		{
			for(int j=0;j<v;j++)
			{
				sum[i]+=d[i][j];
			}
		}
		ans=min_element(sum,sum+v)-sum;
		cout<<ans<<" "<<sum[ans]<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
int main(void){
  int n;
  int maze[10][10];
  while(cin>>n,n){
    int u=0;
    rep(i,10)rep(j,10)maze[i][j]=int(1e9);
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      u=max(a,max(u,b));
      maze[a][b]=c;
      maze[b][a]=c;
    }
    u++;
    //rep(i,u)rep(j,u)cout<<maze[i][j]<<(j==u-1?'\n':' ');
    rep(i,u)rep(j,u)rep(k,u)
      maze[i][j]=min(maze[i][j],maze[i][k]+maze[k][j]);
    int res=int(1e9);
    int sum;
    int rnum=0;
    rep(i,u){
      sum=0;
      rep(j,u)if(i!=j)sum+=maze[i][j];
      if(res>sum){
	res=sum;rnum=i;
      }
    }
    cout<<rnum<<" "<<res<<endl;
  }
}

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

const int TOWN = 10;
const int PATH = 45;
const int INF = 1000000000;

using namespace std;

int main() {
	int n;
	int a, b;

	while (cin >> n , n) {
		int num_of_town = 0;
		int g[TOWN][TOWN] = {};
		for (int i = 0; i < TOWN; i++) {
			for (int j = 0; j < TOWN; j++) {
				g[i][j] = 0;
			}
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			cin >> g[a][b];
			g[b][a] = g[a][b];
			num_of_town = max(num_of_town, max(a, b));
		}
		num_of_town++;
		//	cout << "num_of_town = " << num_of_town << "\n";

		int d[TOWN][TOWN];
		for (int i = 0; i < num_of_town; i++) {
			for (int j = 0; j < num_of_town; j++) {
				if (i == j)			d[i][j] = 0;
				else if (g[i][j] != 0) d[i][j] = g[i][j];
				else				d[i][j] = INF;
			}
		}

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

		//cout << "\n";
		//for (int i = 0; i < num_of_town; i++) {
		//	for (int j = 0; j < num_of_town; j++) {
		//		cout << i << " " << j << " " <<  d[i][j] << "\n";
		//	}
		//}
		//cout << "\n";

		int ans_d = INF;
		int ans_t;
		int tmp = 0;
		for (int i = 0; i < num_of_town; i++) {
			for (int j = 0; j < num_of_town; j++) {
				tmp += d[i][j];
			}
			if (ans_d > tmp) {
				ans_d = tmp;
				ans_t = i;
			}
			tmp = 0;
		}
		cout << ans_t << " " << ans_d << "\n";
	}
	
 	return 0;
}