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 <algorithm>
using namespace std;
#define inf 1<<25
#define min(a,b)((a)<=(b)?(a):(b))
#define rep(i,n)for(int i=0;i<n;i++)
int n,a,b,c;
int cost[10][10];
bool use[10];
int main() {
	while(scanf("%d",&n),n) {
		fill(use,use+10,false);
		fill(cost[0],cost[0]+10*10,inf);
		rep(i,n) {
			scanf("%d %d %d",&a,&b,&c);
			cost[a][b]=cost[b][a]=c;
			use[a]=use[b]=true;
		}
		rep(k,10)rep(i,10)rep(j,10) {
			cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
		}
		int to,cs=inf;
		rep(i,10) {
			if(!use[i])continue;
			int sum=0;
			rep(j,10)if(i!=j&&cost[i][j]<inf)sum+=cost[i][j];
			if(cs>sum)to=i,cs=sum;
		}
		printf("%d %d\n",to,cs);
	}
}

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		// ????????°

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}

		int min=0;
		int total,num;

		for(int i=0;i<m;i++){
			min+=T[0][i];
		}

		for(int i=1;i<m;i++){
			total=0;
			for(int j=0;j<m;j++){
				total+=T[i][j];
			}
			if(min>total){	
				min=total;
				num=i;
			}
		}
		
		cout<<num<<' '<<min<<endl;

	}

	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXC 12
int N,dis[MAXC][MAXC];
bool city[MAXC];
int main()
{
	while(~scanf("%d",&N)&&N)
	{
		memset(dis,0x3F,sizeof dis);
		memset(city,0,sizeof city);
		for(int i=1;i<MAXC;i++)
			dis[i][i]=0;
		for(int i=1,a,b,c;i<=N;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			city[a]=1;city[b]=1;
			dis[a][b]=min(dis[a][b],c);
			dis[b][a]=min(dis[b][a],c);
		}
		for(int k=0;k<MAXC;k++)
		{
			if(!city[k])continue;
			for(int i=0;i<MAXC;i++)
			{
				if(!city[i])continue;
				for(int j=0;j<MAXC;j++)
				{
					if(!city[j])continue;
					dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
				}
			}
		}
		int mn=0x7FFFFFFF,id,sum;
		for(int i=0;i<MAXC;i++)
			if(city[i])
			{
				sum=0;
				for(int j=0;j<MAXC;j++)
					if(city[j])
						sum+=dis[i][j];
				if(mn>sum)
				{mn=sum;id=i;}
			}
		printf("%d %d\n",id,mn);
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 305
using namespace std;
bool debug=false;

int d[12][12];

void init(){
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(i==j) d[i][j]=0;
      else d[i][j]=INF;
    }
  }
}

void make(int n){
  int a,b,c;
  for(int i=0;i<n;i++){
    cin>>a>>b>>c;
    d[a][b]=c;d[b][a]=c;
  }
}

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

void solve(){
  int mini=INF,num;
  for(int i=0;i<=10;i++){
    int sum=0;
    for(int j=0;j<=10;j++){
      if(d[i][j]!=INF)sum+=d[i][j];
    }
    if(sum<mini&&sum!=0){
      mini=sum;
      num=i;
    }
  }
  cout<<num<<" "<<mini<<endl;
}

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    init();
    make(n);
    wf();
    solve();
  }
  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int n;
    int m=0;
    int cost[50][50];
    while(cin>>n){
        if(n==0)break;
        m=0;
        rep(i,50)rep(j,50)cost[i][j]=99999999;
        rep(i,50)cost[i][i]=0;
        rep(i,n){
            int a,b,c;
            cin>>a>>b>>c;
            m=max(m,max(a,b));
            cost[a][b]=cost[b][a]=c;
        }
        m++;
        rep(k,m){
            rep(i,m){
                rep(j,m){
                    cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
                }
            }
        }
        int sum=99999999;
        int t=-1;
        rep(i,m){
            int tmp=0;
            rep(j,m){
                tmp+=cost[i][j];
            }
            if(tmp<sum){
                t=i;
                sum=tmp;
            }
        }
        cout<<t<<" "<<sum<<endl;
    }
}

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 = INT_MAX, index = INT_MAX;
		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();
	}
}