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;

int main() {
  const int V = 10;
  const int INF = 1<<28;
  int n;
  while(cin >> n && n) {
    int v = 0;
    int g[V][V];
    for(int i = 0; i < V; ++i) {
      for(int j = 0; j < V; ++j) {
        g[i][j] = i == j ? 0 : INF;
      }
    }
    for(int i = 0; i < n; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      v = max(v,max(a,b)+1);
      g[a][b] = g[b][a] = min(g[b][a], c);
    }

    for(int k = 0; k < v; ++k) {
      for(int i = 0; i < v; ++i) {
        for(int j = 0; j < v; ++j) {
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        }
      }
    }
    int minv = -1;
    int mini = INF;
    for(int i = 0; i < v; ++i) {
      int sum = 0;
      for(int j = 0; j < v; ++j) {
        sum += g[i][j];
      }
      if(mini > sum) {
        mini = sum;
        minv = i;
      }
    }
    cout << minv << " " << mini << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////
const int MAX_V = 10 , MAX_M = 45;
vector<vector<ll>> dp(MAX_V,vector<ll>(MAX_V,INF));
//d[[i][j]:i,j間の最短経路
int E,V=0; //頂点数

void wf(){
	rep(k,0,V)
		rep(i,0,V)
			rep(j,0,V)
				dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j] );
}

//入力
void make(){
	rep(i,0,E){
		int u,v,c;
		cin>>u>>v>>c;
		dp[u][v] = c;
		dp[v][u] = c;
		V = max(V,u+1);
		V = max(V,v+1);
	}
}

int main(){
	while( cin >> E ){
		if( !E )
			break;

		rep(i,0,MAX_V){
			rep(j,0,MAX_V){
				if( i == j ) dp[i][j] = 0;
				else dp[i][j] = INF;
			}
		}

		V = 0;
		make();
		wf();

		ll ans = INF;
		int idx = 0;
		rep(i,0,V){
			ll sum = 0;
			rep(j,0,V){
				if( dp[i][j] != INF)
					sum += dp[i][j];
			}
			if( ans > sum ){
				ans = sum;
				idx = i;
			}
		}
		cout << idx << " " << ans << endl;
	}
	ret 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>
#include <limits>

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;
}

/*
6
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
0
*/

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1e+9;

int main(){
	int n;
	while( cin >> n , n ){
		int d[11][11], v=0, s[11]={0};
		
		for(int i=0 ; i < 11 ; i++ ){
			for(int j=0 ; j < 11 ; j++ ){
				d[i][j] = (i==j)? 0 : INF;
			}
		}
		for(int i=0 ; i < n ; i++ ){
			int a,b,c;
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
			v = max( max( v , a ) , b );
		}

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

		int ans = INF;
		for(int i=0 ; i <= v ; i++ ){
			int cost = 0;
			for(int j=0 ; j <= v ; j++ ){
				cost += d[i][j];
			}
			s[i] = cost;
			ans = min( ans , cost );
		}
		for(int i=0 ; i <= v ; i++ ){
			if( s[i] == ans ){
				cout << i << " " << ans << endl;
				break;
			}
		}
	}
}

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

#define INF 1000000

using namespace std;

int main(void){
	int n;
	while(cin >> n && n){
		int f[10][10];
		fill((int*)f, (int*)f+n*n, INF);
		int s,t,cost;
		int maxi=0;
		for(int i=0;i<n;i++){
			cin >> s >> t >> cost;
			maxi = max(max(maxi,s),t);
			f[s][t] = cost;
			f[t][s] = cost;
		}
		for(int i=0;i<maxi;i++) f[i][i] = 0;
		//WF
		for(int k=0;k<=maxi;k++){
			for(int i=0;i<=maxi;i++){
				for(int j=0;j<=maxi;j++){
					f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
				}
			}
		}
		int tmp,index;
		int ret = INF;
		for(int i=0;i<=maxi;i++){
			tmp = 0;
			for(int j=0;j<=maxi;j++){
				tmp += f[i][j];
			}
			if(tmp < ret){
				ret = tmp;
				index = i;
			}
		}
		cout << index << " " << ret << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>
#define INF 11111111
using namespace std;

int main(){

  int a[100][100],ans,d,p;
  int n,m,t,u;

  while(cin >> n, n){
    
    for(int i=0;i<100;i++){
      for(int j=0;j<100;j++) a[i][j] = INF;
    }

    for(int i=0;i<n;i++){
      cin >> t >> u >> m;
      a[t][u] = a[u][t] = m;
    }

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

    ans = INF;

    for(int i=0;i<=10;i++){
      d = 0;

      for(int j=0;j<=10;j++){
	if(a[i][j] < INF && i != j) d += a[i][j];
      }

      if(ans > d && d){
	ans = d;
	p = i;
      }
    }

    cout << p << " " << ans << endl;
  }
}