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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename M>
void warshallFloyd(M &m, const int &n) {
  rep(k, n) rep(i, n) rep(j, n) cmin(m[i][j], m[i][k] + m[k][j]);
}

void solve() {
  int n;
  while (cin >> n, n) {
    vvi t(10, vi(10));
    rep(i, 10) rep(j, 10) t[i][j] = i == j ? 0 : INF;
    set<int> s;
    rep(i, n) {
      int a, b, c;
      cin >> a >> b >> c;
      s.insert(a), s.insert(b);
      t[a][b] = t[b][a] = c;
    }
    vi v(s.size());
    copy(all(s), v.begin());
    warshallFloyd(t, 10);
    int ms = INF, mp;
    rep(i, 10) {
      int s = 0;
      for (int j : v) s += t[i][j];
      if (cmin(ms, s)) mp = i;
    }
    cout << mp << ' ' << ms << endl;
  }
}

C++: #include <iostream>

// int inf = 1 << 28;
int inf = 1000000000;

int dijk(int n,int s, int **g) {
	int sum = 0;
	bool *used = new bool[n];
	int *d = new int[n];

	// std::cout << "n = " << n << " " << "s = " << s << std::endl;

	for(int j=0;j<n;j++){
		for(int i=0;i<n;i++){
			std::cout << g[j][i] << ",";
		}
		std::cout << std::endl;
	}

	for(int i = 0; i < n; i++)
		d[i] = inf;
	d[s] = 0;

	while(true) {
		int u = -1;
		for(int v = 0; v < n; v++)
			if(!used[v] && (u == -1 || d[v] < d[u]))
				u = v;

		// std::cout << "u = " << u << std::endl;

		if(u == -1) break;
		used[u] = true;

		for(int v = 0; v < n; v++)
			if(d[v] > d[u] + g[u][v])
				d[v] = d[u] + g[u][v];
	}

	for(int i = 0; i < n; i++) {
		sum += d[i];
	}

	// for(int i = 0; i < n; i++) {
	// std::cout << d[i] << std::endl;
	// }

	return sum;
}

int main() {
	do {
		int **g; // adjacency matrix, ?
		int *d;
		int *a, *b, *c;
		int edge = 0, min = 0, max = 0;
		int tmp = 0;

		std::cin >> edge;
		if(!edge) break;

		a = new int[edge];
		b = new int[edge];
		c = new int[edge];

		for(int i = 0;i < edge;i++) {
			std::cin >> a[i];
			std::cin >> b[i];
			std::cin >> c[i];
		}

		for(int i = 0; i < edge; i++) {
			if(max < a[i])
				max = a[i];
		}
		for(int i = 0; i < edge; i++) {
			if(max < b[i])
				max = b[i];
		}
		max++;

		g = new int*[max];
		d = new int[max];

		for(int i = 0; i < max; i++) {
			g[i] = new int[max];
		}

		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				g[i][j] = inf;

		for(int i = 0; i < edge; i++)
			g[b[i]][a[i]] = g[a[i]][b[i]] = c[i];

		for(int i=0;i<max;i++){
			g[i][i]=0;
		}

		
		for(int k=0;k<max;k++){
			for(int j=0;j<max;j++){
				for(int i=0;i<max;i++){
					if(g[i][k]+g[k][j]<g[i][j]){
						g[i][j]=g[i][k]+g[k][j];
					}
				}
			}
		}
		

		for(int i = 0; i < max; i++)
			;//d[i] = dijk(max, i, g);

		for(int i = 0; i < max; i++){
			d[i]=0;
			for(int j=0;j<max;j++){
				d[i] += g[i][j];
			}
		}

		min = d[0];
		for(int i = 1; i < max; i++) {
			if(min > d[i]) {
				min = d[i];
				tmp = i;
			}
		}

		std::cout << tmp << " " << min << std::endl;
		for(int i = 0; i < max; i++)
			delete[] g[i];
		delete[] g;
		delete[] a;
		delete[] b;
		delete[] c;
		delete[] d;

	}while(true);
	return 0;
}

C++: #include <iostream>
using namespace std;

#define rep(i, n) for(int i = 0;i < (int)n;i++)

const int INF = 100001;

int d[100][100];

int main() {
    while(true) {
        int n;
        cin >> n;
        if(!n) break;

        rep(i, 10) {
            rep(j, 10) {
                d[i][j] = (i != j ? INF : 0);
            }
        }

        int m = 0;

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

        m++;

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

        int ansd = 10000000, ansi;
        rep(i, m) {
            int sum = 0;
            rep(j, m) {
                sum += d[i][j];
            }
            if(sum < ansd) {
                ansd = sum;
                ansi = i;
            }
        }
        cout << ansi << ' ' << ansd << endl;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;

const int MAX_TOWN = 10;
const int INF = 1000000;

int dist[MAX_TOWN][MAX_TOWN];

void minify() {
  for (int k = 0; k < 10; k++)
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int sum_of_dist(int t) {
  int sum = 0;
  for (int i = 0; i < 10; i++)
    sum += (dist[t][i] == INF)? 0:dist[t][i];

  return (sum == 0)? INF:sum;
}

int main() {
  int n;
  while (cin >> n and n != 0) {
    int a, b, c;

    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = (i == j)? 0:INF;

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

    minify();

    int min_dist = INF, min_town = 0;
    for (int t = 0; t < 10; t++) {
      if (min_dist > sum_of_dist(t)) {
        min_town = t;
        min_dist = sum_of_dist(t);
      } 
    }

    cout << min_town << " " << min_dist << endl;
  }
}