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 <cstdio>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <functional>
#include <string.h>
using namespace std;
const int INF = 1000000000;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,start,end) for(int i=(start);i<(end);++i)
#define pint(i) printf("%d\n",(i))
#define pint2(i,j) printf("%d %d\n",(i),(j))
#define pint3(i,j,k) printf("%d %d %d\n",(i),(j),(k))
#define gint(i) scanf("%d",&(i))
#define gint2(i,j) scanf("%d %d",&(i),&(j))
#define gint3(i,j,k) scanf("%d %d %d",&(i),&(j),&(k))
#define init(tar,val) memset((tar),(val),sizeof((tar)))
#define show(tar,len) for(int i=0;i<(len);++i) \
	cout<<tar[i]<<' ';\
	cout<<endl;




class bignum{
public:
	bignum(int size = 4) :len(size){
	}
	~bignum(){
	}
	int size()const{
		return len;
	}
	//int get(int id)const{
	//	return num[id];
	//}
	friend ostream &operator<<(ostream &output, const bignum &b){
		bool stu = false;
		for (int i = int(b.len - 1); i >= 0; --i){
			if (stu)
				printf("%09d", b.num[i]);
			else if (b.num[i] > 0){
				printf("%d", b.num[i]);
				stu = true;
			}
		}
		if (stu == false)
			printf("0");
		return output;
	}
	const bignum& operator+=(const bignum&right){
		int add = 0;
		for (int i = 0; i < len; ++i){
			int tmp = 0;
			if (i < right.size()){
				tmp = right.num[i] + num[i] + add;
			}
			else{
				tmp = num[i] + add;
			}
			num[i] = tmp%gap;
			add = tmp / gap;
		}
		return *this;
	}
	const bignum& operator=(const bignum&right){
		for (int i = 0; i < len; ++i){
			num[i] = right.num[i];
		}
		return *this;
	}
	void set(int a){
		for (int i = 0; i < len; ++i){
			num[i] = a%gap;
			a /= gap;
		}
	}
private:
	int  num[4];
	int len;
	static const int gap = 1000000000;
};


//inline int id(int i){
//	return i & 1;
//}
//
//inline int last(int i){
//	return (i - 1) & 1;
//}
//
//void myshow(int i){
//	rep(j, 0, ){
//		cout << dp[id(i)][j] << ' ';
//	}
//	cout << endl;
//}


//#define my_debug

const int MAX_NUM = 15;

int n;
int len[MAX_NUM][MAX_NUM];
int stu[MAX_NUM];
set<int> cache;
void myinit(){
	rep(i, 0, MAX_NUM)
		rep(j, 0, MAX_NUM){
		if (i == j)
			len[i][j] = 0;
		else
			len[i][j] = INF;
	}
}


void solve(){
	rep(i, 0, MAX_NUM){
		rep(j, 0, MAX_NUM){
			rep(k, 0, MAX_NUM){
				len[i][j] = min(len[i][j], len[i][k] + len[k][j]);
			}
		}
	}
	int out = INF, t = 0;
	for (int i : cache){
		int tmp = 0;
		for (int j : cache){
			tmp += len[i][j];
		}
		if (tmp < out){
			out = tmp;
			t = i;
		}
	}
	pint2(t, out);
}

int main(){
#ifdef my_debug
	freopen("a.in", "r", stdin);
#endif
	while (gint(n) != EOF){
		if (n == 0)
			break;
		fill(stu, stu + MAX_NUM, INF);
		myinit();
		cache.clear();
		int tmp1, tmp2;
		rep(i, 0, n){
			gint2(tmp1, tmp2);
			int tmp;
			gint(tmp);
			len[tmp2][tmp1] = len[tmp1][tmp2] = tmp;
			cache.insert(tmp1);
			cache.insert(tmp2);
		}
		solve();
	}
	return 0;
}

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

int main(){
  int n;
  int a,b,c;
  int at[10][10];
  int cost,max,min,minn;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	if(i==j)at[i][j] = 0;
	else at[i][j] = -1;
      }
    }
    max = 0;
    for(int k=0;k<n;k++){
      cin >> a >> b >> c;
      if(max < a)max = a;
      if(max < b)max = b;
      for(int j=0;j<10;j++){
	if(at[j][a] >= 0){
	  if( (at[j][b] < 0) || ( at[j][a] + c < at[j][b]) ){
	    at[j][b] = c + at[j][a];
	    at[b][j] = c + at[j][a];
	  }
	}
	if(at[j][b] >= 0){
	  if( (at[j][a] < 0) || ( at[j][b] + c < at[j][a]) ){
	    at[j][a] = c + at[j][b];
	    at[a][j] = c + at[j][b];
	  }
	}
      }
    }

    min = 2000000000;
    for(int i=0;i<=max;i++){
      cost = 0;
      for(int j=0;j<=max;j++)cost += at[i][j];
      if(min > cost){
	min = cost;
	minn = i;
      }
    }
    cout << minn << " " << min << endl;
  }
}

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 v;
int g[MAX_V][MAX_V];
int d[MAX_V]; 
bool used[MAX_V]; 

void dijkstra(int s)
{
  fill(d, d + v, INF);
  fill(used, used + v, false);
  d[s] = 0;
  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++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {
		VI a(n), b(n), c(n);
		rep(i, n)cin >> a[i] >> b[i] >> c[i];
		int v = max(*max_element(all(a)), *max_element(all(b))) + 1;

		VVI d(v, VI(v, inf));
		rep(i, v)d[i][i] = 0;
		rep(i, n) { d[a[i]][b[i]] = c[i]; d[b[i]][a[i]] = c[i]; }
		rep(i, v)rep(j, v)rep(k, v)d[j][k] = min(d[j][k], d[j][i] + d[i][k]);

		int ans1 = -1, ans2 = inf;
		rep(i, v) {
			int sum = accumulate(all(d[i]), 0);
			if (ans2 > sum) { ans1 = i; ans2 = sum; }
		}
		cout << ans1 << " " << ans2 << endl;
	}
}