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 <iostream>
#include <map>
#include <vector>
#include <queue>
#define MAX_V 10
#define INF 1000000
#define NIL -1
using namespace std;

struct edge {int to,cost;};
typedef pair<int,int> P;	//first:最短距離 second:頂点番号


int d[MAX_V];

void dijkstra(int s,vector<edge> G[]){
	//greater<P>を指定することでfirstが小さい順に取り出せるようになる
	priority_queue<P,vector<P>,greater<P>> que;
	//fill(d,d+V,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;//最短距離でなければ無視する
		for(int i = 0;i < G[v].size();i++){
			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 E;
bool cities[MAX_V];//その番号の町が出てくるか否か

int main(){
	cin >>E;
	while(E != 0){
		vector<edge> G[MAX_V];		//隣接リスト
		fill(cities,cities + MAX_V,false);
		int a,b,cost;
		for(int i = 0;i < E;i++){
			cin >>a >>b >>cost;
			cities[a] = true;cities[b] = true;
			edge e;e.to = b;e.cost = cost;
			G[a].push_back(e);
			e.to = a;
			G[b].push_back(e);
		}
		int mini = INF;int num = NIL;
		for(int i = 0;i < MAX_V;i++){
			fill(d,d+MAX_V,INF);
			for(int j = 0;j < MAX_V;j++){
				if(!cities[j])d[j] = 0;}
			dijkstra(i,G);
			int min_tmp= 0;
			for(int k = 0;k < MAX_V;k++)min_tmp += d[k];
			if(min_tmp < mini){mini = min_tmp;num = i;}
		}
		cout <<num <<" " <<mini <<endl;
		cin >>E;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<set>
#include<climits>
#define inf INT_MAX
using namespace std;

int main()
{
	int n;
	while(cin>>n,n)
	{
		unsigned long long d[10][10],sum[10]={};
		for(int i=0;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				d[i][j]=i==j?0:inf;
			}
		}
		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;
		}
		int v=ss.size();		
		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>
#include<algorithm>

using namespace std;

const int INF = 10000000;
int n;
int d[10][10];

int main() {
	while (cin >> n, n) {
		int town_max = 0;
		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;
		}
		for (int i = 0; i < n; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			town_max = max(town_max, max(a, b));
			d[a][b] = f, d[b][a] = f;
		}
		for (int k = 0; k <= town_max; k++) {
			for (int i = 0; i <= town_max; i++) {
				for (int j = 0; j <= town_max; j++) {
					if (d[i][j] > d[i][k] + d[k][j]) {
						d[i][j] = d[i][k] + d[k][j];
					}
				}
			}
		}
		int ans = INF,node;
		for (int i = 0; i <= town_max; i++) {
			int total = 0;
			for (int j = 0; j <= town_max; j++) {
				total += d[i][j];
			}
			if (ans > total)node = i, ans = total;
		}
		cout << node << " " << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
 
#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fe(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;
 
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
 
template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

int N;
int dp[11][11]={0};
int main()
{
	while(cin >> N,N){
		int K=0;
		rep(i,11){
			rep(j,11){
				dp[i][j]=inf;
			}
		}
		rep(i,11){
			dp[i][i]=0;
		}
		rep(i,N){
			int a,b,c;
			cin >> a >> b >>c;
			K=max(K,max(a,b));
			dp[a][b]=c;
			dp[b][a]=c;
		}
		K++;
		rep(i,K){
			rep(j,K){
				rep(k,K){
					dp[j][k]=min(dp[j][k],dp[i][j]+dp[i][k]);
				}
			}
		}
		int ans=inf;int id;
		rep(i,K){
			int t=0;
			rep(j,K){
				t+=dp[i][j];
			}
			if(ans > t){
				ans=t;
				id=i;
			}
		}
		printf("%d %d\n",id,ans);

	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define INF 1000000
#define MAX_V 10

int d[MAX_V][MAX_V]; // d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF.ただしd[i][i]=0とする)
int V; // 頂点数

void warshall_floyd() {
    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]);
}

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

main() {

    int n,a, b, c;
    V = MAX_V;
    while(cin>>n,n!=0) {
        clearD();
        for(int i=0;i<n;i++) {
            cin>>a>>b>>c;
            d[a][b]=c;
            d[b][a]=c;
        }
        warshall_floyd();
        int ans = INF;
        int ans_pos = 0;
        for(int i=0;i<V;i++) {
            int sum = 0;
            for(int j=0;j<V;j++) {
                if(d[i][j] == INF) continue;
                sum += d[i][j];
            }
            if(sum != 0 && sum < ans) {
                ans = sum;
                ans_pos = i;
            }
        }
        cout << ans_pos << " " << ans << endl;
    }
}