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++: /*
 * AOJ 0189: Convenient Location
 * ?¢???????????????°??????????????????????????????????????¶??´??±?´?????±???°????????°????????¶??´??????????°??????????
 * ?±????????????????
 * ???????????¨Floyd?±???°???????????´????????????????????????????°??????????
 */

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

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

bool vis[10];

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

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 ans = INF;
      int T;
      for(int i=0; i<m; i++){
        int sum = 0;
        for(int j=0; j<m; j++){
          sum += t[i][j];
        }
        if(sum<ans){
          ans = sum;
          T=i;
        }
      }
        cout << T << ' ' << ans << endl;
    }
    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(k, MAX_N) {
            rep(i, MAX_N) {
                rep(j, 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 <algorithm>
using namespace std;

const int INF = 1 << 28;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int m = 0;
    vector<vector<int> > dp(10, vector<int>(10, INF));
    for (int i = 0; i < n; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      dp[a][b] = dp[b][a] = c;
      dp[i][i] = 0;
      m = max(m, max(a, b));
    }
    ++m;

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

    int index = 0, sum = INF;
    for (int i = 0; i < m; ++i) {
      int tmp = 0;
      for (int j = 0; j < m; ++j)
	tmp += dp[i][j];

      if (sum > tmp) {
	sum = tmp;
	index = i;
      }
    }

    cout << index << " " << sum << endl;
  }
  return 0;
}