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 <algorithm>

using namespace std;

const int MAX = 101;
const int INF = 1<<28;
 
int main()
{
    int n,cost[MAX][MAX],a,b,c;
    while (cin >> n, n) {
	fill(cost[0], cost[MAX], INF);
 
	int M = 0;
	for (int i = 0; i < n; i++) {
	    cin >> a >> b >> c;
	    cost[a][b] = cost[b][a] = c;
	    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++) {
		    cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
		}
	    }
	}
	int ans = INF, sum, num;
	for (int i = 0; i < M; i++) {
	    sum = 0;
	    for (int j = 0; j < M; j++) {
		if (i == j) continue;
		sum += cost[i][j];
	    }
	    if (sum < ans) {
		ans = sum;
		num = i;
	    }
	}
	cout << num << ' ' << ans << endl;
    }
    return 0;
}

C++: //
//  main.cpp
//

#include <iostream>
//#include <algorithm>
#include <vector>
//#include <limits>
#include <math.h>
//#include <queue>
//#include <tuple>
//#include <stdio.h>
//#include <stdlib.h>
//#include <string>
//#include "string.h"
//#include <unordered_map>
#include <unordered_set>
//#include <array>
#include <set>

using namespace std;

using ll = long long;

int main() {
    while (true) {
        int N;
        cin >> N;
        if (N == 0) {
            return 0;
        }
        set<int> cities;
        vector<vector<int>> dists(10, vector<int>(10, 100000));
        for (int i = 0; i < 10; i++) {
            dists[i][i] = 0;
        }
        for (int i = 0; i < N; i++) {
            int ai, bi, ci;
            cin >> ai >> bi >> ci;
            dists[ai][bi] = ci;
            dists[bi][ai] = ci;
            cities.insert(ai);
            cities.insert(bi);
        }
        for (int k = 0; k < 10; k++) {
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    dists[i][j] = min(dists[i][j], dists[i][k]+dists[k][j]);
                }
            }
        }
        int minCity = -1;
        int minSum = numeric_limits<int>::max();
        for (int cityA : cities) {
            int sum = 0;
            for (int cityB : cities) {
                sum += dists[cityA][cityB];
            }
            if (sum < minSum) {
                minCity = cityA;
                minSum = sum;
            }
        }
        printf("%d %d\n", minCity, minSum);
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXC 12
int N,dis[MAXC][MAXC];
int main()
{
	int m;
	while(~scanf("%d",&N)&&N)
	{
		memset(dis,0x3F,sizeof dis);
		for(int i=1;i<MAXC;i++)
			dis[i][i]=0;
		m=0;
		for(int i=1,a,b,c;i<=N;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			m=max(m,max(a,b));
			dis[a][b]=min(dis[a][b],c);
			dis[b][a]=min(dis[b][a],c);
		}
		for(int k=0;k<=m;k++)
			for(int i=0;i<=m;i++)
				for(int j=0;j<=m;j++)
					dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
		int mn=0x7FFFFFFF,id,sum;
		for(int i=0;i<=m;i++)
		{
				sum=0;
				for(int j=0;j<=m;j++)
					sum+=dis[i][j];
				if(mn>sum)
				{mn=sum;id=i;}
		}
		printf("%d %d\n",id,mn);
	}
	return 0;
}

C++: #include <iostream>

#define MAX 10
#define INF 2000000
using namespace std;

int d[MAX][MAX];
int n, num_ver = 0;
int min_t = INF;
int min_ver;

void init();
void input();
void wf();

int main(){

  while(cin >> n, n){
    init();
    input();  
    wf();
    
   
    for(int i = 0; i <= num_ver; i++){
      int tmp = 0;
      for(int j = 0; j <= num_ver; j++){
	tmp += (i<j)? d[i][j] : d[j][i];
      }
      if(min_t > tmp) {min_t = tmp; min_ver = i;}
    }
    cout << min_ver << " " << min_t << endl;
  }
}

void init(){
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      d[i][j] = (i==j)? 0: INF;
    }
  }
}

void input(){
  for(int i = 0; i < n; i++){
    int a, b, c;
    cin >> a >> b >> c;
    d[a][b] = c;
    if(num_ver < b) num_ver = b;
  }
}

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

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};
static const int INF = 1e9+7;

int main() {
  int n;
  while(cin >> n, n) {
    vector<vector<int>> dist(11, vector<int> (11, INF));
    int v = 0;
    int a, b, c;

    rep(i, 0, n) {
      cin >> a >> b >> c;
      dist[a][b] = c;
      dist[b][a] = c;
      dist[a][a] = 0;
      dist[b][b] = 0;
      v = max(v, a+1);
      v = max(v, b+1);
    }

    rep(i, 0, v) {
      dist[i][i] = 0;
    }

    rep(k, 0, v) {
      rep(i, 0, v) {
        rep(j, 0, v) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }

    int cost = INF;
    int town;
    rep(i, 0, v) {
      int c = 0;
      rep(j, 0, v) {
        c += dist[i][j];
      }

      if (c < cost) {
        cost = c;
        town = i;
      }
    }

    cout << town << ' ' << cost << endl;
  }

  return 0;
};