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 <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 10000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
struct edge{int to,cost;};
int N;
ll d[10];
bool f[10];
vector<edge> G[10];
void dijkstra(int s){
      REP(i,N)d[i]=-1;
      d[s]=0;
      priority_queue<P,vector<P>,greater<P> > Q;
      Q.push(P(0,s));
      while(!Q.empty()){
            P p=Q.top();Q.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            REP(i,G[v].size()){
                  edge e=G[v][i];
                  if(d[e.to]==-1||d[e.to]>d[v]+e.cost){
                        d[e.to]=d[v]+e.cost;
                        Q.push(P(d[e.to],e.to));
                  }
            }
      }
}
int main(){
      while(cin>>N&&N){
            memset(f,false,sizeof(f));
            REP(i,N){
                  int a,b,c;
                  cin>>a>>b>>c;
                  G[a].PB((edge){b,c});
                  G[b].PB((edge){a,c});
                  f[a]=f[b]=true;
            }
            ll ans=-1,pos=-1;
            REP(i,10){
                  if(!f[i])continue;
                  ll sum=0;
                  dijkstra(i);
                  REP(j,10)if(f[j])sum+=d[j];
                  if(ans==-1||ans>sum){
                        ans=sum;
                        pos=i;
                  }
            }
            cout<<pos<<" "<<ans<<endl;
      }
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>

using namespace std;

struct edge{
	int from,to,cost;
};
typedef pair<int,int> P;//firstがcost,secondがnodeを表す

int N;
int d[20];
vector<edge> e;
const int INF=100000000;
bool flag=true;


void BF(int s){
	for(int i=0;i<N;i++){
		d[i]=INF;
	}
	d[s]=0;
	
	bool update=true;
	while(update){
		update=false;
		for(int i=0;i<e.size();i++){
			edge ed=e[i];
			if(d[ed.from]!=INF&&d[ed.to]>d[ed.from]+ed.cost){
				d[ed.to]=d[ed.from]+ed.cost;
				update=true;
			}
			if(d[ed.to]!=INF&&d[ed.from]>d[ed.to]+ed.cost){
				d[ed.from]=d[ed.to]+ed.cost;
				update=true;
			}
		}
	}
	
	
}
int A[10000][2];
int counter=0;
void solve(){
	int R,mind=INF,ans;N=0;
	cin>>R;
	if(R==0) {flag=false; return;}
	for(int i=0;i<R;i++){
		int x,y,c;
		cin>>x>>y>>c;
		N=max(N,max(x,y));
		edge ne1={x,y,c};
		e.push_back(ne1);
	}
	N++;
	int D[20]={0};
	for(int i=0;i<N;i++){
		BF(i);
		for(int j=0;j<N;j++){
			D[i]+=d[j];
		}
	}
	for(int i=0;i<N;i++){
		if(mind>D[i]){
			ans=i;
			mind=D[i];
		}
	}
	A[counter][0]=ans;A[counter][1]=mind;
	counter++;
	//cout<<ans<<" "<<mind<<endl;
}

int main(){
	while(flag){
		solve();
	}
	for(int i=0;i<counter;i++){
		cout<<A[i][0]<<" "<<A[i][1]<<endl;
	}
}

C++: #include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

map<int, int> convert_table, reverse_table;

int convert(int x) {
	if(convert_table.count(x))
		return convert_table[x];

	convert_table.insert(make_pair(x, convert_table.size()));
	reverse_table.insert(make_pair(convert_table.size() - 1, x));
	return convert_table.size() - 1;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	const int INF = 0xfffffff;

	for(int n; cin >> n, n;) {
		vector<vector<int> > dist(10, vector<int>(10, INF));
		for(int i = 0; i < dist.size(); ++i)
			dist[i][i] = 0;

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

			a = convert(a);
			b = convert(b);

			dist[a][b] = dist[b][a] = c;
		}

		int m = convert_table.size();
		for(int k = 0; k < m; ++k)
			for(int i = 0; i < m; ++i)
				for(int j = 0; j < m; ++j)
					chmin(dist[i][j], dist[i][k] + dist[k][j]);

		int city = INT_MAX, ans = INT_MAX;
		for(int i = 0; i < m; ++i) {
			int sum = 0;
			for(int j = 0; j < m; ++j)
				sum += dist[i][j];

			if(ans > sum || (ans == sum && reverse_table[i] < city)) {
				ans = sum;
				city = reverse_table[i];
			}
		}

		cout << city << " " << ans << endl;
	}

	return EXIT_SUCCESS;
}

C++: //----------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
typedef pair<int64_t,int64_t> pii;
typedef int64_t myint;

const myint INF=INT64_MAX;
const double EPS=1e-10;

void init(){cin.tie(0);ios::sync_with_stdio(false);}
//----------------------------------------------------

typedef struct edge{
  myint to;
  myint cost;
}Edge;

int V=10;
vector<vector<Edge>> G(10);
myint d[10][10];

void dijkstra(int s){
  priority_queue<pii,vector<pii>,greater<pii>> que;

  for(int i=0;i<V;i++){
    d[s][i]=INF;
  }

  d[s][s]=0;
  que.push(pii(0,s));

  while(!que.empty()){
    pii p = que.top();
    que.pop();

    int v=p.second;
    if(d[s][v] < p.first) continue;
    for(int i=0;i<G[v].size();i++){
      Edge e = G[v][i];

      if(d[s][e.to]>d[s][v]+e.cost){
        d[s][e.to]=d[s][v]+e.cost;
        que.push(pii(d[s][e.to],e.to));
      }
    }
  }
}

pii solve(myint n){
  for(int i=0;i<V;i++){
    vector<Edge>().swap(G[i]);
  }

  for(int i=0;i<n;i++){
    int a,b,c;
    cin >> a >> b >> c;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }

  for(int i=0;i<V;i++){
    dijkstra(i);
  }

  vector<myint> cost(V);
  for(int i=0;i<V;i++){
    cost[i]=INF;
  }

  bool isExist;
  for(int i=0;i<V;i++){
    isExist=false;
    for(int j=0;j<V;j++){
      if(d[i][j]!=INF && i!=j){
        cost[i]-=d[i][j];
          isExist=true;
      }
    }
    if(isExist){
      cost[i]=INF-cost[i];
    }
  }

  pii best = pii(0,cost[0]);
  for(int i=1;i<V;i++){
    if(best.second > cost[i]){
      best = pii(i,cost[i]);
    }
  }
  return best;
}

int main(){
  init();

  myint n;
  while(cin >> n,n!=0){
    pii best = solve(n);
    cout << best.first << " " << best.second << endl;
  }
  return 0;
}