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++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

typedef struct edge {
	int from;
	int to;
	int time;
} edge;


int main(){
	int n;


	while (cin >> n && n != 0) {
		int min_ = INT_MAX;
		int min_num = 1;
		vector<edge> town;
		int cost[50][50];
		int max_ = 0;

		for (int i = 0; i < 50; i++) {
			for (int j = 0; j < 50; j++) {
				cost[i][j] = INT_MAX / 10;
			}
		}
		for (int i = 0; i < 50; i++) {
			cost[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			edge tmp;
			cin >> tmp.from >> tmp.to >> tmp.time;
			cost[tmp.from][tmp.to] = tmp.time;
			cost[tmp.to][tmp.from] = tmp.time;
			max_ = max(max(tmp.from, tmp.to), max_);
		}
		max_++;
		for (int i = 0; i < max_; i++) {
			for (int j = 0; j < max_; j++) {
				for (int k = 0; k < max_; k++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		for (int i = 0; i < max_; i++) {
			int total = 0;
			for (int j = 0; j < max_; j++) {
				total += cost[i][j];
			}
			if (total < min_) {
				min_ = total;
				min_num = i;
			}
		}
		cout << min_num << " " << min_ << endl;
  }
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>

#define SIZE 100
#define INF 10000000

typedef struct {
  int data;
  int pos;
} DAT;


using namespace std;

int main(){

  DAT ans;
  int i,j,k;
  int a,b,c;
  int n;
  int time[SIZE][SIZE];

  while(1){

    int sum[SIZE]={0};
    cin>>n;

  for(i=0;i<n+1;i++){
    for(j=0;j<n+1;j++){
      if(i==j){
	time[i][j]=0;
      } else {
	time[i][j]=INF;
      }
    }
  }

  int max=0;
    for(i=0;i<n;i++){
      cin>>a>>b>>c;
      time[a][b]=c;
      time[b][a]=c;
      if(max<a)max=a;
      if(max<b)max=b;
    }

    for(i=0;i<max+1;i++){
      for(j=0;j<max+1;j++){
	for(k=0;k<max+1;k++){
	  time[j][k]=min(time[j][k],time[j][i]+time[i][k]);
	}
      }
    }

    for(i=0;i<max+1;i++){
      for(j=0;j<max+1;j++){
	sum[i]+=time[i][j];
      }
    }

    ans.data=INF;
    ans.pos=-1;
    for(i=0;i<max+1;i++){
      if(sum[i]<ans.data){
	ans.data=sum[i];
	ans.pos=i;
      }
    }

    printf("%d %d\n",ans.pos,ans.data);

  }
  
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

// to avoid error on mingw
string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int M = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}


const int MAX_N = 11;
int d[MAX_N][MAX_N];

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(8);
    ios_base::sync_with_stdio(false);

    int n;
    while(cin >> n, n) {
        rep(i,MAX_N) {
            fill(d[i], d[i] + MAX_N, INF);
            d[i][i] = 0;
        }

        rep(i,n) {
            int a, b, c;
            cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
        }

        rep(i, MAX_N) {
            rep(j, MAX_N) {
                rep(k, MAX_N) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }

//        rep(i,5) {
//            rep(j,5) {
//                cerr << d[i][j]<< " ";
//            }
//            cerr << endl;
//        }

        pair<ll, int> res = mp(INF, 1);
        rep(i,MAX_N) {
            ll total = 0;
            rep(j,MAX_N)
                if(d[i][j] == INF)
                    break;
                else
                    total += d[i][j];
            if(total != 0 && total < res.first)
                res = mp(total, i);
        }

        cout << res.second << " " << res.first << endl;
    }


    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<map>
#define int long long
using namespace std;

signed main() {
	int a;
	while (cin >> a, a) {
		vector<vector<int>>b(a);
		int n = 0;
		for (int c = 0; c < a; c++) {
			vector<int>d(3);
			cin >> d[0] >> d[1] >> d[2];
			if (d[1] > n)n = d[1];
			if (d[0] > n)n = d[0];
			b[c] = d;
		}
		n++;
		vector<vector<int>>miti(n, vector<int>(n, 1000000));
		for (int e = 0; e < a; e++) {
			miti[b[e][0]][b[e][1]] = miti[b[e][1]][b[e][0]] = b[e][2];
		}
		for (int f = 0; f < n; f++) {
			for (int g = 0; g < n; g++) {
				for (int h = 0; h < n; h++) {
					if (g == h)miti[g][h] = 0;
					else miti[g][h] = (miti[g][h]<miti[g][f]+miti[f][h]) ? (miti[g][h]) :( miti[g][f] + miti[f][h]);
				}
			}
		}
		map<int, int>l;
		for (int i = 0; i < n; i++) {
			int s = 0;
			for (int j = 0; j <n; j++) {
				s += miti[i][j];
			}
			l[s];
			l[s] = i;
		}
		auto t = l.begin();
		cout << t->second << " " << t->first << endl;
	}
}