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<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
using namespace std;
const int INF=100000000;
int main(){
  int n;
  while(cin>>n,n!=0){
    int dp[100][100];
    rep(i,10){
      rep(j,10){
	dp[i][j]=i==j?0:INF;
      }
    }
    int k[100]={};
    vector<int> vec;
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      dp[a][b]=c;
      dp[b][a]=c;
      k[a]++;
      k[b]++;
    }
    int city=0;
    rep(i,11){
      if(k[i]>0){
	city++;
	vec.push_back(i);
      }
    }
    rep(k,10){
      rep(i,10){
	rep(j,10){
	  dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
	}
      }
    }
    int minsum=INF,num;
    rep(i,vec.size()){
      int sum=0;
      rep(j,vec.size()){
	sum+=dp[vec[i]][vec[j]];
      }
      if(minsum>sum){
	minsum=sum;
	num=vec[i];
      }    
    }
    cout<<num<<" "<<minsum<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;


struct edge {
	int to, cost;
	edge(int _to, int _cost) :to(_to), cost(_cost){};
};

vector<edge> G[100];

int n, a, b, c;
int d[100];
set<int> si;
set<int>::iterator it;

void dijkstra(int s){
	fill(d, d + 100, INF);
	d[s] = 0;
	priority_queue<P> que;
	que.push(P(0, s));

	while (!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;

		if (d[v] < p.first)continue;

		for (int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	while (cin >> n&&n){
		REP(i, n){
			cin >> a >> b >> c;
			if (si.find(a) == si.end())si.insert(a);
			if (si.find(b) == si.end())si.insert(b);
			G[a].push_back(edge(b, c));
			G[b].push_back(edge(a, c));
		}
		int ans = 2147483647, index = 2147483647;
		it = si.begin();
		REP(i, si.size()){
			int sum = 0;
			dijkstra(*it + i);
			REP(i, si.size()){
				sum += d[i];
			}
			if (ans > sum){
				ans = sum;
				index = *it + i;
			}
		}
		cout << index << " " << ans << endl;
		REP(i, si.size()){
			G[*it + i].clear();
		}
		si.clear();
	}
}

C++: #include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <bitset>
#include <iostream>
using namespace std;




int main()
{   
    // freopen("in","r",stdin);
    int n;
    while(scanf("%d",&n)&&n){
        int dist[10][10];
        int a,b,c,V = 0;
        memset(dist,0x3f,sizeof(dist));
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&a,&b,&c);
            dist[a][b]=dist[b][a]=c;
            V = max(V,max(a+1,b+1));
        }
        for(int i=0;i<V;i++)
            dist[i][i] = 0;

        for(int k=0;k<V;k++){
            for(int i=0;i<V;i++){
                for(int j=0;j<V;j++){
                    if(dist[i][k]+dist[k][j]<dist[i][j]){
                        // printf("%d = %d + %d\n",dist[i][j],dist[i][k],dist[k][j]);
                        dist[i][j] = dist[i][k]+dist[k][j];
                    }
                }
            }
        }
        int ans = 1e8,id;
        for(int i=0;i<V;i++){
            int res = 0;
            for(int j=0;j<V;j++){
                res += dist[i][j];
            }
            if(res < ans){
                ans = res;
                id = i;
            }
        }
        printf("%d %d\n",id,ans);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

struct edge{
	int to, cost;
};

int main(){
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0) return 0;

		vector<vector<llong> > v(15, vector<llong>(15, INF));
		int m=0;
		REP(i, n){
			int f, t, c;
			scanf("%d %d %d", &f, &t, &c);
			m=max(m, f);
			m=max(m, t);
			v[f][t]=c;
			v[t][f]=c;
		}
		m++;
		REP(i, m) v[i][i]=0;

		REP(i, m){
			REP(j, m){
				REP(k, m){
					if(v[i][j]>v[i][k]+v[k][j]){
						v[i][j]=v[i][k]+v[k][j];
					}
				}
			}
		}

		int ans=0;
		vector<llong> sum(15, 0);
		REP(i, m){
			REP(j, m){
				if(v[i][j]>=INF) continue;
				sum[i]+=v[i][j];
			}
			if(sum[ans]>sum[i]) ans=i;
		}

		printf("%d %ld\n", ans, sum[ans]);
	}
}

C++: #include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int d[50][50];
void floryd()
{
    for(int k=0;k<=n;k++)
    {
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            {
               d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}
int w,ma;
int main()
{
    while(scanf("%d",&w)&&w)
    {
        for(int i=0;i<=46;i++)
        {
            for(int j=0;j<=46;j++)
            {
                d[i][j]=0x3f3f3f3f;
            }
        }
        ma=-1;
        int a,b,c;
        for(int i=0;i<w;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            ma=max(max(a,b),ma);
            d[a][b]=d[b][a]=c;
        }
        n=ma;
        int q,s;
        floryd();
        int mi=0x3f3f3f3f;
        for(int i=0;i<=ma;i++)
        {
            s=0;
            for(int j=0;j<=ma;j++)
            {
                if(i!=j)
                {
                    s=s+d[i][j];
                }
            }
            if(s<mi)
            {
                mi=s;
                q=i;
            }
        }
        printf("%d %d\n",q,mi);
    }

    return 0;
}