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>
#include <cstring>
using namespace std;
int map[110][110];
int mine[110];
int main()
{
    int a;
    while(scanf("%d",&a)&&a)
    {
        for(int i=0;i<a;i++)
    {
        for(int j=0;j<a;j++)
        {
            if(i==j)
            {
                map[i][i]=0;
            }
            else
            map[i][j]=99999;
        }
    }
    int fuck=0;
    for(int i=1;i<=a;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        map[x][y]=z;
        map[y][x]=z;
        fuck=max(fuck,max(x,y));

    }
    for(int i=0;i<=fuck;i++)
    {
        for(int j=0;j<=fuck;j++)
        {
            for(int k=0;k<=fuck;k++)
            {
                if(map[j][k]>map[j][i]+map[i][k])
                map[j][k]=map[j][i]+map[i][k];
            }
        }
    }
    int sum;
    int hh=100000;
    for(int i=0;i<=fuck;i++)
    {sum=0;
        for(int j=0;j<=fuck;j++)
        {
            sum+=map[i][j];
        }
        mine[i]=sum;
        hh=min(sum,hh);
    }


    for(int i=0;i<=fuck;i++)
    {
        if(mine[i]==hh)
        {
            cout<<i<<" "<<mine[i]<<endl;
            break;
        }
    }
    }


}

C++: #include <iostream>
#include <algorithm>
using namespace std;

const int MAX_V = 10;
const int INF = 1 << 29;
const int MAX_N = 45;

int d[MAX_V + 1][MAX_V + 1];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		
		for(int i = 0; i != MAX_V; ++i){
			for(int j = 0; j != MAX_V; ++j){
				d[i][j] = INF;
				if(i == j)
					d[i][j] = 0;
			}
		}
		
		int v = 0;
		for(int i = 0; i != n; ++i){
			int a, b, c;
			cin >> a >> b >> c;
			v = max({a + 1, b + 1, v});
			d[a][b] = c;
			d[b][a] = c;
		}
		//cout << v << endl;
		//cout << INF*2 << endl;
		
		for(int i = 0; i != v; ++i){
			for(int j = 0; j != v; ++j){
				for(int k = 0; k != v; ++k){
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
					//cout << d[i][j] << endl;
				}
			}
		}
		
		int m = INF;
		int now = 0;
		for(int i = 0; i != v; ++i){
			int sum = 0;
			for(int j = 0; j != v; ++j){
				sum += d[i][j];
			}
			if(m > sum){
				m = sum;
				now = i;
			}
			//cout << sum << endl;
		}
		
		cout << now << " " << m << endl;
	}
	return 0;
}

C++: #include<iostream>

#define TOWN_MAX 11
#define ROAD_MAX 46
#define INF 1000000000

int solve(int);

int main(int argc, char const* argv[]) {
    int n;

    while (true) {
        std::cin >> n;
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

int solve(int road_num) {
    int distances[TOWN_MAX][TOWN_MAX];
    bool used[TOWN_MAX];

    for (int i = 0; i < TOWN_MAX; i++) {
        used[i] = false;
        for (int j = 0; j < TOWN_MAX; j++)
            distances[i][j] = (i == j) ? 0 :INF;
    }

    for (int i = 0; i < road_num; i++) {
        int src, dest, cost;
        std::cin >> src >> dest >> cost;
        distances[src][dest] = cost;
        distances[dest][src] = cost;
        used[src] = used[dest] = true;
    }

    for (int infix_road = 0; infix_road < road_num; infix_road++) {
        for (int begin_town = 0; begin_town < TOWN_MAX; begin_town++) {
            for (int end_town = 0; end_town < TOWN_MAX; end_town++) {
                distances[begin_town][end_town] = std::min(distances[begin_town][end_town],
                        distances[begin_town][infix_road] + distances[infix_road][end_town]);
            }
        }
    }

    int min_cost       = INF;
    int min_cost_index = 0;
    for (int i = 0; i < TOWN_MAX; i++) {
        if (!used[i]) continue;

        int sum_cost   = 0;
        for (int j = 0; j < TOWN_MAX; j++) {
            if (!used[j]) continue;
            sum_cost += distances[i][j];
        }

        if (sum_cost < min_cost) {
            min_cost       = sum_cost;
            min_cost_index = i;
        }
    }

    std::cout << min_cost_index << " " << min_cost % INF << std::endl;

    return 0;
}

C++: #include <iostream>

// int inf = 1 << 28;
int inf = 1000000000;

int dijk(int n,int s, int **g) {
	int sum = 0;
	bool *used = new bool[n];
	int *d = new int[n];

	// std::cout << "n = " << n << " " << "s = " << s << std::endl;

	for(int j=0;j<n;j++){
		for(int i=0;i<n;i++){
			std::cout << g[j][i] << ",";
		}
		std::cout << std::endl;
	}

	for(int i = 0; i < n; i++)
		d[i] = inf;
	d[s] = 0;

	while(true) {
		int u = -1;
		for(int v = 0; v < n; v++)
			if(!used[v] && (u == -1 || d[v] < d[u]))
				u = v;

		// std::cout << "u = " << u << std::endl;

		if(u == -1) break;
		used[u] = true;

		for(int v = 0; v < n; v++)
			if(d[v] > d[u] + g[u][v])
				d[v] = d[u] + g[u][v];
	}

	for(int i = 0; i < n; i++) {
		sum += d[i];
	}

	// for(int i = 0; i < n; i++) {
	// std::cout << d[i] << std::endl;
	// }

	return sum;
}

int main() {
	do {
		int **g; // adjacency matrix, ?
		int *d;
		int *a, *b, *c;
		int edge = 0, min = 0, max = 0;
		int tmp = 0;

		std::cin >> edge;
		if(!edge) break;

		a = new int[edge];
		b = new int[edge];
		c = new int[edge];

		for(int i = 0;i < edge;i++) {
			std::cin >> a[i];
			std::cin >> b[i];
			std::cin >> c[i];
		}

		for(int i = 0; i < edge; i++) {
			if(max < a[i])
				max = a[i];
		}
		for(int i = 0; i < edge; i++) {
			if(max < b[i])
				max = b[i];
		}
		max++;

		g = new int*[max];
		d = new int[max];

		for(int i = 0; i < max; i++) {
			g[i] = new int[max];
		}

		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				g[i][j] = inf;

		for(int i = 0; i < edge; i++)
			g[b[i]][a[i]] = g[a[i]][b[i]] = c[i];

		for(int i=0;i<max;i++){
			g[i][i]=0;
		}

		for(int k=0;k<max;k++){
			for(int j=0;j<max;j++){
				for(int i=0;i<max;i++){
					if(g[i][k]+g[k][j]<g[i][j]){
						g[i][j]=g[i][k]+g[k][j];
					}
				}
			}
		}

		//for(int i = 0; i < max; i++)
		//	d[i] = dijk(max, i, g);

		for(int i = 0; i < max; i++){
			d[i]=0;
			for(int j=0;j<max;j++){
				d[i] += g[i][j];
			}
		}

		min = d[0];
		for(int i = 1; i < max; i++) {
			if(min > d[i]) {
				min = d[i];
				tmp = i;
			}
		}

		std::cout << tmp << " " << min << std::endl;
		for(int i = 0; i < max; i++)
			delete[] g[i];
		delete[] g;
		delete[] a;
		delete[] b;
		delete[] c;
		delete[] d;

	}while(true);
	return 0;
}