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<iostream>
#include<vector>
using namespace std;
#define FOR(i,a) for(int i=0;i<(int)(a);i++)
#define pb push_back
#define clr clear()
#define sz size()
typedef unsigned int ui;

class node{
public:
  int num;
  void set(int n){num = n;}
  bool equal(int a){
    return num == a;
  }
};

class edge{
public:
  node b,e;
  int cost;

  void set(int s,int g,int c){
    b.set(s);
    e.set(g);
    cost = c;
  }
};

class graph{
public:
  vector<node> n;
  vector<edge> e;

  void set(void){
    n.clr;
    e.clr;
  }

  bool Nexist(node a){
    FOR(i,n.sz){
      if(a.num == n[i].num)return true;
    }
    return false;
  }

  int Eexist(int a,int b){
    for(ui i=0;i<e.sz;i++){
      if(e[i].b.equal(a) && e[i].e.equal(b))return i;
      if(e[i].b.equal(b) && e[i].e.equal(a))return i;
    }
    return -1;
  }

  void Nadd(node a){
    if(!n.sz)n.pb(a);
    else if(!Nexist(a)){
      ui i = 0;
      while(n[i].num < a.num && i<n.sz)i++;
      n.insert(n.begin()+i,a);
    }
  }

  void Eadd(edge a){
    if(!e.sz)e.pb(a);
    else{
      ui i = 0;
      while(e[i].cost < a.cost && i<e.sz)i++;
      e.insert(e.begin()+i,a);
    }
    Nadd(a.b);
    Nadd(a.e);
  }

  graph prim(void){
    graph res;

    res.set();

    if(!e.sz)return res;
    else{
      res.Eadd(e[0]);
      res.Nadd(e[0].b);
      res.Nadd(e[0].e);

      while(res.n.sz < n.sz){
	FOR(i,e.sz){
	  if(res.Nexist(e[i].b) && !res.Nexist(e[i].e)){
	    res.Eadd(e[i]);
	    res.Nadd(e[i].e);
	    i = 0;
	  }else if(!res.Nexist(e[i].b) && res.Nexist(e[i].e) ){
	    res.Eadd(e[i]);
	    res.Nadd(e[i].b);
	    i = 0;
	  }
	}
      }
      return res;
    }
  }

  vector<int> warshall_floyd(void){
    vector<int> at;
    int tmp;
    for(ui i=0;i<n.sz;i++){
      for(ui j=0;j<n.sz;j++){
	if(i==j)at.pb(0);
	else{
	  tmp = Eexist(i,j);
	  if(tmp>=0)at.pb(e[tmp].cost);
	  else at.pb(-1);
	}
      }
    }
    for(ui k=0;k<n.sz;k++){
      for(ui i=0;i<n.sz;i++){
	for(ui j=0;j<n.sz;j++){
	  if(at[i*n.sz+k] >= 0 && at[k*n.sz+j] >= 0){
	    if(at[i*n.sz+k] + at[k*n.sz+j] < at[i*n.sz+j] || at[i*n.sz+j]<0){
	      at[i*n.sz+j] = at[i*n.sz+k] + at[k*n.sz+j];
	      at[j*n.sz+i] = at[i*n.sz+k] + at[k*n.sz+j];
	    }
	  }
	}
      }
    }
    return at;
  }
};

int main(){
  int n;
  int a,b,c;
  vector<int> at;
  graph wf;
  edge tmp;
  int cost,max,minn;
  int min;

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

    max = 0;
    wf.set();
    at.clear();
    for(int k=0;k<n;k++){
      cin >> a >> b >> c;
      if(max < a)max = a;
      if(max < b)max = b;
      tmp.set(a,b,c);
      wf.Eadd(tmp);
    }

    at = wf.warshall_floyd();
    
    max++;

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

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

int main(){
    int N;
    const int INF = 1e9;
    while(cin >> N, N){
        vector<vector<int>> Graph(10,vector<int>(10,INF));

        for(int i=0;i<N;i++){
            int a,b,c;
            cin >> a >> b >> c;
            Graph[a][b] = c;
            Graph[b][a] = c;
        }

        for(int mid = 0; mid < 10; mid++){
            for(int from = 0; from < 10; from++){
                for(int to = 0; to < 10; to++){
                    if(Graph[from][mid] == INF || Graph[mid][to] == INF) continue;
                    Graph[from][to] = min(Graph[from][to], Graph[from][mid] + Graph[mid][to]);
                }
            }
        }

        int V = -1;
        int minCost = INF;

        for(int i=0;i<10;i++){
            int cost = 0;
            for(int j = 0;j<10;j++){
                if(i == j) continue;
                if(Graph[i][j] == INF) continue;
                cost += Graph[i][j];
            }
            if(minCost > cost && cost != 0){
                minCost = cost;
                V = i;
            }
        }
        cout << V << " " << minCost << endl;
    }
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	constexpr int INF = 1e8;
	while(1) {
		int n;
		cin>>n;
		if(!n) break;
		vector<vector<int>> d(10,vector<int>(10,INF));
		for (int i = 0; i < 10; i++)
			d[i][i] = 0;
		for (int i = 0; i < n; i++) {
			int a,b,c;
			cin>>a>>b>>c;
			d[a][b] = d[b][a] = c;
		}
		int maxTown = 0;
		for (maxTown = 0; maxTown < 10; maxTown++) {
			bool exist = false;
			for (int j = 0; j < 10; j++)
				if(d[maxTown][j] != INF && d[maxTown][j]) exist = true;
			if(!exist) break;
		}
		for (int k = 0; k < maxTown; k++)
			for (int i = 0; i < maxTown; i++)
				for (int j = 0; j < maxTown; j++)
					d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
		int minsum = INF,minidx = -1;
		for (int i = 0; i < maxTown; i++) {
			int sum = 0;
			for (int j = 0; j < maxTown; j++)
				sum += d[i][j];
			if(minsum > sum) {
				minsum = sum;
				minidx = i;
			}
		}
		cout << minidx << ' ' << minsum << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <utility>
using namespace std;

typedef long long ll;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)


int d[20][20];
int cost[20][20];
int n;
int numTown;
int t;
void show(){
  for(int i=0;i<t;i++){
    for(int j=0;j<t;j++){
      printf("%10d ",cost[i][j]);
    }
    cout<<endl;
  }
  cout<<endl;
}

void solve(){
  for(int i=0;i<t;i++)for(int j=0;j<t;j++)cost[i][j]=d[i][j];
  for(int k=0;k<t;k++){
    for(int i=0;i<t;i++){
      for(int j=0;j<t;j++){
	if(i==j||i==k||j==k)continue;
	cost[i][j]=cost[j][i]=min(cost[i][j],cost[i][k]+cost[k][j]);
	//	show();
      }
    }
  }
  int ans=INT_MAX;
  int p=0;
  for(int i=0;i<t;i++){
    int sum=0;
    for(int j=0;j<t;j++){
      sum+=cost[i][j];
    }
    if(ans>sum){
      ans=sum;
      p=i;
    }
  }
  cout<<p<<" "<<ans<<endl;

}

int main(void){
  
  while(cin>>n,n){
    t=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i==j)d[i][j]=0;
	else d[i][j]=10000000;
      }
    }
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b>>c;
      d[a][b]=d[b][a]=c;
      t=max(t,max(a+1,b+1));
    }
    solve();
  }
}