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 <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define INF (1000000000)
#define MOD (1000000007)
using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<double> VD;
typedef vector<double>::iterator VDI;
typedef pair<int, int> PII;

int d[10][10];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				d[i][j] = INF * (i != j);
			}
		}
		
		int v = 0;
		
		for (int i = 0; i < n; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			d[a][b] = c;
			d[b][a] = c;
			
			v = max(v, max(a, b));
		}
		
		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]);
				}
			}
		}
		
		PII mini = PII(INF, INF);
		for (int i = 0; i <= v; i++){
			int sum = 0;
			
			for (int j = 0; j <= v; j++){
				sum += d[i][j];
			}
			
			if (mini.second > sum){
				mini = PII(i, sum);
			}
		}
		printf("%d %d\n", mini.first, mini.second);
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
    vvi v(n+1,vi(n+1,INF));
    rep(i,n+1)v[i][i]=0;
    int hoge = 0;
    rep(i,n){
        int c;
        pii temp; cin>>temp.first>>temp.second>>c;
        v[temp.first][temp.second]=c;
        v[temp.second][temp.first]=c;
        hoge=max(hoge,max(temp.first, temp.second));
    }
    n=hoge+1;
    loop(k,0,n)
    loop(i,0,n)
    loop(j,0,n){
        v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
    }
    //loop(i, 0, n){loop(j, 0, n)cout<<v[i][j]<<" "; puts("");}
    ll ans=INF,temp=0; int num=12;
    loop(i,0,n){
        loop(j,0,n)temp+=v[i][j];
        if(ans>temp){num=i; ans=temp;}
        temp=0;
    }
    cout<<num<<" "<<ans<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <iterator>

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;


struct edge
{
	int to;
	int cost;

	edge(int to,int cost) : to(to),cost(cost) {}
};


vector<edge> G[10];
ll d[10];

void dijkstra(int s,int n)
{
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+n,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty())
	{
		P 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(P(d[e.to],e.to));
			}
		}
	}
}

int main()
{
	int n;
	
	while(cin >> n && n)
	{
		vector<int> t;
		rep(i,n)
		{
			int a,b,c;
			cin >> a >> b >> c;

			G[a].push_back(edge(b,c));
			G[b].push_back(edge(a,c));

			vector<int>::iterator ite = find(t.begin(),t.end(),a);
			if(ite == t.end())
			{
				t.push_back(a);
			}

			ite = find(t.begin(),t.end(),b);
			if(ite == t.end())
			{
				t.push_back(b);
			}

		}

		pair<int,ll> ans;
		ans.first = t[0];
		ans.second = INF;
		
		rep(i,t.size())
		{
			dijkstra(t[i],10);

			ll sum = 0;

			rep(j,t.size()) 
			{
				sum += d[t[j]];
			}


			if(ans.second > sum)
			{
				ans.first = t[i];
				ans.second = sum;
			}	
		}
		cout << ans.first << " " << ans.second << endl;
	}

	return 0;
	
}

C++: #include <algorithm>
#include <cstdio>
#include <climits>
#include <queue>
#include <vector>
using namespace std;

int d[10][10];

int main() {
	for (;;) {
		int n; scanf("%d", &n);
		if (n == 0) break;
		for (int u = 0; u < 10; u++)
			for (int v = 0; v < 10; v++)
				d[u][v] = (u == v) ? 0 : (INT_MAX / 2);
		int N = 0;
		for (; n > 0; n--) {
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			d[a][b] = c;
			d[b][a] = c;
			N = max(N, max(a + 1, b + 1));
		}
		for (int k = 0; k < N; k++)
			for (int u = 0; u < N; u++)
				for (int v = 0; v < N; v++)
					d[u][v] = min(d[u][v], d[u][k] + d[k][v]);
		int umin = 0, dmin = INT_MAX;
		for (int u = 0; u < N; u++) {
			int dsum = 0;
			for (int v = 0; v < N; v++)
				dsum += d[u][v];
			if (dsum < dmin) {
				umin = u;
				dmin = dsum;
			}
		}
		printf("%d %d\n", umin, dmin);
	}
}