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++: /*
 * @Author: your name
 * @Date: 2020-08-03 05:04:45
 * @LastEditTime: 2020-08-03 05:45:31
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /ACM_Introduction/2020.8.2/aoj0189.cpp
 */
#include <iostream>
#include <cstring>
using namespace std;

const int maxn = 15;
int d[maxn][maxn];
int n, a, b, c, len;
#define INF 0x3f3f3f3f
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
void floyd() {
    for(int k = 0; k <= len; ++k)
        for(int i = 0; i <= len; ++i)
            for(int j = 0; j <= len; ++j)
                d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
}

int main() {
    while(scanf("%d", &n), n) {
        int ans = INF, pos = -1, sum = 0;
        memset(d, INF, sizeof(d));
        for(int i = 0; i < maxn; ++i) 
            d[i][i] = 0;
        len = -1;
        for(int i = 0; i < n; ++i) {
            scanf("%d%d%d", &a, &b, &c);
            len = max(max(a, b), len);
            d[a][b] = d[b][a] = c;
        }
        // printf("%d", len);
        floyd();
        for(int i = 0; i <= len; ++i) {
            sum = 0;
            for(int j = 0; j <= len; j++) 
                sum += d[i][j];
            if(ans > sum) {
                ans = sum;
                pos = i;
            }
        }
        printf("%d %d\n", pos, ans);
    }
    return 0;
}

C++: #include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
using namespace std;
const int INF=100000000;

int main(){
  int n;
  while(cin>>n,n!=0){
    int dp[100][100];
    rep(i,n){
      rep(j,n){
	dp[i][j]=i==j?0:INF;
      }
    }
    int k[100]={};
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      dp[a][b]=c;
      dp[b][a]=c;
      k[a]++;
      k[b]++;
    }
    int city=0;
    rep(i,11){
      if(k[i]>0){
	city++;
      }
    }
    rep(k,city){
      rep(i,city){
	rep(j,city){
	  dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
	}
      }
    }
    
    int minsum=INF,num;
    rep(i,city){
      int sum=0;
      rep(j,city){
	sum+=dp[i][j];
      }
      if(minsum>sum){
	minsum=sum;
	num=i;
      }	
    }
    cout<<num<<" "<<minsum<<endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                             it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

const int NO = 1000000000;
int main(){
    while(true){
        // miti kazu
        int n;
        cin >> n;
        if(n eq 0) break;
        // miti
        vector<vector<int> > R(10,vector<int>(10,NO));
        // distance
        vector<vector<int> > D(10,vector<int>(10,NO));

        int m = -1;
        for(int i=0;i<n;i++){
            int a,b,c;
            cin >> a >> b >> c;
            R[a][b] = R[b][a] = c;
            m = max(m,max(a,b));
        }

        for(int i=0;i<10;i++){
            R[i][i] = 0;
            D[i][i] = 0;
        }

        m++;
        for(int i=0;i<m;i++){
            for(int j=i+1;j<m;j++){

                // distance where
                priority_queue<pair<int,int> , vector<pair<int,int> > , greater<pair<int,int> > > Q;
                Q.push(mp(0,i));

                while(!Q.empty()){
                    int dis = Q.top().first;
                    int where = Q.top().second;
                    Q.pop();

                    if(where eq j){
                        D[i][j] = D[j][i] = dis;
                        break;
                    }
                    for(int k=0;k<10;k++){
                        if(where == k) continue;
                        if(R[where][k] not_eq NO){
                            Q.push(mp(R[where][k] + dis,k));
                        }
                    }
                }
            }
        }


        int index_i = -1;
        int sum = NO;
        for(int i=0;i<m;i++){
            int s = 0;
            for(int j = 0;j<m;j++){
                s += D[i][j];
            }
            if(sum > s){
                sum = s;
                index_i = i;
            }
        }

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

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

using namespace std;
#define INF 100000

int  road, max_t = 0, time_[100][100] = { 0 }, sum, root[100] = { 0 };

void dijkstra(int a) {

	int i,j,k=INF,used[10],minroot;
	for (i = 0; i <= max_t; i++) {
		used[i] = 0;
		root[i] = INF;
	}
	root[a] = 0;
	while (1) {
		minroot = INF;
		for (i = 0; i <= max_t; i++) {
			if (used[i] == 0&&root[i]<minroot) {
				j = i;
				minroot = root[i];
			}
			
		}
		if (k == j) {
			break;
		}
		else {
			k = j;
		}
		used[j] = 1;
		for (i = 0; i <= max_t; i++) {
			if (root[i] > root[j] + time_[j][i]) {
				root[i] = root[j] + time_[j][i];
			}

		}
	}
	sum = 0;
	for (i = 0; i <= max_t; i++)sum += root[i];

	return ;
}






int main() {
	cin >> road;

	if (road == 0) return 0;
	int i, j, a, b, c, save_a[450] = { 0 }, save_b[450] = { 0 }, save_c[450] = { 0 }, min_sum = INF, ans_town;

	for (i = 1; i <= road; i++) {
		cin >> a >> b >> c;
		if (max_t < a) max_t = a;
		if (max_t < b) max_t = b;
		save_a[i] = a;
		save_b[i] = b;
		save_c[i] = c;
	}
	for (i = 0; i <= max_t; i++) {
		for (j = 0; j <= max_t; j++) {
			time_[i][j] = INF;
		}
		time_[i][i] = 0;
	}
	for (i = 1; i <= road; i++) {
		time_[save_a[i]][save_b[i]] = save_c[i];
		time_[save_b[i]][save_a[i]] = save_c[i];
	}
	for (i = 0; i <= max_t; i++) {
		dijkstra(i);
		if (sum < min_sum) {
			ans_town = i;
			min_sum = sum;
		}
	}
	cout << ans_town << " " << min_sum << endl;

	return 0;
}