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 rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << x << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

const int INF = 10000000;

int main()
{
    int n;
    while (n = in()){
        int town[16][16];
        rep(i, 16) rep(j, 16) town[i][j] = INF;
        rep(i, 16) town[i][i] = 0;
        int maxi = 0;
        rep(i, n){
            int f, t, c;
            f = in();
            t = in();
            c = in();
            maxi = max(maxi, f);
            maxi = max(maxi, t);
            town[t][f] = town[f][t] = c;
        }
        n = maxi + 1;
        rep(k, n) rep(i, n) rep(j, n) town[i][j] = min(town[i][j], town[i][k] + town[k][j]);
        vector<pair<int, int> > costs;
        rep(i, n){
            int cost = 0;
            rep(j, n){
                cost += town[i][j];
            }
            costs.push_back(make_pair(cost, i));
        }
        sort(costs.begin(), costs.end());
        printf("%d %d\n", costs[0].second, costs[0].first);
    }
    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 = sum+T[i][j];
		  }
		  if(sum<ans){
		    ans = sum;
		    t=i;
		  }
		}
		cout << t << ' ' << ans << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>

using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;

//int main() {
//	int n,c,v;
//	array<array<pii, 50>, 50> graph = {};
//	scanf("%d %d %d", &n, &c, &v);
//	vector<pii> roads(v, {0,0});
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		roads[i].first = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		roads[i].second = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		graph[roads[i].first][roads[i].second].first = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		graph[roads[i].first][roads[i].second].second = s;
//	}
//
//	array<int> 
//
//	return 0;
//}

int main() {
	int n;
	while (scanf("%d", &n)) {
		if (!n)
			return 0;
		array<array<int, 11>, 11> graph = {};
		int m = 0;
		for (int i = 0; n > i; i++) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);

			graph[a][b] = c;
			graph[b][a] = c;
			m = max(m, max(a, b));
		}
		m++;
		pii Min = { INT_MAX,INT_MAX };
		for (int i = 0; m > i; i++) {
			priority_queue<pii, vector<pii>, greater<pii>> que;
			vector<int> al(m, -1);
			for (int j = 0; m > j; j++) {
				if (graph[i][j]) {
					que.push({ graph[i][j], j });
				}
			}
			al[i] = 0;
			while (!que.empty()) {
				pii num = que.top();
				que.pop();
				if (al[num.second] != -1)
					continue;
				al[num.second] = num.first;
				for (int j = 0; m > j; j++) {
					if (graph[num.second][j] && al[j] == -1) {
						que.push({ num.first + graph[num.second][j], j });
					}
				}
			}
			Min = min(Min, { accumulate(al.begin(), al.end(),0),i });
		}
		printf("%d %d\n", Min.second, Min.first);
	}
	return 0;
}

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

using namespace std;

#define MAX 11
#define INF (1<<29)

int main(){
  int n,a,b,c;

  while(cin >> n ,n){
    int G[MAX][MAX],m = 0;
    fill(G[0],G[MAX],INF);
    
    for(int i = 0 ; i < MAX ; i++){
      G[i][i] = 0;
    }
    for(int i = 0 ; i < n ; i++){
      cin >> a >> b >> c;
      G[a][b] = G[b][a] = c;
      m = max(m,max(a,b));
    }
  

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

    int min_ = INF,num;
    for(int i = 0 ; i <= m ; i++){
      int sum = 0;
      for(int j = 0 ; j <= m ; j++){
	sum += G[i][j];
      }
      if(min_ > sum){
	min_ = sum;
	num = i;
      }
    }
    cout << num << " " << min_ << endl;
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x>y?y:x)
#define INF 1000000
typedef long long ll;

ll cost[15][15];

int main()
{
	int n,max,num;
	ll sum,min;
	
	while(cin>>n,n){
		num=0;
		min=INF;
		max=0;
		
		for(int i=0;i<15;i++){
			for(int j=0;j<15;j++){
				cost[i][j]=(i==j?0:INF);
			}
		}
		
		for(int i=0;i<n;++i){
			int a,b;
			ll c;
			cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
			if(max<MAX(a,b))max=MAX(a,b);

		}
		
		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]);
				}
			}
		}
		
		for(int i=0;i<=max;i++){
			sum=0;
			for(int j=0;j<=max;j++){
				sum+=cost[i][j];
			}
			if(min>sum){
				min=sum;
				num=i;
			}	
		}
		cout<<num<<" "<<min<<endl;
	}
	return 0;
}