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 <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                             it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

const int NO = 1000000000;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        vector<pair<pair<int,int>,int> > R;
        int m=0;
        rep(i,n){
            int a,b,c;
            cin >> a >> b >> c;
            m = max(m,max(a,b));
            R.push_back(mp(mp(a,b),c));
        }
        m++;
        vector<vector<int> > V(m,vector<int>(m,NO));

        rep(i,m){
            V[i][i] = 0;
        }

        rep(i,n){
            int a = R[i].first.first;
            int b = R[i].first.second;
            int c = R[i].second;
            V[a][b] = V[b][a] = c;
        }


        cerr << __LINE__ << endl;

        for(int k=0;k<m;k++){
            for(int i=0;i<m;i++){
                for(int j=0;j<m;j++){
                    V[i][j] = min(V[i][j],V[i][k]+V[k][j]);
                }
            }
        }

        int ret = -1;
        int mi = NO;

        for(int i=0;i<m;i++){
            int s = 0;
            for(int j=0;j<m;j++){
                s += V[i][j];
            }
            if(mi > s){
                mi = s;
                ret = i;
            }
        }
        cout << ret << " " << mi << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define all(n) n.begin(),n.end()
#define mp make_pair
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,1,-1,-1,0};
const int dy[]={0,0,1,-1,1,-1,1,-1,0};

int cost[11][11];
struct Edge{int to,from,cost;};

vector<Edge> edge;
vector<int> town;

int main() {
	int n;
	while(n=in()){
		edge.clear();
		town.clear();
		rep(i,n){
			Edge e;
			cin>>e.from>>e.to>>e.cost;
			edge.push_back(e);
			swap(e.from,e.to);
			edge.push_back(e);
		}
		rep(i,edge.size()){
			int j;
			rep0(j,town.size())if(town[j]==edge[i].from)break;
			if(j==town.size())town.push_back(edge[i].from);
		}
		rep(j,edge.size()){
			rep(i,town.size()){
				if(edge[j].from==town[i]){
					edge[j].from=i;
					break;
				}
			}
			rep(i,town.size()){
				if(edge[j].to==town[i]){
					edge[j].to=i;
					break;
				}
			}
		}
		rep(i,town.size())rep(j,town.size())cost[i][j]=INF/3;
		rep(i,town.size())cost[i][i]=0;
		rep(i,edge.size())cost[edge[i].from][edge[i].to]=edge[i].cost;
		rep(k,town.size())rep(i,town.size())rep(j,town.size()){
			chmin(cost[i][j],cost[i][k]+cost[k][j]);
		}
		int res=INF/3,rest;
		rep(i,town.size()){
			int r=0;
			rep(j,town.size()){
				r+=cost[i][j];
			}
			if(res>r){
				res=r;
				rest=i;
			}
		}
		cout<<town[rest]<<" "<<res<<endl;
	}
	return 0;
}

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

using namespace std;

#define INF 1000000000LL

long long edges[20][20];
long long dist[20][20];

int ids[20];
int nids;

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N==0)break;

        memset(edges,0,sizeof(edges));
        memset(dist,0,sizeof(dist));
        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(ids[l]==y) iy = l;
            }

            if(ix<0){ ix = nids; ids[nids++]=x; }
            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])
                    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  = -1;
        long long msum = 0;

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

            long long sum = 0;
            for(int j=0;j<nids;++j) sum += dist[i][j];

            if(ans<0 || sum<msum){
                ans  = i;
                msum = sum;
            }

        }

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


    }

    return 0;

}