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>
#define INF 10000000
using namespace std;
const int maxn=1000;
int n;
int s[maxn][maxn];
int dp[maxn][maxn];
int x,y,l;
int main()
{
    while(scanf("%d",&n)&&n)
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i==j) s[i][j] = 0;
                else s[i][j]=INF;
            }
        }
        int v=-1;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d",&x,&y,&l);
            s[x][y]=s[y][x]=l;
              v = max(v, max(x, y));
        }
        for(int k=0;k<=v;k++)
        {
            for(int i=0;i<=v;i++)
            {
                for(int j=0;j<=v;j++)
                {
                    s[i][j]=min(s[i][j],s[i][k]+s[k][j]);
                }
            }
        }
        int ans=INF;
        int loc;
        for(int i=0;i<=v;i++)
        {
            int sum=0;
           for (int j=0;j<=v;j++)
            {
                sum+=s[i][j];
            }
            if(sum<ans)
            {
                loc=i;
                ans=sum;
            }
        }
        printf("%d %d\n",loc,ans);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>

#define rep(i,n)	for(int i = 0;i < n;i++)
#define rep2(i,n)	for(int i = 1;i <= n;i++)
#define each(i,x)	for(auto & i : x)

using namespace std;

struct edge
{
	edge(int _s,int _t,int _cost)
	{
		s = _s;t = _t;cost = _cost;
	}
	int s;
	int t;
	int cost;
};

int main()
{
	int n;
	cin >> n;
	while(n)
	{
		vector<edge> ary;
		int mt = 0;
		rep(i,n)
		{
			int a,b,d;
			cin >> a >> b >> d;
			ary.push_back(edge(a,b,d));
			if(mt < a)
			{
				mt = a;
			}
			if(mt < b)
			{
				mt = b;
			}
		}
		mt++;
		vector<vector<int>> cost(mt,vector<int>(mt,1000000));
		rep(i,mt)
		{
			cost[i][i] = 0;
		}
		rep(i,ary.size())
		{
			int a = ary[i].s;
			int b = ary[i].t;
			int d = ary[i].cost;
			rep(j,mt)
			{
				rep(k,mt)
				{
					if(cost[j][k] > cost[j][a] + cost[b][k] + d)
					{
						cost[j][k] = cost[j][a] + cost[b][k] + d;
					}
					if(cost[j][k] > cost[j][b] + cost[a][k] + d)
					{
						cost[j][k] = cost[j][b] + cost[a][k] + d;
					}
				}
			}
		}
		int smin = 1000000;
		int imin = 0;
		rep(i,mt)
		{
			int s = 0;
			rep(j,mt)
			{
				s += cost[i][j];
			}
			if(smin > s)
			{
				smin = s;
				imin = i;
			}
		}
		cout << imin << ' ' << smin << endl;
		cin >> n;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
typedef vector<P> vec;
typedef vector<vec> mat;

int main() {
    int N;
    while (cin >> N, N) {
        mat m(10);
        vector<vector<int> > dp(10, vector<int>(10, 1 << 28));
        for (int i = 0; i < N; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            dp[a][b] = dp[b][a] = c;

            dp[a][a] = 0;
            dp[b][b] = 0;
        }

        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 10; k++) {
                    dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
                }
            }
        }

        int ans = 999999999;
        int p;
        for (int i = 0; i < 10; i++) {
            if (dp[i][i] == 1 << 28) continue;

            int sum = 0;

            for (int j = 0; j < 10; j++) {
                if (dp[i][j] != 1 << 28) sum += dp[i][j];
            }

            if (ans > sum) {
                ans = sum;
                p = i;
            }
        }

        cout << p << " " << ans << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX 11
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum;
bool visit[MAX];

int dijkstra(int s,int g){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = 0 ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = 0 ; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            if(t < v[i] && r[mn][i] != INF) v[i] = t;
        }
    }
    
    return v[g];
}


int main(){
    int a,b,c;
    
    for(int i = 0 ; i < MAX ; i++)
        for(int j = 0 ; j < MAX ; j++)
            r[i][j] = INF;

    while(cin >> n,n){
        maxnum = 0;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = c;
            r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
        }

        int mx = INF, num = 0;
        for(int i = 0 ; i <= maxnum ; i++){
            int sum = 0;
            for(int j = 0 ; j <= maxnum ; j++){
                if(i == j) continue;
                if(dijkstra(i,j)!=INF) sum += dijkstra(i,j);
            }
            if(sum < mx){
                mx = sum;
                num = i;
            }
        }
        cout << num << ' ' << mx << endl;
    }
    
    return 0;
}