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 <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define INF   (1e9+7)
#define MAX_V (10)
#define MAX_E (45)
#define MAX_C (100)

int V, E;
int D[MAX_V][MAX_V];

void warshall_floyd() {
  for (size_t u = 0; u < V; u++)
    for (size_t v = 0; v < V; v++)
      for (size_t w = 0; w < V; w++) D[u][v] = min(D[u][v], D[u][w] + D[w][v]);
}

void solve() {
  int ans_c, ans_d = INF;

  warshall_floyd();

  for (size_t v = 0; v < V; v++) {
    int cost = 0;
    for (size_t u = 0; u < V; u++) cost += D[u][v];
    if (cost < ans_d) {
      ans_c = v;
      ans_d = cost;
    }
  }

  printf("%d %d\n", ans_c, ans_d);
}

int main() {
  while (true) {
    scanf("%d", &E);
    if (E == 0) break;

    for (size_t u = 0; u < MAX_V; u++)
      for (size_t v = 0; v < MAX_V; v++) D[u][v] = (u == v)? 0: INF;

    V = 0;
    for (size_t i = 0; i < E; i++) {
      int v, u, cost;
      scanf("%d %d %d", &v, &u, &cost);
      D[u][v] = cost; D[v][u] = cost;
      V = max(V, (max(u, v)));
    }
    V++;

    solve();
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
const int inf = 999999999;
int main(){
	int n,a,b,c;
	while(cin >> n, n) {
		int cost[10][10] = {}, ans[10][10] = {};
		rep(i,10) {
			rep(j,10) {
				if(i==j)continue;
				cost[i][j] = inf;
				ans[i][j] = inf;
			}
		}
		int max = 0;
		rep(i,n) {
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			if(max < a) max = a;
			if(max < b) max = b;
		}

		rep(i,max+1) {
			rep(j,max+1) {
				rep(k,max+1) {
					int len = cost[i][j] + cost[j][k];
					if(len < ans[i][k]) {
						ans[i][k] = len;
					}
				}
			}
		}
		int min = inf, rmin = -1;
		rep(i,max+1) {
			int ret = 0;
			rep(j,max+1) {
				ret += ans[i][j];
			}
			if(min > ret) {
				min = ret;
				rmin = i;
			}
		}
		cout << rmin << " " << min << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
#include <unordered_map> //???????????\??¢??°

using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
//#define TEST //*******************************************************************************************************************************************

//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
#ifdef TEST
    #define dout cout
#else
    stringstream dummy; //???????????°??????dout?????????????????????????????????
    #define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
    //???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif


#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << (A) << " "
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl









////////////////////////////////////////
//AIZU
//Convenient Location
//
//??????????????????
//
//
////////////////////////////////////////

const int INF = 1e9-1;

int main(void) {
    
    int N = 10; //????????°????????§??§???10
    int M; //?????°
    int a, b, c;
    
    int d[N][N]; //0~9??????????????????
    int sumTotalCost[N]; //sumTotalCost[i] = i????????§?????????????????????????????????????????¢?????????????????????????????????????°???????ans??¨??????
    
    
    while(1) {
        cin >> M;
        if( M== 0 ) break;
        
        //initialization
        rep(i,0,N) {
            rep(j,0,N) {
                d[i][j] = (i==j ? 0 : INF);
            }
        }
        
        rep(i,0,N) {
            sumTotalCost[i] = 0;
        }
        
        
        rep(i,0,M) {
            cin >> a >> b >> c; //??????a??????b?????§????????????t
            
            d[a][b] = d[b][a] = c;
        }
        
        //test display
        rep(i,0,N) {
            disP(i);
            dispAll(d[i], N);
        }
        dout << endl;
        
        //Warshall Floyd Algorithm
        rep(i,0,N) {
            rep(j,0,N) {
                rep(k,0,N) {
                    d[i][j] = min( d[i][j], d[i][k] + d[k][j] );
                }
            }
        }
        
        //test display
        rep(i,0,N) {
            disP(i);
            dispAll(d[i], N);
        }
        dout << endl;
        
        
        //??????????????????????????????????????????????±???????
        rep(i,0,N) {
            rep(j,0,N) {
                sumTotalCost[i] += ( d[i][j]==INF ? 0 : d[i][j] ); //INF???????????????INF??\????????°???????¶?????????????
            }
        }
        
        //test display
        dispAll(sumTotalCost, N);
        dout << endl;
        
        
        //????????????????????????????°???¨?????????????±???????
        int ans = INF;
        int ans_Origin = 0;
        rep(i,0,N) {
            if( ans > sumTotalCost[i] && sumTotalCost[i] != 0 ) { //???????????¨????????????i???sumTotal???0????????§???0?????????????????????
                ans = sumTotalCost[i];
                ans_Origin = i;
            }
        }
        
        disp(ans_Origin);
        dout << "??????????????¨??????????????????????????????????°???¨???????????????????????????????????????\n";
        disp(ans);
        dout << "??¨?????????\n";
        
        cout << ans_Origin << " " << ans << endl;
        
    }
    
    return 0;
}