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>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 100000000;
using namespace std;

void warshallFloyd(int m[50][50], int n){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
            }
        }
    }
}

int main(){
    int n;
    while(cin >> n, n){
        map<int, int> t;
        int m[50][50];
        int ans[2];
        ans[1] = INF;

        rep(i,50) rep(j,50) m[i][j] = INF;
        rep(i,50) m[i][i] = 0;
        rep(i,n){
            int a, b , c;
            cin >> a >> b >> c;
            m[a][b] = m[b][a] = c;
            t[a] = 1;
            t[b] = 1;
        }

        warshallFloyd(m, n);

        for(auto i = t.begin(); i != t.end(); i++){
            int sum = 0;
            for(auto j = t.begin(); j != t.end(); j++){
                sum+=m[i->first][j->first];
                //show(sum)
            }
            if(sum < ans[1]){
                ans[0] = i->first;
                ans[1] = sum;
            }
        }
        cout << ans[0] << ' ' << ans[1] << endl;
    }
}

C++: #include <iostream>
#include <string>
#define MAX 10
#define INF 1 << 29
using namespace std;

int cost[MAX][MAX];

void warshall_floyd() {
	for (int k = 0; k < MAX; k++) {
		for (int i = 0; i < MAX; i++) {
			for (int j = 0; j < MAX; j++) {
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
}

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		for (int i = 0; i < MAX; i++) {
			for (int j = 0; j < MAX; j++) {
				if (i == j) cost[i][j] = 0;
				else cost[i][j] = INF;
			}
		}
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
		}
		warshall_floyd();
		int ans = INF;
		int town = -1;
		for (int i = 0; i < MAX; i++) {
			int res = 0;
			for (int j = 0; j < MAX; j++) {
				if (cost[i][j] == INF) continue;
				res += cost[i][j];
			}
			if (res > 0) {
				if (res < ans) {
					ans = res;
					town = i;
				}
			}
		}
		cout << town << ' ' << ans << endl;
	}
}

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;		// ????????°

		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;
			}
		}

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

		int cnt=INF; int town=0;
		for(int i=0; i<m; i++){
			int tmp=0;
			for(int j=0; j<m; j++){
				tmp=tmp+T[i][j];
			}
			if(tmp<=cnt){
				cnt=tmp;
				town=i;
			}
		}

		cout << town << ' ' << cnt<<endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back

ll cost[10][10];
ll n,m;


void wf(){
  rep(k,m){
    rep(i,m){
      rep(j,m)cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
    }
  }
}

main(){
  while(cin>>n,n){
    m=0;
    rep(i,10){
      rep(j,10){
        cost[i][j]=1<<20;
      }
      cost[i][i]=0;
    }

    rep(i,n){
      ll a,b,c;
      cin>>a>>b>>c;
      m=max(m,max(a,b));
      cost[a][b]=c;
      cost[b][a]=c;
    }
    ++m;
    wf();
    ll minan=2<<20,town;

    rep(i,m){
      ll sum=0;
      rep(j,m)sum+=cost[i][j];
      if(sum<minan){
        minan=sum;
        town=i;
      }
    }
    cout<<town<<" "<<minan<<endl;
  }
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int INF = 0x3f3f3f3f;

int d[10][10];
int m;

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


int main() {
  int i, j, a, b, c, n;
  while (scanf("%d", &n) != EOF && n) {
    memset(d, 0x3f, sizeof(d));
    m = 0;
    while (n--) {
      scanf("%d%d%d", &a, &b, &c);
      d[a][b] = d[b][a] = c;
      m = max(m, max(a + 1, b + 1));
    }
    floyd();
    int ans, p, tmp;
    p = 0;
    ans = INF;
    for (i = 0; i < m; ++i) {
      tmp = 0;
      for (j = 0; j < m; ++j) {
        if (i == j) continue;
        tmp += d[i][j];
        if (tmp >= INF) break;
      }
      if (tmp < ans) {
        ans = tmp;
        p = i;
      }
    }
    printf("%d %d\n", p, ans);
  }
  return 0;
}