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++: // 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

	//		if(a+1>m){
	//			m = a+1;
	//		}
	//		if(b+1>m){
	//			m = b+1;
	//		}
		}
//???????????§???????????????
//????????????????????????
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}
//????°???????????????¢???
		int town;//????????????
		int x=100000;//????????????
		for(int i=0;i<n;i++){
			int r=0;//i?????§???????????????
			for(int j=0;j<n;j++)
				r=r+T[i][j];
			if(r<x){
				x=r;
				town=i;
			}
		}
		cout<<town<<' '<<x<<endl;

	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define pb push_back
using namespace std;

struct edge {
    int to,from,cost;
};

bool app[11];
const int INF = 10000000;
vector<edge> E;
int d[11];

int wf(int a){
    FOR(i,0,11)d[i]=10000000;
    d[a]=0;
    while(1){
        bool update=false;
        FOR(i,0,E.size()){
            edge&e=E[i];
            if(d[e.to]>d[e.from]+e.cost){
                update=1;
                d[e.to]=d[e.from]+e.cost;
            }
        }
        if(!update) break;
    }
    int sum=0;
    FOR(i,0,11){
        if(app[i]) sum+=d[i];
    }
    return sum;
}

int main(){
    int n;
    while(1){
        cin>>n;
        if(!n) break;
        E.clear();
        memset(app,0,sizeof(app));
        FOR(i,0,n){
            int a,b,c; cin>>a>>b>>c;
            E.pb({a,b,c});
            E.pb({b,a,c});
            app[a]=app[b]=1;
        }
        int ans=INF;
        int town;
        FOR(i,0,11){
            if(!app[i])continue;
            int t=wf(i);
            if(ans>t){
                ans=t;
                town=i;
            }
        }
        cout<<town<<" "<<ans<<endl;
    }
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
template<class _T> _T MAX(_T p1,_T p2){return (p2<p1)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
typedef vector<int> VI;
typedef vector<VI> VVI;
#define pb                  push_back

const int inf = 1<<29;

void solve(VVI vi, int n){
    REP(k,n)REP(i,n)REP(j,n){
        vi[i][j] = MIN(vi[i][j], vi[i][k]+vi[k][j]);
    }
    int res = inf, idx = -1;
    REP(i,n){
        int total = 0;
        REP(j,n) total += vi[i][j];
        if(res > total){
            idx = i;
            res = total;
        }
    }
    cout << idx << " " << res << endl;
}

int main(void){
    int n;
    while(cin >> n && n){
        VVI vi(10, VI(10, inf));
        int m = 0;
        REP(i,n){
            int a,b,c;
            cin >> a>>b>>c;
            vi[a][b] = MIN(vi[a][b], c);
            vi[b][a] = MIN(vi[b][a], c);
            m = MAX(m, MAX(a,b));
        }
        m++;
        REP(i,m) vi[i][i] = 0;
        solve(vi, m);
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <climits>
typedef long long ll;

const int max_t = 20;
ll 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;
			ll d;
			scanf("%d%d%lld", &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++) {
						dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}

		ll min_len = INT_MAX;
		int start = -1;
		for (int i = 0; i <= t; i++) {
			ll 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 %lld\n", start, min_len);
	}
	return 0;
}

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);
    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;
}