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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }

    replace(dist.begin(), dist.end(), INT_MAX, 0);
}

void shortestPath(const vector<vector<Edge> >& edges, vector<vector<int> >& dist)
{
    dist.resize(edges.size());
    for(unsigned i=0; i<edges.size(); ++i)
        shortestPath(edges, i, dist[i]);
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<vector<Edge> > edges(10);
        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            edges[a].push_back(Edge(b, c));
            edges[b].push_back(Edge(a, c));
        }

        vector<vector<int> > dist;
        shortestPath(edges, dist);

        int k;
        int sum = INT_MAX;
        for(int i=0; i<n; ++i){
            int tmp = accumulate(dist[i].begin(), dist[i].end(), 0);
            if(tmp != 0 && tmp < sum){
                sum = tmp;
                k = i;
            }
        }
        cout << k << ' ' << sum << endl;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;
const int N = 107;
#define inf 0x3f3f3f3f
int dis[N][N];
int main()
{
    int n;
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    while(cin >> n , n) {
        int v = 0, a, b, c;
        for(int i = 0;i < N;i ++) for(int j = 0;j < N;j ++)  dis[i][j] = (i == j) ? 0 : inf;
        for(int i = 1;i <= n;i ++) {
            cin >> a >> b >> c;
            dis[a][b] = dis[b][a] = c;
            v = max(max(v, a), b);
        }
        v ++;
        for(int k = 0;k < v;k ++) {
            for(int j = 0;j < v;j ++) {
                for(int i = 0;i < v;i ++) {
                    dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
                }
            }
        }
        int ans1,ans2 = inf,x;
        for(int i = 0;i < v;i ++) {
            x = 0;
            for(int j = 0;j < v;j ++) {
                x += dis[i][j];
            }
            if(x < ans2) {
                ans1 = i, ans2 = x;
            }
        }
        cout << ans1 << " " << ans2 << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

static const int INF = 1e9;
int d[11];
struct edge
{
	int from;
	int to;
	int cost;
};

void BellmanFord()
{
	int n;
	while (cin >> n, n)
	{
		vector<edge> E;
		for (int i = 0; i < n; ++i)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			edge e1, e2;
			e1.from = e2.to = from;
			e1.to = e2.from = to;
			e1.cost = e2.cost = cost;
			E.push_back(e1);
			E.push_back(e2);
		}
		int minPos = 0;
		int minSumCost = INF;
		for (int i = 0; i < 10; ++i)
		{			
			for (int j = 0; j < 10; ++j)
			{
				d[j] = INF;
			}
			d[i] = 0;
			bool update = true;
			while (update)
			{
				update = false;
				for (int j = 0; j < E.size(); ++j)
				{
					edge e = E[j];
					if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost)
					{
						d[e.to] = d[e.from] + e.cost;
						update = true;
					}
				}
			}
			int sum = 0;
			for (int j = 0; j < 10; ++j)
			{
				if (d[j] != INF)
				{
					sum += d[j];
				}
			}
			if (sum == 0)
			{
				continue;
			}
			if (minSumCost > sum)
			{
				minSumCost = sum;
				minPos = i;
			}
		}
		cout << minPos << " " << minSumCost << endl;
	}
}

int dist[11][11];
void WarshallFloyd()
{
	int n;
	while (cin >> n, n)
	{
		for (int i = 0; i < 10; ++i)
		{
			for (int j = 0; j < 10; ++j)
			{
				dist[i][j] = INF;
			}
			dist[i][i] = 0;
		}
		for (int i = 0; i < n; ++i)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			dist[from][to] = cost;
			dist[to][from] = cost;
		}
		for (int k = 0; k < 10; ++k)
		{
			for (int i = 0; i < 10; ++i)
			{
				for (int j = 0; j < 10; ++j)
				{
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
		int minSumCost = INF;
		int minPos = 0;
		for (int i = 0; i < 10; ++i)
		{
			int sum = 0;
			for (int j = 0; j < 10; ++j)
			{
				if (dist[i][j] != INF)
				{
					sum += dist[i][j];
				}
			}
			if (sum == 0)
			{
				continue;
			}
			if (minSumCost > sum)
			{
				minSumCost = sum;
				minPos = i;
			}
		}
		cout << minPos << " " << minSumCost << endl;
	}
}

int main()
{
	BellmanFord();
	//WarshallFloyd();
	return(0);
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#define inf 1000000
using namespace std;
int d[10][10];
int v;

int main()
{
	int n;
	while(cin>>n,n)
	{
		bool used[10];
		memset(used,0,sizeof(used));
		memset(d,0,sizeof(d));
		for(int i=0;i<n;i++)
		{
			int s,t,c;
			cin>>s>>t>>c;
			used[s]=used[t]=true;
			d[s][t]=d[t][s]=c;
		}
		v=0;
		for(int i=0;i<10;i++)
		{
			if(used[i]) v=i;
			for(int j=0;j<10;j++)
			{
				if(d[i][j]==0&&i!=j) d[i][j]=inf;
			}
		}

		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,mn=inf;
		for(int i=0;i<=v;i++)
		{
			int sum=0;
			for(int j=0;j<=v;j++)
			{
				sum+=d[i][j];
			}
			if(sum<mn)
			{
				ans=i;mn=sum;
			}
		}
		cout<<ans<<" "<<mn<<endl;

	}
	return 0;
}