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 <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>
 
using namespace std;
 
int main(){
 
    int n,a,b,time,distance[10][10],min_value,min_index;
    int D[10],P[10],tmp_min,tmp_min_index,tmp_sum,count,max_number;
 
    while(true){
        scanf("%d",&n);
        if(n == 0)break;
 
        for(int i = 0; i < 10; i++){
            for(int k = 0; k < 10; k++)distance[i][k] = 2000000000;
        }
 
        max_number = -1;
        for(int i = 0; i < n; i++){
            scanf("%d %d %d",&a,&b,&time);
            distance[a][b] = time;
            distance[b][a] = time;
            max_number = max(max_number,max(a,b));
        }
 
        min_value = 2000000000;
 
        for(int town = 0; town <= max_number; town++){
            for(int i = 0; i <= max_number; i++){
                P[i] = 0;
                D[i] = 2000000000;
            }
 
            for(int i = 0; i <= max_number; i++){
                if(distance[town][i] >= 0){
                    D[i] = distance[town][i];
                }
            }
 
            count = 1;
            P[town] = 1;
            D[town] = 0;
 
            while(count <= max_number){
                tmp_min = 2000000000;
                for(int i = 0; i <= max_number; i++){
                    if(D[i] >= 0 && P[i] == 0 && D[i] < tmp_min){
                        tmp_min = D[i];
                        tmp_min_index = i;
                    }
                }
 
                if(tmp_min == 2000000000)break;
 
                P[tmp_min_index] = 1;
                count++;
 
                for(int k = 0; k <= max_number; k++){
                    if(D[k] > D[tmp_min_index] + distance[tmp_min_index][k]){
                        D[k] = D[tmp_min_index] + distance[tmp_min_index][k];
                    }
                }
            }
 
            tmp_sum = 0;
 
            for(int i = 0; i <= max_number; i++){
                tmp_sum += D[i];
            }
 
            if(tmp_sum < min_value){
                min_value = tmp_sum;
                min_index = town;
            }else if(tmp_sum == min_value && town < min_index){
                min_index = town;
            }
        }
 
        printf("%d %d\n",min_index,min_value);
 
    }
 
    return 0;
}

C++: #ifndef VS
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<math.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {
	cww() { CIN_ONLY{ ios::sync_with_stdio(false); cin.tie(0); } }
}star;
#define DEBUG if(0)
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r) { bool a = l>r; if (a)l = r; return a; }
template <typename T>inline bool chmax(T &l, T r) { bool a = l<r; if (a)l = r; return a; }
typedef vector<LL> V;
typedef vector<V> VV;
const LL INF = 1e14;
typedef pair<LL, int> P;
int main() {
	int m;
	while (cin >> m, m) {
		VV d(10, V(10, INF));
		REP(i, 10)d[i][i] = 0;
		V e(10, 0);
		REP(i, m) {
			int a, b;LL c;
			cin >> a >> b >> c;
			chmin(d[a][b], c);
			chmin(d[b][a], c);
			e[a] = e[b] = 1;
		}
		REP(k, 10)REP(i, 10)REP(j, 10)chmin(d[i][j], d[i][k] + d[k][j]);
		P ret(INF, 0);
		REP(i, 10)if (e[i]) {
			P ans(0,i);
			REP(j, 10)if (e[j])ans.first += d[i][j];
			chmin(ret, ans);
		}
		cout << ret.second << " " << ret.first << endl;
	}
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

#define INF 100000000

int edges[100][100];
int dist[100][100];

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N == 0) break;

        memset(edges,0,sizeof(edges));

        int ids[20];
        int nids = 0;

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            int ix=-1;
            int iy=-1;

            for(int l=0;l<nids;++l)
                if(ids[l]==x) ix = l;

            if(ix<0){ ix = nids; ids[nids++]=x; }

            for(int l=0;l<nids;++l)
                if(ids[l]==y) iy = l;

            if(iy<0){ iy = nids; ids[nids++]=y; }

            edges[ix][iy] = edges[iy][ix] = c;

        }

        for(int i=0;i<nids;++i){
            for(int j=0;j<nids;++j){
                if(i==j)
                    dist[i][j] = 0;
                else if(edges[i][j]>0)
                    dist[i][j] = edges[i][j];
                else
                    dist[i][j] = INF;
            }
        }

        for(int k=0;k<nids;++k)
            for(int i=0;i<nids;++i)
                for(int j=0;j<nids;++j)
                    dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);

        int ans  = 0;
        int msum = INF;

        for(int i=0;i<nids;++i){

            int sum = 0;
            for(int j=0;j<nids;++j){
               if(dist[i][j]==INF)continue;
               sum += dist[i][j];
            }

            if(sum<=msum){

                if(sum==msum){

                    if(ids[i]<=ids[ans])
                        ans = i;

                } else {

                    ans = i;

                }

                msum = sum;

            }

        }

        cout << ids[ans] << " " << msum << endl;

    }

    return 0;

}

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

const int MAXN = 11;
const int MAXR = 50;
const int INF = 0x3f3f3f3f;

int d[MAXN][MAXN];
int n, V;

void Floyd() {
	for (int k = 0; k < V; ++k) {
		for (int i = 0; i < V; ++i) {
			for (int j = 0; j < V; ++j) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}
void solve() {
	Floyd();
	int resSum = INF, resId = -1;
	for (int i = 0; i < V; ++i) {
		long long cur = 0;
		for (int j = 0; j < V; ++j) {
			cur += d[i][j];
		}
		if (cur < resSum) {
			resSum = cur;
			resId = i;
		}
	}
	printf("%d %d\n", resId, resSum);
}
int main(int argc, char const *argv[])
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	while (scanf("%d", &n) && n != 0) {
		for (int i = 0; i < MAXN; ++i) {
			fill(d[i], d[i] + MAXN, INF);
			d[i][i] = 0;
		}
		V = 0;
		for (int i = 0; i < n; ++i) {
			int u, v, w;
			scanf("%d%d%d", &u, &v, &w);
			V = max(V, max(u, v) + 1);
			d[u][v] = w;
			d[v][u] = w;
		}
		solve();
	}
	//system("pause");
	return 0;
}