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 <algorithm>

using namespace std;

const int INF = 10000000;

int main(void)
{
	int m,n;
	int city[11][11];

	while( cin >> m && m ){
		for( int i = 0;i < 11;i++ ){
			for( int j = 0;j < 11;j++ ){
				city[i][j] = INF;
			}
		}

		for( int i = 0;i < 11;i++ ){
			city[i][i] = 0;
		}

		for( int i = 0;i < m;i++ ){
			int a,b,cost;

			cin >> a >> b >> cost;
			city[a][b] = cost;
			city[b][a] = cost;
		}

		for( int k = 0;k <= 10;k++ ){
			for( int j = 0;j <= 10;j++ ){
				for( int i = 0;i <= 10;i++ ){
					city[k][i] = min( city[k][i], city[k][j] + city[j][i] );
				}
			}
		}
		int answer = 0;
		int sum;
		int answer_sum = INF;
		for( int i = 0;i <= 10;i++ ){
			sum = 0;
			for( int j = 0;j <= 10;j++ ){
				sum += city[i][j];
				if( city[i][j] == INF ) sum -= INF;
			}
			if( answer_sum > sum && sum != 0 ){
				answer_sum = sum;
				answer = i;
			}
		}


		cout << answer << " " << answer_sum << endl;
	}

	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 = 50;
const int MAX_V = 15;
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 <vector>
#include <algorithm>
#include <functional>
#include <queue>

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

typedef pair<int, int> P;
struct edge2
{
	int to;
	int cost;
};

void Dijkstra()
{
	int n;
	while (cin >> n, n)
	{
		vector<edge2> E[11];
		for (int i = 0; i < n; ++i)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			edge2 e1, e2;
			e1.to = to;
			e2.to = from;			
			e1.cost = e2.cost = cost;
			E[from].push_back(e1);
			E[to].push_back(e2);
		}
		int minPos = 0;
		int minSumCost = INF;
		for (int i = 0; i < 10; ++i)
		{
			priority_queue<P, vector<P>, greater<P> > que;
			for (int j = 0; j < 10; ++j)
			{
				d[j] = INF;
			}
			d[i] = 0;
			que.push(P(0, i));
			while (!que.empty())
			{
				P p = que.top();
				que.pop(); int v = p.second;
				if (d[v] < p.first)
				{
					continue;
				}
				for (int j = 0; j < E[v].size(); ++j)
				{
					edge2 e = E[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 < 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();
	Dijkstra();
	//WarshallFloyd();
	return(0);
}