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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 10;
unsigned N, dist[MAXN][MAXN];
int mark[MAXN];

int main() {
    //freopen("0189.txt", "r", stdin);
    while (~scanf("%d", &N) && N) {
        memset(mark, 0, sizeof(mark));
        memset(dist, 0x7f, sizeof(dist));

        for (int i = 0; i < N; i++) {
            int u, v, d;
            scanf("%d%d%d", &u, &v, &d);
            dist[u][v] = dist[v][u] = d;
            dist[u][u] = dist[v][v] = 0;
            mark[u] = mark[v] = 1;
        }
        for (int k = 0; k < MAXN; k++) if (mark[k]) {
            for (int u = 0; u < MAXN; u++) if (mark[u]) {
                for (int v = 0; v < MAXN; v++) if (mark[v]) {
                    if (dist[u][v] > dist[u][k] + dist[k][v]) {
                        dist[u][v] = dist[u][k] + dist[k][v];
                    }
                }
            }
        }

        int start_pos = 0;
        int distance = 0x7f7f7f7f;
        for (int s = 0; s < MAXN; s++) if (mark[s]) {
            int tmp = 0;
            for (int e = 0; e < MAXN; e++) if (mark[e]) {
                tmp += dist[s][e];
            }
            if (tmp < distance) {
                start_pos = s;
                distance = tmp;
            }
        }
        printf("%d %d\n", start_pos, distance);
    }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 100000
using namespace std;

int main(){
	//int town[11][11];
	int to,from,cost;
	int n;
	while(1){
		cin>>n;
		if(!n)break;
		int maxsize=0;
		int dt[11][11];
		for(int i=0;i<11;i++){
			for(int j=0;j<11;j++){
				//town[i][j]=INF;
				if(i!=j)dt[i][j]=INF;
				else dt[i][j]=0;
				//out<<"yeah "<<i<<" "<<j<<endl;
			}
		}
		for(int i=0;i<n;i++){
			cin>>to>>from>>cost;
			//cout<<"analize"<<endl;
			dt[to][from]=cost;
			dt[from][to]=cost;
			maxsize=max(maxsize,to);
			maxsize=max(maxsize,from);
		}
		for(int k=0;k<maxsize+1;k++){
			for(int i=0;i<maxsize+1;i++){
				for(int j=0;j<maxsize+1;j++){
					dt[i][j]=min(dt[i][j],dt[i][k]+dt[k][j]);
				}
			}
		}
		int sum[maxsize+1];
		rep(i,maxsize+1){
			sum[i]=0;
			rep(j,maxsize+1){
				sum[i]+=dt[i][j];
			}
			//cout<<sum[i]<<" ";
		}
		int ans[maxsize];
		rep(i,maxsize+1)ans[i]=sum[i];
		sort(sum,sum+maxsize+1);
		//cout<<sum[0]<<endl;
		for(int i=0;i<maxsize+1;i++){
			if(ans[i]==sum[0]){
				cout<<i<<" "<<sum[0];
			}
		}
		cout<<endl;
		//cout<<"finish"<<endl;
	}
	return 0;
}

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

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

		int m = 0;     //How many towns are there?

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

		int d[10][10];
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				d[i][j]=T[i][j];
			}
		}
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(d[i][j]>d[i][k]+d[k][j]){
						d[i][j]=d[i][k]+d[k][j];
					}
				}
			}
		} 

		int dis=INF,name=-1,tmp;
		for(int i=0;i<m;i++){
			tmp = 0;
			for(int j=0;j<m;j++){
				tmp += d[i][j];
			}
			if(dis>tmp){
				dis=tmp;
				name=i;
			}
		}
		cout << name << " " << dis << endl;


	}

	return 0;
}

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

using namespace std;


int main(){

    long long n;
    vector< vector<long long> > map(100,vector<long long>(100));
    long long a,b,c;
    vector<long long> v(100);
    fill(v.begin(),v.end(),1<<20);
    while(true){
	fill(map.begin(),map.end(),v);
	cin >> n;
	long long ma=0;
	if(n == 0) break;
	for(long long i=0;i<n;i++){
	    cin >> a >> b >> c;
	    map[a][b] = c;
	    map[b][a] = c;
	    ma = max(ma,b);
	}
	for(long long i=0;i<ma;i++){
	    map[i][i] = 0;
	}
	ma++;
	for(long long i=0;i<ma;i++){
	    for(long long j=0;j<ma;j++){
		for(long long k=0;k<ma;k++){
			map[i][j] = min(map[i][j] ,map[i][k] + map[k][j] );
		}
	    }
	}
	

	long long res = 1<<30,t=0;
	for(long long i=0;i<ma;i++){
	    a =0;
	    for(long long j=0;j<ma;j++){
		a += map[i][j];
	    }
	    if(a!=0 && res>a){
		res = a;
		t = i;
	    }
	}
	cout << t<<" " << res << 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 << std::endl;

    return 0;
}