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>

using namespace std;

int N, M;
int d[15][15];

bool read() {
  cin >> M;
  if (M == 0) return false;
  for (int i = 0; i <= 10; i++) {
    for (int j = 0; j <= 10; j++) {
      d[i][j] = i<<20;
    }
    d[i][i] = 0;
  }
  N = 0;
  int s, e, m;
  for (int i = 0; i < M; i++) {
    cin >> s >> e >> m;
    d[s][e] = m;
    d[e][s] = m;
    N = max(N, s);
    N = max(N, e);
  }
  return true;
}

void floyd(int n) {
  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]);
}

void solve() {
  floyd(N+1);
  int dmin = 1<<20, idx = 0;
  for (int i = 0; i < N; i++) {
    int dis = 0;
    for (int j = 0; j <= N; j++) dis += d[i][j];
    if (dis < dmin) dmin = dis, idx = i;
  }
  cout << idx << ' ' << dmin;
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (read()) {
    solve();
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n,m=11;
	while(cin>>n,n){
		vector<vector<int> >cost(m,vector<int>(m));
		rep(i,m)rep(j,m)cost[i][j]=inf;
		rep(i,n){
			int a,b,c;cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
		}
		int mi=1e9,mii=-1;
		rep(k,m){
			vector<bool>used(m);
			vector<int>d(m,inf);
			d[k]=0;
			while(1){
				int v=-1;
				rep(i,m)if(!used[i]&&(v==-1||d[v]>d[i]))v=i;
				if(v==-1)break;
				used[v]=true;
				rep(i,m)d[i]=min(d[i],d[v]+cost[v][i]);
			}
			int sum=0;
			rep(i,m)if(d[i]!=inf)sum+=d[i];
			if(mi>sum&&sum){mi=sum;mii=k;}
		}
		cout<<mii<<" "<<mi<<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(20, vector<int>(20, 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 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 = 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 <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int MAX_V=10;
int d[10][10];
int V;
const int INF=100000000;

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

int main(){

	int n;
	while(cin>>n&&n!=0){
		for(int i = 0; i < n; i++)
			fill(d[i],d[i]+n,INF);
		set<int> s;
		for(int i = 0; i < n; i++){
			int a,b,c;
			cin>>a>>b>>c;
			d[a][b]=c;
			d[b][a]=c;
			d[i][i]=0;
			s.insert(a);
			s.insert(b);
		}
		V=s.size();
		warshall_floyd();
		int idx;
		int minValue=INF;
		for(int i = 0; i < V; i++){
			int sum=0;
			for(int j = 0; j < V; j++){
				if(i!=j&&d[i][j]!=INF){
					sum+=d[i][j];
				}
			}
			if(minValue>sum){
				minValue=sum;
				idx=i;
			}
		}
		cout<<idx<<" "<<minValue<<endl;
	}


	return 0;
}

C++: #include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<20;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef long long LL;
typedef pair<int,int> P;


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

  const int TOWN = 10;

  int n;
  while(cin>>n,n){

    int cost[TOWN][TOWN];
    REP(i,TOWN){
      fill( cost[i], cost[i]+TOWN, INF );
      cost[i][i]=0;
    }

    int tnum = 0;
    REP(_t,n){
      int a,b,c;
      cin >>a>>b>>c;
      cost[a][b] = cost[b][a] =  c;
      tnum = max( tnum, max(a,b) );
    }
    tnum++;

    REP(k,tnum){
      REP(i,tnum)
	REP(j,tnum)
	cost[i][j] = min( cost[i][j], cost[i][k] + cost[k][j] );
    }

    int res=INF;
    int num=0;
    REP(i,tnum){
      int tmp=0;
      REP(j,tnum){
	tmp += cost[i][j];
      }
      if( res > tmp ){
	res = tmp;
	num = i;
      }
    }

    cout << num << " " << res << endl;
  }

  return 0;
}