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++: //C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

using namespace std;

typedef long long ll;
typedef pair<int,int> P;



int d[10][10];
int V=10;
int INF=10000;
//d[i][i]==0;no path==INF;
void warshall_floyd(){
    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 main(){
    while(1){
        int n;
        cin>>n;
        if(n==0) break;
        rp(i,0,10){
            rp(j,0,10) {
                d[i][j]=INF;
                if(i==j) d[i][j]=0;
            }
        }
        rp(i,0,n) {
            int x,y,z;
            cin>>x>>y>>z;
            d[x][y]=z;
            d[y][x]=z;
        }
        warshall_floyd();
        int sum=0,ans=-1,pos=-1;
        rp(i,0,10){
            sum=0;
            rp(j,0,10){
                //cout<<d[i][j]<<" ";
                if(i==j) continue;
                if(d[i][j]!=INF) sum+=d[i][j];
            }
            //cout<<sum<<endl;
            if(ans==-1) {ans=sum;pos=i;}
            else if(sum!=0 and sum<ans){ans=sum;pos=i;}
        }
        cout<<pos<<" "<<ans<<endl;


    }
    return 0;
};

C++: #include <iostream>
#include <algorithm>
#define MAX 10
#define INF 9999999

using namespace std;

int v[MAX + 1];
int road[MAX + 1][MAX + 1];
bool visit[MAX + 1];
int n,mn,MN,Max;

int dij(int now){

  fill( v , v + MAX + 1 , INF );
  fill( visit , visit + MAX + 1 , false );
  v[now] = 0;
  
  while(1){
    
    MN = INF;
    for( int i = 0 ; i <= Max ; i++ ){
      if( !visit[i] && v[i] < MN ){
	MN = v[i];
	mn = i;
      }
    }
    if( MN == INF ) break;
    visit[mn] = true; 
    
    for( int i = 0 ; i <= Max ; i++ ){
      int t = road[mn][i] + v[mn];
      v[i] = min( v[i] , t );
    }
  }
  
  int total = 0;
  for(int i = 0 ; i <= Max ; i++) 
    total += v[i]; 
  
  return total;
}

int main(void){

  while( cin >> n , n ){

    for(int i = 0 ; i <= MAX ; i++)
      for(int j = 0 ; j <= MAX ; j++)
	road[i][j] = INF;

    int a,b,c; 
    Max = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> a >> b >> c;
      road[a][b] = c;
      road[b][a] = c;
      Max = max( Max , max(a,b) );
    } 
    
    int ans = INF;
    int ansnum;
    for(int i = 0 ; i < Max ; i++){
      int ANS = dij(i);
      if( ans > ANS ){ 
	ans = ANS;
	ansnum = i;
      }
    }
    cout << ansnum << " " << ans << endl;
    }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

int chmax(int& a,int b){
	if(b > a){
		a=b;
	}
	return a;
}
int chmin(int& a,int b){
	if(b < a){
		a=b;
	}
	return a;
}
int dp[11][11]={inf};

int main(){
	int n;
	while(cin >> n,n){
		int mc=0;
		rep(i,11){
			rep(j,11){
				dp[i][j]=inf;
			}
		}
		rep(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			chmax(mc,max(a,b));
			dp[a][b]=c;
			dp[b][a]=c;
		}
		mc++;
		rep(i,mc){
			rep(j,mc){
				rep(k,mc){
					dp[j][k]=min(dp[j][k],dp[i][j]+dp[i][k]);
				}
			}
		}
		int id;int ans=inf;
		rep(i,mc){
			int tmp=0;
			rep(j,mc){
				if(i==j)continue;
				tmp+=dp[i][j];
			}
			if(ans > tmp){
				id=i;
				ans=tmp;
			}
		}
		printf("%d %d\n",id,ans);
	}
	return 0;
}

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

using namespace std;

const int inf=999999;

int m[50][50];

int n;

void floyd(int n)
{
    for(int k=0;k<n;++k)
        for(int i=0;i<n;++i)
            for(int j=0;j<n;++j)
                if(i!=j && i!=k && j!=k)
                    if(m[i][k]+m[k][j]<m[i][j])
                        m[i][j]=m[i][k]+m[k][j];
}
int main()
{
    while(cin>>n)
    {
        if(n==0) break;
        for(int i=0;i<=45;i++)
        {
            for(int j=0;j<=45;j++)
            {
                m[i][j]=inf;
                if(i==j) m[i][j]=0;
            }
        }
        int a,b,w,maxn=0;
        for(int i=0;i<n;i++)
        {
            cin>>a>>b>>w;
            m[a][b]=w;
            m[b][a]=w;
            maxn=max(a,maxn);
            maxn=max(b,maxn);
        }
        maxn++;
        floyd(maxn);

        int ans=inf,ansn=0,temp=0;
        for(int i=0;i<=maxn;i++)
        {
            temp=0;
            for(int j=0;j<=maxn;j++)
            {
                if(m[i][j]!=inf) temp+=m[i][j];
            }
            if(temp<ans)
            {
                ans=temp;
                ansn=i;
            }
        }
		cout<<ansn<<' '<<ans<<endl;
    }
    return 0;
}