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 <vector>
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
#include <string.h>
#include <stdio.h>

typedef long long ll;
using namespace std;

typedef vector<vector<int>> graph_t;
const int INF = 1e9+1;

pair<int, int> solve(vector<tuple<int, int, int>> roads)
{
	graph_t g;
	const int N = 10;
	g.resize(N);
	for (int i = 0; i < N; i++) {
		g[i].resize(N, INF);
		g[i][i] = 0;
	}
	for (auto i = roads.begin(); i != roads.end(); ++i) {
		int s = get<0>(*i);
		int t = get<1>(*i);
		int d = get<2>(*i);
		g[s][t] = d;
		g[t][s] = d;
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++)
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		}
	}
	int ans = INF;
	int index = -1;
	for (int i = 0; i < N; i++) {
		int s = 0;
		for (int j = 0; j < N; j++) {
			if (i == j || g[i][j] >= INF)
				continue;
			s += g[i][j];
		}
		if (ans > s && s > 0) {
			ans = s;
			index = i;
		}
	}
	return make_pair(index, ans);
}

void solve_stdio()
{
	while (true) {
		int n;
		if (!(cin >> n))
			break;
		if (n == 0)
			break;
		vector<tuple<int, int, int>> roads;
		for (int i = 0; i < n; i++) {
			int s, t, d;
			cin >> s >> t >> d;
			roads.emplace_back(s, t, d);
		}
		int index;
		int ans;
		tie(index, ans) = solve(roads);
		cout << index << " " << ans << endl;
	}
}

int main()
{
	solve_stdio();
}

C++: #include<iostream>
#include<queue>
#include<cstring>

#define HOME 10
#define ROAD 45
#define MAX  100000000
using namespace std;

int dis[HOME][HOME];
bool chk[HOME];

class Datum {
public:
	int now;
	int dis;

	Datum(int n, int d) {now = n;dis = d;}
	Datum() {}
};

bool operator<( const Datum& a, const Datum& b ) {
	return a.dis < b.dis;
}

bool operator>( const Datum& a, const Datum& b ) {
	return a.dis > b.dis;
}

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

		for ( int i=0; i<HOME;i ++ ) {
			for ( int j=0; j<HOME; j++ ) {
				dis[i][j] = MAX;
			}
		}

		int find = -1;
		for ( int i=0;i<n; i++ ) {
			int from, to, distance;
			cin >> from >> to >> distance;
			
			if ( find < to )
				find = to;
			if ( find < from )
				find = from;

			dis[from][to] = distance;
			dis[to][from] = distance;

			dis[i][i] = 0;
		}

		n = find+1;

		priority_queue<Datum, vector<Datum>, greater<Datum> > flow;

		while( !flow.empty() ) {
			flow.pop();
		}

		
		for ( int i=0 ; i<n; i++ ) {

			while( !flow.empty() ) {
				flow.pop();
			}

			flow.push(Datum(i,0));
			int count = n;

			memset( chk, false, n*sizeof(bool) );

			while(!flow.empty()) {
				Datum now;
				now = flow.top();
				flow.pop();

				for ( int j=0; j<n; j++ ) {
					if ( i != j ) {
						if ( chk[j] )
							continue;

						if ( dis[now.now][j] + now.dis <= dis[i][j] ) {
							dis[i][j] = dis[now.now][j] + now.dis;
							dis[j][i] = dis[now.now][j] + now.dis;

							if ( dis[now.now][j] == MAX )
							continue;

							chk[j] = true;
							count--;
	
							flow.push(Datum(j,dis[i][j]));
							
						}
					}
				}

				if ( count == 1 ) {
					break;
				}
			}
		}



		int maxhome = -1;
		int maxdis = MAX;
		for ( int i=0; i<n; i++ ) {
			int sum = 0;
			
			for ( int j=0; j<n; j++ ) {
				sum += dis[i][j];
			}
			
			if ( maxdis > sum ) {
				maxdis = sum;
				maxhome = i;
			}
		}

		cout << maxhome << ' ' << maxdis << endl;
	}
}

C++: #include<iostream>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>

using namespace std;


int main(){

    int n;
    vector< vector<int> > map(100,vector<int>(100));
    int a,b,c;
    int ma=0;
    cin >> n;
    vector<int> v(100);
    fill(v.begin(),v.end(),1<<20);
    fill(map.begin(),map.end(),v);
    for(int i=0;i<n;i++){
	cin >> a >> b >> c;
	map[a][b] = c;
	map[b][a] = c;
	ma = max(ma,b);
    }
    for(int i=0;i<ma;i++){
	map[i][i] = 0;
    }
    ma++;
    for(int l=0;l<2;l++){
    for(int i=0;i<ma;i++){
	for(int j=0;j<ma;j++){
	    for(int k=0;k<ma;k++){
		    map[i][j] = min(map[i][j] ,map[i][k] + map[k][j] );
	    }
	}
    }
    }

    bool flag = false;
    int res = 1<<30,t;
    for(int i=0;i<ma;i++){
	a =0;
	for(int j=0;j<ma;j++){
	    a += map[i][j];
	}
	if(a!=0 && res>a){
	    res = a;
	    t = i;
	}
    }
    cout << t<<" " << res << endl;
    
    return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int INF = 1e9;
const int N = 11;

int main() {
  int M, G[N][N];
  while(cin >>M && M){
    int n = 0;
    REP(i, N) REP(j, N) G[i][j] = (i == j ? 0 : INF);
    REP(i, M){
      int f, t, c; cin >>f >>t >>c;
      n = max(n, max(f, t));
      G[f][t] = G[t][f] = min(G[t][f], c);
    }
    ++n;
    REP(k, n) REP(i, n) REP(j, n) G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
    int index = 0, sum = 0;
    REP(i, n) sum += G[0][i];
    FOR(i, 1, n){
      int _sum = 0;
      REP(j, n) _sum += G[i][j];
      if(_sum < sum){
        index = i;
        sum = _sum;
      }
    }
    cout <<index <<" " <<sum <<endl;
  }
  return 0;
}

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

#define N 10
#define INF 1000000
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)

int main() {
	int n, cost[N][N], ans = INF, num = -1, sum, m=0, a, b, c;
	while(1) {
		cin >> n;
		if(!n) break;
		for(int i=0; i<N; ++i) for(int j=0; j<N; ++j) {
			cost[i][j] = (i==j?0:INF);
		}
		for(int i=0; i<n; ++i) {
			cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
			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) {
					cost[i][j]= min(cost[i][j], cost[i][k]+cost[k][j]);
				}
			}
		}
		for(int i=0; i<=m; ++i) {
			sum = 0;
			for(int j=0; j<=m; ++j) {
				sum += cost[i][j];
			}
			if(ans>sum) {
				num = i;
				ans = sum;
			}
		}
		cout << num << " " << ans << endl;
	}
	return 0;
}