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<vector>
#include<queue>
#include<functional>
#define INF 100000

using P = std::pair < int, int > ;

# define MAX_E 45
# define MAX_V 10

int V, E;

struct edge{
	int to, cost;
	edge(int _t, int _c) : to(_t), cost(_c) {}
};

std::vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
	std::priority_queue<P, std::vector<P>, std::greater<P>> Q;
	std::fill(d, d + V, INF);
	d[s] = 0;
	Q.push(P(0, s));
	while (!Q.empty()){
		P p = Q.top(); Q.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;
				Q.push(P(d[e.to], e.to));
			}
		}
	}
}

P solve(){
	int min = INF, minv;
	for (int i = 0; i < V; ++i){
		int sum = 0;
		dijkstra(i);
		for (int j = 0; j < V; ++j){
			if (d[j] == INF)
				break;
			else{
				sum += d[j];
			}
		}
		if (min > sum)
			min = sum; minv = i;
	}
	return P(minv, min);
}

int main(){
	while (1){
		std::cin >> E;
		if (E == 0)
			break;
		int f, t, c;
		for (int i = 0; i < E; ++i){
			std::cin >> f >> t >> c;
			G[f].push_back(edge(t, c));
			G[t].push_back(edge(f, c));
			if (V < t)
				V = t;
		}
		std::cout << solve().first<<' '<< solve().second << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 10;
const int M = 10;
const int INF = 0x3f3f3f3f;
int d[N][N];
int n;
/*void input()
{
    for (int i = 0; i < N; i ++)
        fill(d[i], d[i]+N, INF);
    int m;
    cin >> m;
    n = 0;
    while ( m-- ) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        d[a][b] = d[b][a] = c;
        n = max(max(n, a+1), b+1);
    }
}*/
void solve()
{
    for (int k = 0; k < n; k ++) {
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < n; j ++) {
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }

    int sum, msum = INF;
    int id = 0;
    for (int i = 0; i < n; i ++) {
        sum = 0;
        for (int j = 0; j < n; j ++) {
            if (i == j) continue;
            sum += d[i][j];
        }
        if (sum < msum) {
            msum = sum;
            id = i;
        }
    }
    printf("%d %d\n", id, msum);
}
int main(void)
{
    int m;
    while ( cin >> m && m ) {
        for (int i = 0; i < N; i ++)
            fill(d[i], d[i]+N, INF);
        n = 0;
        while ( m-- ) {
            int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
            d[a][b] = d[b][a] = c;
            n = max(max(n, a+1), b+1);
        }
        solve();
    }
    re

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

const int TOWN = 10;
const int INF = 1000000000;

using namespace std;

int main() {
	int n;
	int a, b;

	while (cin >> n , n) {

		int d[TOWN][TOWN];
		for (int i = 0; i < TOWN; i++) {
			for (int j = 0; j < TOWN; j++) {
				if (i == j)			d[i][j] = 0;
				else				d[i][j] = INF;
			}
		}

		int num_of_town = 0;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			cin >> d[a][b];
			d[b][a] = d[a][b];
			num_of_town = max(num_of_town, max(a, b));
		}
		num_of_town++;
		//	cout << "num_of_town = " << num_of_town << "\n";



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

		//cout << "\n";
		//for (int i = 0; i < num_of_town; i++) {
		//	for (int j = 0; j < num_of_town; j++) {
		//		cout << i << " " << j << " " <<  d[i][j] << "\n";
		//	}
		//}
		//cout << "\n";

		int ans_d = INF;
		int ans_t;
		int tmp = 0;
		for (int i = 0; i < num_of_town; i++) {
			for (int j = 0; j < num_of_town; j++) {
				tmp += d[i][j];
			}
			if (ans_d > tmp) {
				ans_d = tmp;
				ans_t = i;
			}
			tmp = 0;
		}
		cout << ans_t << " " << ans_d << "\n";
	}
	
 	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <queue>
#define INF 0x3f3f3f
using namespace std;
struct edge
{
    int from,to,cost;
};
int V[100],E[100],dis[100][100],N;
edge edges[100];
void floyd()
{
    int i,j,k;
    for(k=0;k<N;k++)
        for(i=0;i<N;i++)
            for(j=0;j<N;j++)
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
int main()
{
    int n,i,j,k,a,b,c,ans,big;
    while(scanf("%d",&n)&&n)
    {
        ans=0;
        N=0;
        for(k=0;k<100;k++)
            for(i=0;i<100;i++)
                {
                    dis[k][i]=INF;
                    if(k==i)
                        dis[k][i]=0;
                }
        for(i=0;i<n;i++)
        {
            scanf("%d %d %d",&a,&b,&c);
            dis[a][b]=c;
            dis[b][a]=c;
            N=max(N,a);
            N=max(N,b);
        }
        N++;
        floyd();
        int x[100]={0};
        for(i=0;i<N;i++)
        {
            for(j=0;j<N;j++)
                x[i]+=dis[i][j];
        }
        int pos = min_element(x,x+N)-x;
        cout<<pos<<" "<<x[pos]<<endl;
    }

    return 0;
}