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<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>

#define SIZE 100
#define INF 10000000

typedef struct {
  int data;
  int pos;
} DAT;


using namespace std;

int main(){

  DAT ans;
  int i,j,k;
  int a,b,c;
  int n;
  int time[SIZE][SIZE];

  while(1){

    int sum[SIZE]={0};
    cin>>n;
    if(n==0)break;

  for(i=0;i<n+1;i++){
    for(j=0;j<n+1;j++){
      if(i==j){
	time[i][j]=0;
      } else {
	time[i][j]=INF;
      }
    }
  }

  int max=0;
    for(i=0;i<n;i++){
      cin>>a>>b>>c;
      time[a][b]=c;
      time[b][a]=c;
      if(max<a)max=a;
      if(max<b)max=b;
    }

    for(i=0;i<max+1;i++){
      for(j=0;j<max+1;j++){
	for(k=0;k<max+1;k++){
	  time[j][k]=min(time[j][k],time[j][i]+time[i][k]);
	}
      }
    }

    for(i=0;i<max+1;i++){
      for(j=0;j<max+1;j++){
	sum[i]+=time[i][j];
      }
    }

    ans.data=INF;
    ans.pos=-1;
    for(i=0;i<max+1;i++){
      if(sum[i]<ans.data){
	ans.data=sum[i];
	ans.pos=i;
      }
    }

    printf("%d %d\n",ans.pos,ans.data);

  }
  
  return 0;
}

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;

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

int V, E;
int D[MAX_V][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 (cin >> E) {
    if (E == 0) break;

    for (size_t u = 0; u < MAX_V; u++)
      for (size_t v = 0; v < MAX_V; v++) D[u][v] = (u == v)? 0: INF;

    V = 0;
    for (size_t i = 0; i < E; i++) {
      int v, u, cost;
      cin >> v >> u >> cost;
      D[u][v] = cost; D[v][u] = cost;
      V = max(V, (max(u, v)));
    }
    V++;

    solve();
  }

  return 0;
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<climits>

using namespace std;

#define INF INT_MAX/2

int edges[100][100];
int dist[100][100];

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N == 0) break;

        memset(edges,0,sizeof(edges));

        int ids[20];
        int nids = 0;

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            int ix=-1;
            int iy=-1;

            for(int l=0;l<nids;++l)
                if(ids[l]==x){
                    ix = l;
                    break;
                }

            if(ix<0){ ix = nids; ids[nids++]=x; }

            for(int l=0;l<nids;++l)
                if(ids[l]==y){
                    iy = l;
                    break;
                }

            if(iy<0){ iy = nids; ids[nids++]=y; }

            edges[ix][iy] = edges[iy][ix] = c;

        }

        for(int i=0;i<nids;++i){
            for(int j=0;j<nids;++j){
                if(i==j)
                    dist[i][j] = 0;
                else if(edges[i][j]>0)
                    dist[i][j] = edges[i][j];
                else
                    dist[i][j] = INF;
            }
        }

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

        int ans  = 0;
        int msum = INF;

        for(int i=0;i<nids;++i){

            int sum = 0;
            for(int j=0;j<nids;++j){
               if(dist[i][j]==INF)continue;
               sum += dist[i][j];
            }

            if(sum<=msum){

                if(sum==msum){

                    if(ids[i]<=ids[ans])
                        ans = i;

                } else {

                    ans = i;

                }

                msum = sum;

            }

        }

        cout << ids[ans] << " " << msum << endl;

    }

    return 0;

}

C++: #include <iostream>

int inf = 1 << 28;

int dijk(int n,int s, int **g) {
	int sum = 0;
	bool *used = new bool[n];
	int *d = new int[n];

	// std::cout << "n = " << n << " " << "s = " << s << std::endl;

	for(int i = 0; i < n; i++)
		d[i] = inf;
	d[s] = 0;

	while(true) {
		int u = -1;
		for(int v = 0; v < n; v++)
			if(!used[v] && (u == -1 || d[v] < d[u]))
				u = v;

		// std::cout << "u = " << u << std::endl;

		if(u == -1) break;
		used[u] = true;

		for(int v = 0; v < n; v++)
			if(d[v] > d[u] + g[u][v])
				d[v] = d[u] + g[u][v];
	}

	for(int i = 0; i < n; i++) {
		sum += d[i];
	}

	// for(int i = 0; i < n; i++) {
	// std::cout << d[i] << std::endl;
	// }

	return sum;
}

int main() {
	do {
		int **g; // adjacency matrix, ?
		int *d;
		int *a, *b, *c;
		int edge = 0, min = 0, max = 0;
		int tmp = 0;

		std::cin >> edge;
		if(!edge) break;

		a = new int[edge];
		b = new int[edge];
		c = new int[edge];

		for(int i = 0;i < edge;i++) {
			std::cin >> a[i];
			std::cin >> b[i];
			std::cin >> c[i];
		}

		for(int i = 0; i < edge; i++) {
			if(max < a[i])
				max = a[i];
		}
		for(int i = 0; i < edge; i++) {
			if(max < b[i])
				max = b[i];
		}
		max++;

		g = new int*[max];
		d = new int[max];

		for(int i = 0; i < max; i++) {
			g[i] = new int[max];
		}

		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				g[i][j] = inf;

		for(int i = 0; i < edge; i++)
			g[b[i]][a[i]] = g[a[i]][b[i]] = c[i];

		for(int i = 0; i < max; i++)
			d[i] = dijk(max, i, g);

		min = d[0];
		for(int i = 1; i < max; i++) {
			if(min > d[i]) {
				min = d[i];
				tmp = i;
			}
		}

		std::cout << tmp << " " << min << std::endl;
		for(int i = 0; i < max; i++)
			delete[] g[i];
		delete[] g;
		delete[] a;
		delete[] b;
		delete[] c;
		delete[] d;

	}while(true);
	return 0;
}