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 <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;
const int MAX_E = 45;
const int MAX_V = 10;
const int INF = INT32_MAX;
struct edge {int to, cost; };
typedef pair<int, int> P;
vector<edge> G[MAX_V];
vector<string> result;

int main() {
    int n;
    while(1) {
        cin >> n;
        if (n == 0) break;
        int max_v = -1;
        for (int i = 0; i <= MAX_V; i++)G[i].clear();
        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            edge e, e1;
            e.to = to;
            e.cost = cost;
            G[from].push_back(e);
            e1.to = from;
            e1.cost = cost;
            G[to].push_back(e1);
            max_v = max(max(max_v, from), to);
        }
        max_v++;

        int dps[max_v];
        for(int i = 0; i < max_v; i++) {
            int d[max_v];
            fill(d, d + max_v, INF);
            priority_queue<P, vector<P>, greater<P>> que;
            d[i] = 0;
            que.push(P(0, i));
            while(!que.empty()) {
                P p = que.top();
                que.pop();
                int v = p.second;
                if(p.first > d[v]) continue;
                for(int j = 0; j < G[v].size(); j++) {
                    edge e = G[v][j];
                    if(d[e.to] > d[v] + e.cost) {
                        d[e.to] = d[v] + e.cost;
                        que.push(P(d[e.to], e.to));
                    }
                }
            }


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

            dps[i] = sum;
        }

        int min_i = 0;
        for(int i = 1; i < max_v; i++) {
            if(dps[min_i] > dps[i]) {
                min_i = i;
            }
        }

        result.push_back(to_string(min_i) + " " + to_string(dps[min_i]));
    }

    for(int i = 0; i < result.size(); i++) {
        cout << result[i] << endl;
    }
    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, 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;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
ll dp[50][50];
int main(){
  int n=47,m;
  while(cin>>m&&m){
    lol(i,n)lol(j,n)dp[i][j]=(i==j?0:mod);
    lol(i,m){
      ll a,b,c;cin>>a>>b>>c;
      dp[a][b]=c;
      dp[b][a]=c;
    }
    lol(k,n)lol(i,n)lol(j,n){
      dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
    }
    ll mini=mod,pnt;
    lol(i,n){
      ll sum=0,cnt=0;
      lol(j,n)if(dp[i][j]!=mod)sum+=dp[i][j],cnt++;
      if(sum<mini&&cnt>1)mini=sum,pnt=i;
    }
    cout<<pnt<<" "<<mini<<endl;
  }
  return 0;
}

C++: #include<algorithm>
#include<stdio.h>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
 
#define  N 15
int n;
int dis[N],maps[N][N];
int main()
{
    int i,a,b,c,j,k;
    while(scanf("%d",&n),n)
    {
        for(i=0;i<N;i++)
        {
            for(j=0;j<N;j++)
            {
                maps[i][j]=(i==j)?0:INF;
            }
        }
 
        int m=-1;
        for( i=0; i<n; i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            m=max(a,m);
            m=max(b,m);
            maps[a][b]=maps[b][a]=c;
        }
 
        for(k=0;k<=m;k++)
        {
            for(i=0;i<=m;i++)
            {
                for(j=0;j<=m;j++)
                {
                    if(maps[i][j]>maps[i][k]+maps[k][j])
                        maps[i][j]=maps[i][k]+maps[k][j];
                }
            }
        }
 
        int  Min=INF;
        int index=-1;
        memset(dis,0,sizeof(dis));
        for(i=0;i<=m;i++)
        {
            for(j=0;j<=m;j++)
            {
                dis[i]=dis[i]+maps[i][j];
            }
            if(Min>dis[i])
            {
                index=i;
                Min=dis[i];
            }
        }
        printf("%d %d\n",index,Min);
    }
    return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
	int t,map[12][12],sum,ans,s,i,j,k,max0,a,b,c;
	while(scanf("%d",&t) && t)
	{
		memset(map,1,sizeof(map));
		max0=0;
		for(i=0;i<t;i++)
		{
			scanf("%d %d %d",&a,&b,&c);
			map[a][b]=map[b][a]=c;
			max0=max(max0,max(a,b));
		}
	/*	printf("%d\n\n",max0);
		 for(i=0;i<=max0;i++)
		 {
		 	for(j=0;j<=max0;j++)
		 	{
		 		printf("%d  ",map[i][j]);
		 		if(j == max0)
		 			printf("\n");
			 }
		 }*/
		for(k=0;k<=max0;k++)
		{
			for(i=0;i<=max0;i++)
			{
				for(j=0;j<=max0;j++)
				{
					map[i][j]=min(map[i][j],map[i][k]+map[k][j]);
				}
			}
		}
		sum=10000000,ans=0;
		for(i=0;i<=max0;i++)
		{
			s=0;
			for(j=0;j<=max0;j++)
			{
				if(i != j)
				{
					s+=map[i][j];
				}
			}
			if(s < sum)
			{
				sum=s;
				ans=i;
			}
		}
		printf("%d %d\n",ans,sum);
	}
}