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<cstring>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
int main(){
  int MATHI[10][10];
  int n,a,b,c,syo;
  while(1){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++) MATHI[i][j]=1000000;
      MATHI[i][i]=0;
    }
    syo=0;
    cin >> n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin >> a >> b >> c;
      MATHI[a][b]=MATHI[b][a]=c;
      syo=max(syo,max(a,b));
    }
    for(int i=0;i<=syo;i++){
      for(int j=0;j<=syo;j++){
	for(int k=0;k<=syo;k++){
	  MATHI[j][k]=min(MATHI[j][k],MATHI[j][i]+MATHI[i][k]);
	}
      }
    }
    int no,h=1000000;
    for(int i=0;i<=syo;i++){
      int sum=0;
      for(int j=0;j<=syo;j++){
	sum+=MATHI[i][j];
      }
      if(h>sum){
	h=sum;
	no=i;
      }
    }
    cout << no << " " << h << endl;
  }
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#define INF 100000000
typedef long long int lli;
using namespace std;

struct edge{int from1,to1,from2,to2,cost;};
int shortest_path(int s,int V,int E,vector<int> d,vector<edge> es){
	int result=0;
	for(int i=0; i<V; ++i) d[i]=INF;
	d[s]=0;
	while(true){
		bool update = false;
		for(int i=0; i<E; ++i){
			edge e=es[i];
			if(d[e.from1]!=INF&&d[e.to1]>d[e.from1]+e.cost){
				d[e.to1]=d[e.from1]+e.cost;
				update=true;
			}
			if(d[e.from2]!=INF&&d[e.to2]>d[e.from2]+e.cost){
				d[e.to2]=d[e.from2]+e.cost;
				update=true;
			}
		}
		if(!update) break;
	}
	for(int i=0; i<V; ++i){
		result+=d[i];
	}
	return result;
}

int main(){
	int n;
	while(cin>>n&&n){
		vector<edge> es(n);
		int m=0;
		for(int i=0; i<n; ++i){
			int a,b,c;
			cin >> a >> b >> c;
			m=max(a,max(b,m));
			es[i].from1=a;
			es[i].to1=b;
			es[i].from2=b;
			es[i].to2=a;
			es[i].cost=c;
		}
		vector<int> d(m+1);
		int ans_d=INF;
		int ans_s;
		for(int i=m; i>=0; --i){
			int tmp=shortest_path(i,m+1,n,d,es);
			//cout << tmp << "\n";
			if(ans_d>tmp){
				ans_d=tmp;
				ans_s=i;
			}
		}
		cout << ans_s << " " << ans_d << "\n";
	}
	return 0;
}

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

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

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

	const int INF = 0xfffffff;

	for(int n; cin >> n, n;) {
		int m = 0;
		vector<vector<long long> > dist(10, vector<long long>(10, LLONG_MAX / 2));
		for(int i = 0; i < 10; ++i)
			dist[i][i] = 0;

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

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

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

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

			if(ans > sum) {
				ans = sum;
				city = i;
			}
		}

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


	return EXIT_SUCCESS;
}

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

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

typedef struct{int to; int cost;} edge;

#define INF   (1e9+7)
#define MAX_V (10)
#define MAX_E (45)
#define MAX_C (100)

int V, E;
int D[MAX_V+1][MAX_V];

void warshall_floyd() {
  for (size_t u = 0; u < V; u++)
    for (size_t v = 0; v < V; v++)
      for (size_t w = 0; w < V; w++) D[u][v] = min(D[u][v], D[u][w] + D[w][v]);
}

void solve() {
  int ans_c, ans_d = INF;

  warshall_floyd();

  for (size_t v = 0; v < V; v++) {
    int cost = 0;
    for (size_t u = 0; u < V; u++) cost += D[u][v];
    if (cost < ans_d) {
      ans_c = v;
      ans_d = cost;
    }
  }

  printf("%d %d\n", ans_c, ans_d);
}

int main() {
  while (true) {
    for (size_t u = 0; u < MAX_V; u++)
      for (size_t v = 0; v < MAX_V; v++) D[u][v] = INF;

    scanf("%d", &E);
    if (E == 0) break;
    V = 0;
    for (size_t i = 0; i < E; i++) {
      int v, u, cost;
      scanf("%d %d %d", &v, &u, &cost);
      D[u][v] = cost; D[v][u] = cost;
      V = max(V, (max(u, v)));
    }
    V++;
    for (size_t v = 0; v < V; v++) D[v][v] = 0;

    solve();
  }

  return 0;
}

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

using namespace std;
int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0)
            break;
        
        vector<int> x(10);
        x[0] = 0;
        x[1] = 1;
        for(int i = 0; i < 9; i++){
            x[i+1] = x[i] * 2 + 1;
        }
        int y = x[9] * 2 + 1;
        vector<int> r(y, 0-1);
        vector<int> t(10, 0);
        int ans;
        int anst;
        
        for(int i = 0; i < 10; i++)
            r[ x[i]+x[i] ] = 0;
        
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            r[ x[a]+x[b] ] = c;
        }
        
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                if( r[x[i]+x[j]] == 0-1 )
                    continue;
                int M = 0-1;
                for(int k = 0; k < 10; k++){
                    if( r[x[i]+x[k]] == 0-1 )
                        continue;
                    if( r[x[j]+x[k]] == 0-1 || r[x[j]+x[k]] > r[x[i]+x[j]] + r[x[i]+x[k]] )
                        r[x[j]+x[k]] = r[x[i]+x[j]] + r[x[i]+x[k]];
                }
            }
        }
        
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                t[i] += r[x[i]+x[j]];
            }
            if( i == 0 ){
                ans = i;
                anst = t[i];
            }
            else if( t[i] < anst ){
                ans = i;
                anst = t[i];
            }
        }
        
        cout << ans << " " << anst <<endl;
        
    }
}