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>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 100;
int merg(int x,int y);
int Find(int x);
int a[N][N];
const int inf = 0x3f3f3f3f;

int main()
{
    int n;
    while(scanf("%d", &n),n!=0)
    {
        for(int i=0;i<=15;i++)
        {
            for(int j=0;j<15;j++)
            {
                if(i==j)
                {
                    a[i][j]=0;
                }
                else
                {
                    a[i][j]=inf;
                }

            }
        }
        for(int i=0;i<n;i++)
        {
            int x, y, z;
            scanf("%d %d %d", &x, &y, &z);
            a[x][y]=min(a[x][y],z);
            a[y][x]=a[x][y];
        }
        for(int i=0;i<=15;i++)
        {
            for(int j=0;j<=15;j++)
            {
                for(int k=0;k<=15;k++)
                {
                    if(a[j][k]>a[j][i]+a[i][k]&&a[i][k]!=inf&&a[j][i]!=inf)
                    {
                        a[j][k]=a[j][i]+a[i][k];
                    }
                }
            }
        }
        int sum=inf, u;
        for(int i=0;i<=15;i++)
        {
            int tmp=0;
            for(int j=0;j<=15;j++)
            {
                if(a[i][j]!=inf)
                {
                    tmp+=a[i][j];
                }
            }
            if(tmp==0)
            {
                continue;
            }
            if(tmp<sum)
            {
                sum=tmp;
                u=i;
            }
        }
        printf("%d %d\n", u, sum);
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 101;
const int INF = 1<<28;

int main(){
  int n,cost[MAX][MAX],a,b,c;
  while(cin >> n, n){
    fill(cost[0],cost[MAX],INF);

    int M = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> a >> b >> c;
      cost[a][b] = cost[b][a] = c;
      M = max(M,max(a,b));
    }
    ++M;
    for(int k = 0 ; k < M ; k++)
      for(int i = 0 ; i < M ; i++)
	for(int j = 0 ; j  < M ; j++)
	  cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);

    int ans = INF,sum,num;
    for(int i = 0 ; i < M ; i++){
      sum = 0;
      for(int j = 0 ; j < M ; j++){
	if(i == j) continue;
	sum += cost[i][j];
      }
      if(sum < ans){
	ans = sum;
	num = i;
      }
    }
    cout << num << ' ' << ans << endl;
  }

  return 0;
}

C++: #include<iostream>

#define TOWN_MAX 10
#define ROAD_MAX 45
#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]);
                distances[end_town][begin_town] = std::min(distances[end_town][begin_town],
                        distances[end_town][infix_road] + distances[infix_road][begin_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 << std::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];

    for (int i = 0; i < TOWN_MAX; i++)
        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;
    }

    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++) {
        int sum_cost = 0;
        for (int j = 0; j < TOWN_MAX; j++) {
            if (distances[i][j] < INF) sum_cost += distances[i][j];
        }

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

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

    return 0;
}