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 <string>
#include <queue>
#include <vector>
#include <functional>
#include <utility>
#include <algorithm>
#include <iomanip>

using Pair = std::pair<int, int>;
constexpr int infl = 1e+9;

int n;
int cost[11][11];

bool func() {
    std::fill(cost[0], cost[0] + sizeof(cost) / sizeof(int), infl);
    
    std::cin >> n;
    
    if(n == 0)
        return false;
    
    int from, to, c;
    int tMax = 0;
    for(int i = 0; i < n; ++i) {
        std::cin >> from >> to >> c;
        
        cost[from][to] = c;
        cost[to][from] = c;
        cost[to][to] = 0;
        cost[from][from] = 0;
        
        tMax = std::max({tMax, to, from});
    }
    ++tMax;
    
    for(int i = 0; i < tMax; ++i)
        for(int j = 0; j < tMax; ++j)
            for(int k = 0; k < tMax; ++k) {
                cost[j][k] = std::min(cost[j][k], cost[j][i] + cost[i][k]);
            }
    
    int costMin = infl, idx = 0;
    for(int i = 0; i < tMax; ++i) {
        int sum = 0;
        
        for(int j = 0; j < tMax; ++j) {
            sum += cost[i][j];
        }
        
        if(costMin > sum) {
            idx = i;
            costMin = sum;
        }
    }
    
    std::cout << idx << " " << costMin << std::endl;
    
    return true;
}

int main() {
    while(func());
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <climits> 
#include <map>
using namespace std;

const int MAX_V = 1000; // ???????????°????????§???
const int INF = 1000000; // ???????????§?????????(int ???????????§???)
int v; // ????????°
int g[MAX_V][MAX_V]; // ??£??\??????
int d[MAX_V]; // ??????s ????????????????????¢
bool used[MAX_V]; // ?????§??????????????¢????¢??????????????????¨???????????°

void dijkstra(int s)
{
  // ??????
  fill(d, d + v, INF);
  fill(used, used + v, false);
  d[s] = 0;
  // ??????s ????????????????????????????????¢????¨????
  for(;;){
    // ???????¢???????????????????????????????????????¢???????°???????????????¢???
    // ?????????????????¢???????????????????????¢????¢??????????
    int i = -1;
    for(int j = 0; j < v; ++j)
      if(!used[j] && (i == -1 || d[i] > d[j]))
	i = j;
    if(i == -1)break; // ??¨??????????????????????????¢????¢????????????´???
    // ?????????????????¢???????????????????????¢?¢????
    used[i] = true;
    // ???????????¢????¢?????????????????????£??\????????????????????±?????´??°
    for(int j = 0; j < v; ++j)
      d[j] = min(d[j], d[i] + g[i][j]);
  }
}

int main()
{
  for(;;){
    int gv, ge;
    cin >> ge;
    if(ge==0){return 0;}
    set<int> s;

    fill(&g[0][0], &g[MAX_V][0], 100000);
    //for(int i=0;i<5;i++){for(int j=0;j<5;j++){cout << g[i][j] << " ";}cout << endl;}


    for(int i = 0; i < ge; ++i){
      int gs, gt, gd;
      cin >> gs >> gt >> gd;
      g[gs][gt]=gd;
      g[gt][gs]=gd;
      s.insert(gs);
      s.insert(gt);
    }

    gv=s.size();
    v = gv;

    vector<pair<int,int> > p(s.size());
    set<int>::iterator it= s.begin();



    int count=0;
    while(it!=s.end()){
      dijkstra(*it);
      //for(int i=0;i<v;i++)cout << d[i] << endl;

      int sum=0;
      for(int i=0;i<v;i++){sum+=d[i];}
      //cout << sum << ":" << *it << endl;
      p[count].first=sum;
      p[count].second=*it;
      it++;
      count++;
    }

    sort(p.begin(),p.end());
  
    //for(int i=0;i<p.size();i++)
    cout << p[0].second << " " << p[0].first << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1ll << 60;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

#ifdef WIN32
#define dump(x) cout << #x << " = " << (x) << "\n"
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n"
#else
#define dump(x)
#define debug(x)
#endif

struct edge {
	int to;
	int cost;
	edge( int t, int c ) {
		to = t;
		cost = c;
	}
};
int n;
int r[ 10 ][ 10 ];
vector<edge> e[ 10 ];

void dijkstra( int s ) {
	fill( r[ s ], r[ s ] + 10, INF );
	priority_queue< PII, vector<PII>, greater<PII> > que;
	que.push( PII( s, 0 ) );
	while ( que.size() ) {
		int to = que.top().first;
		int cost = que.top().second;
		que.pop();
		if ( r[ s ][ to ] < cost ) {
			continue;
		}
		r[ s ][ to ] = cost;
		for ( int i = 0; i < e[ to ].size(); i++ ) {
			if ( r[ s ][ e[ to ][ i ].to ] > cost + e[ to ][ i ].cost ) {
				r[ s ][ e[ to ][ i ].to ] = r[ e[ to ][ i ].to ][ s ] = cost + e[ to ][ i ].cost;
				que.push( PII( e[ to ][ i ].to, cost + e[ to ][ i ].cost ) );
			}
		}
	}
}

int main() {
#ifdef WIN32
	printf( "Debug Mode\n" );
#endif
	while ( ~scanf( "%d", &n ) && n ) {
		for ( int i = 0; i < 10; i++ ) {
			e[ i ].clear();
		}
		int m = 0;
		for ( int i = 0; i < n; i++ ) {
			int s, g, c;
			m = max( max( s, g ), m );
			dump( m );
			scanf( "%d %d %d", &s, &g, &c );
			e[ s ].push_back( edge( g, c ) );
			e[ g ].push_back( edge( s, c ) );
		}
		int ans_cost = INF;
		int ans_t = 0;
		for ( int i = 0; i <= m; i++ ) {
			dijkstra( i );
		}
		for ( int i = 0; i <= m; i++ ) {
			int cost = 0;
			for ( int j = 0; j <= m; j++ ) {
				cost += r[ i ][ j ];
			}
			if ( ans_cost > cost ) {
				ans_cost = cost;
				ans_t = i;
			}
		}
		printf( "%d %d\n", ans_t, ans_cost );
	}
	return 0;
}