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 "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N;
    while (cin >> N, N) {

        auto cost = make_v(INF, 15, 15);

        for (size_t i = 0; i < 15; ++i) {
            cost[i][i] = 0;
        }

        size_t maxnode = 0;
        for (size_t i = 0; i < N; ++i) {
            size_t a, b, c; cin >> a >> b >> c;
            cost[a][b] = cost[b][a] = c;
            chmax(maxnode, max(a, b));
        }

        for (size_t node = 0; node <= maxnode; ++node) {
            for (size_t s = 0; s <= maxnode; ++s) {
                for (size_t g = 0; g <= maxnode; ++g) {
                    chmin(cost[s][g], cost[s][node] + cost[node][g]);
                }
            }
        }

        pair<size_t, size_t> minv = {INF, INF};
        for (size_t s = 0; s <= maxnode; ++s) {
            size_t sum = 0;
            for (size_t node = 0; node <= maxnode; ++node) {
                if (s == node) continue;
                if (cost[s][node] != INF) {
                    sum += cost[s][node];
                }
            }
            chmin(minv, make_pair(sum, s));
        }

        cout << minv.second << " " << minv.first << "\n";
    }

    return 0;
}

C++: #include<cstdio>
using namespace std;
static const int MAX_V = 10;
static const int MAX_E = 45;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX_V][MAX_V];

int dijkstra(int s){
	int mincost;
	int d[MAX_V], color[MAX_V];

	for(int i = 0; i < MAX_V; i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[s] = 0;
	color[s] = GRAY;
	while(true){
		int u;
		mincost = INFTY;
		for(int i = 0; i < MAX_V; i++){
			if(mincost > d[i] && color[i] != BLACK){
				u = i;
				mincost = d[i];
			}
		}

		if(mincost == INFTY) break;

		color[u] = BLACK;

		for(int v = 0; v < MAX_V; v++){
			if(color[v] != BLACK && M[u][v] != INFTY){
				if(d[v] > d[u] + M[u][v]){
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}
	int sum_d = 0;
	for(int i = 0; i < MAX_V; i++){
		if(d[i] != INFTY){
			sum_d += d[i];
		}
	}
	return sum_d;
}

int main(void){
	while(true){
		scanf("%d", &n);
		if(n == 0) break;

		for(int i = 0; i < MAX_V; i++){
			for(int j = 0; j < MAX_V; j++){
				M[i][j] = INFTY;
			}
		}

		for(int i = 1; i <= n; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			M[a][b] = M[b][a] = c;
		}

		int min_v, min_d = INFTY;
		for(int i = 0; i < MAX_V; i++){
			int dist = dijkstra(i);
			//printf("%d %d\n", i, dist);
			if(dist < min_d && dist != 0){
				min_d = dist;
				min_v = i;
			}
		}

		printf("%d %d\n", min_v, min_d);
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
const int INF = 1e+9;

int main(void){
	int n;
	while(cin>>n,n){
		int g[11][11],v=0;
		for(int i=0;i<11;++i)for(int j=0;j<11;++j) g[i][j]=INF;
		for(int i=0,a,b,c;i<n;++i){
			cin>>a>>b>>c;
			g[a][b]=c;
			g[b][a]=c;
			v = (((a>b)?a:b)>v)?((a>b)?a:b):v;
		}
		int sum_min=INF,d_sum[11]={0};
		for(int i=0;i<=v;++i){
			int d[11];
			for(int j=0;j<=v;++j) d[j]=INF;
			d[i]=0;
			bool f=false;
			for(;;){
				f=false;
				for(int j=0;j<=v;++j){//from
					for(int k=0;k<=v;++k){//to
						if(d[j] != INF && d[k] > d[j] + g[j][k]){
							f = true;
							d[k] = d[j] + g[j][k];
						}
					}
				}
				if(!f) break;
			}
			for(int j=0;j<=v;++j) d_sum[i]+=d[j];
			if(sum_min>d_sum[i]) sum_min = d_sum[i];
		}
		for(int i=0;i<=v;++i){
			if(sum_min==d_sum[i]){
				cout<<i<<" "<<sum_min<<endl;
				break;
			}
		}
	}
}