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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>

using namespace std;
int inf = 0x3f3f3f3f;

int maps[50][50];
//int dis[50],vis[50];
void floyd(int k,int n)
{

    for(int t =k; t<=n; t++)
        for(int i = k; i<=n; i++)
            for(int j = k; j<=n; j++)
                if(maps[i][j]>maps[i][t]+maps[t][j])
                    maps[i][j]=maps[i][t]+maps[t][j];
}
int main(void)
{
    int n;
    while(scanf("%d",&n)&&n)
    {
        memset(maps,inf,sizeof(maps));
        //memset(dis,inf,sizeof(dis));
        int ma = 0;
        int k = inf;
        for(int i = 0; i<n; i++)
        {
            int x,y,w;
            scanf("%d%d%d",&x,&y,&w);
            maps[x][y] = maps[y][x] = w;
            maps[i][i] = 0;
            ma = max(ma,x);
            ma = max(ma,y);
            k = min(k,x);
            k = min(k,y);
        }
        floyd(k,ma);
        int mi = inf,b=k;
        for(int i = k;i <=ma; i++)
            {
                int sum = 0;
                for(int j = k; j<=ma; j++)
                {
                    sum += maps[i][j];
                }
                if(sum<mi)   b = i,mi=sum;

            }

        printf("%d %d\n",b,mi);
    }
    return 0;
}

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]=min(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=max(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 <queue>
#include <vector>
#include <stdio.h>
using namespace std;

const int INF = 1e8;
struct edge{int to, cost;};
typedef pair<int, int> pii;
const int MAX_N = 45;
const int MAX_V = 10;
int n, V;
//ある街から出ている道
vector<edge> G[MAX_V];
int d[MAX_V];

int dijkstra(int s){
    int ret = 0;
    priority_queue<pii, vector<pii>, greater<pii> > que;
    fill(d, d+V, INF);
    
    d[s] = 0;
    que.push(pii(0, s));
    
    while(!que.empty()){
        pii 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(pii(d[e.to], e.to));
            }
        }
    }
    for(int i=0; i<V; i++)
        ret += d[i];
    return ret;
}

void solve(){
    int ans = INF, num;
    int vmax = 0;
    int from, to, cost;
    for(int i=0; i<n; i++){
        scanf("%d%d%d", &from, &to, &cost);
        G[from].push_back(edge{to, cost});
        G[to].push_back(edge{from, cost});
        vmax = max(vmax, max(from, to));
    }
    V = vmax+1;
    for(int i=0; i<V; i++){
        int tmp;
        if ((tmp = dijkstra(i)) < ans){
            ans = tmp;
            num = i;
        }
    }
    printf("%d %d\n", num, ans);
}

int main(){
    while(scanf("%d", &n), n)
        solve();
    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;

int time[10][10];
int town;
int INF = 9999;

void fw(){
    for(int k = 0; k <= town; k++){
        for(int i = 0; i <= town; i++){
            for(int j = 0; j <= town; j++){
                time[i][j] = min(time[i][j], time[i][k] + time[k][j]);
            }
        }
    }
}

void solve(){
    int ret, mintime = 1<<21;
    for(int i = 0; i <= town; i++){
        int candidate = 0;
        for(int j = 0; j <= town; j++){
            candidate += time[i][j];
        }
        if(candidate < mintime){
            mintime = candidate;
            ret = i;
        }
    }

    cout << ret << " " << mintime << endl;
}

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

        if(n == 0)  break;

        town = 0;
        memset(time, INF, sizeof(time));
        for(int i = 0; i < 10; i++) time[i][i] = 0;

        int a, b, c;
        while(n-- > 0){
            cin >> a >> b >> c;
            time[a][b] = time[b][a] = c;
            town = max(town, max(a,b));
        }

        fw();
        solve();
    }
    return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x>y?y:x)
#define INF 1000000
typedef long long ll;
typedef map<ll,int> M;

int cost[15][15];

int main()
{
	int n;
	ll sum;
	int max=0;
	M d;
	while(cin>>n,n){
		max=0;

		for(int i=0;i<15;i++){
			for(int j=0;j<15;j++){
				cost[i][j]=(i==j?0:INF);
			}
		}
		
		for(int i=0;i<n;++i){
			int a,b,c;
			cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
			if(max<MAX(a,b))max=MAX(a,b);

		}
		
		for(int i=0;i<=max;i++){
			for(int j=0;j<=max;j++){
				for(int k=0;k<=max;k++){
					cost[i][j]=MIN(cost[i][j],cost[i][k]+cost[k][j]);
				}
			}
		}
		
		for(int i=0;i<=max;i++){
			sum=0;
			for(int j=0;j<=max;j++){
				sum+=cost[i][j];
			}
			d[sum]=i;
		}
		M::iterator it=d.begin();
		cout<<(*it).second<<" "<<(*it).first<<endl;
		d.clear();
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#define INF 1 << 16
#define MAX_V 10
using namespace std;
int d[MAX_V][MAX_V];
int maxv;

void warshall_floyd() {
	for (int i = 0; i <= maxv; ++i) {
		for (int j = 0; j <= maxv; ++j) {
			for (int k = 0; k <= maxv; ++k) {
				d[i][j] = (d[i][k] + d[k][j] < d[i][j]) ? d[i][k] + d[k][j] : d[i][j];
			}
		}
	}
	return;
}

int main() {
	int m, a, b, c, minv, minsum;

	while (cin >> m) {
		for (int i = 0; i < MAX_V; ++i) {
			for (int j = 0; j < MAX_V; ++j) {
				d[i][j] = (i == j) ? 0 : INF;
			}
		}
		while (m--) {
			cin >> a >> b >> c;
			maxv = (b > maxv) ? a : maxv;
			maxv = (b > maxv) ? b : maxv;
			d[a][b] = c;
			d[b][a] = c;
		}
		warshall_floyd();

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

		minsum = INF;
		for (int i = 0; i <= maxv; ++i) {
			if (sum[i] < minsum) {
				minv = i;
				minsum = sum[i];
			}
		}
		cout << minv << " " << minsum << endl;
	}
	return 0;
}