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 <algorithm>
using namespace std;

#define INF 1e+9;

int E, V;
int cost[50][50];
int d[100];

int main(){

    while(cin >> E, E){
        V = 0;
        fill(d, d+100, 0);
        for(int i=0; i < 50; i++){
            for(int j=0; j < 50; j++){
                cost[i][j] = (i==j)? 0:INF
            }
        }

        for(int i=0; i < E; i++){
            int a, b, c;
            cin >> a >> b >> c;
            cost[a][b] = c;
            cost[b][a] = c;
            V = max(V, max(a, b));
        }

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

        int minCost = INF;
        for(int i=0; i <= V; i++){
            for(int j=0; j <= V; j++){
                d[i] += cost[i][j];
            }
            minCost = min(minCost, d[i]);
        }

        for(int i=0; i <= V; i++){
            if(minCost == d[i]){
                cout << i << " " << d[i] << endl;
                break;
            }
        }
    }
}

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;

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

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}


    for(int k=0; k<m; k++){
      for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
          if(T[i][j]>T[i][k]+T[k][j]){
            T[i][j] = T[i][k]+T[k][j];
          }
        }
      }
    }

    int ans = INF;
        int t;
        for(int i=0; i<m; i++){
          int sum = 0;
          for(int j=0; j<m; j++){
            sum = sum+T[i][j];
          }
          if(sum<ans){
            ans = sum;
            t=i;
          }
        }
        cout << t << ' ' << ans << endl;
    }








	

	return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 9999999

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;


bool shortestPath(const Graph &g,
    Matrix &dist, vector<vector<int> > &prev) {
  int n = g.size();
  Array h(n+1);
  REP(k,n) REP(i,n) FOR(e,g[i]) {
    if (h[e->dst] > h[e->src] + e->weight) {
      h[e->dst] = h[e->src] + e->weight;
      if (k == n-1) return false; // negative cycle
    }
  }
  dist.assign(n, Array(n, INF));
  prev.assign(n, vector<int>(n, -2));
  REP(s, n) {
    priority_queue<Edge> Q;
    Q.push(Edge(s, s, 0));
    while (!Q.empty()) {
      Edge e = Q.top(); Q.pop();
      if (prev[s][e.dst] != -2) continue;
      prev[s][e.dst] = e.src;
      FOR(f,g[e.dst]) {
        if (dist[s][f->dst] > e.weight + f->weight) {
          dist[s][f->dst] = e.weight + f->weight;
          Q.push(Edge(f->src, f->dst, e.weight + f->weight));
        }
      }
    }
    REP(u, n) dist[s][u] += h[u] - h[s];
  }
}
vector<int> buildPath(const vector< vector<int> >& prev, int s, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[s][u])
    path.push_back(u);
  reverse(ALL(path));
  return path;
}

int main() {
	int n;
	while(cin>>n,n){
		Graph g(10);
		Matrix d;
		vector<vector<int> > p;
		REP(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			g[a].push_back(Edge(a,b,c));
			g[b].push_back(Edge(b,a,c));
		}
		shortestPath(g,d,p);

		int mn=INF,t,mi;
		REP(i,d.size()){
			if(d[i][0]==INF)continue;
			t=0;
			REP(j,d[i].size()){
				if(d[i][j]==INF||i==j)continue;
				t+=d[i][j];
			}
			if(t<mn)mn=t,mi=i;
		}
		cout<<mi<<" "<<mn<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

#define TEST 0
int weakdist(int tc[10][10],int town,int from,int to)
{
    if(from ==to)
        return 0;
    if(tc[from][to] >= 0)
        return tc[from][to];
    return -1;
}

int dist(int tc[10][10],int town,int from,int to)
{
    if(from ==to)
        return 0;
    if(tc[from][to] >= 0)
        return tc[from][to];
    int mindist=-1;
    for(int via=0;via<town;via++)
    {
        if(via == from || via ==to)
            continue;
        if(tc[from][via] == -1 || tc[via][to]==-1)
            continue;
        int sumdist=dist(tc,town,from,via)
        +dist(tc,town,via,to);
        if(mindist < 0 || mindist > sumdist)
            mindist=sumdist;
    }
    if(mindist == -1)
        return -1;
    tc[from][to]=mindist;
    tc[to][from]=mindist;
    return mindist;
}
void dump(int tc[10][10])
{
    
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++)
            {
                printf("%d ",tc[i][j]);
            }
            puts("");
        }
}

int main(void)
{
    int n;
    int tc[10][10];//connections between towns
    while(scanf("%d",&n) == 1 && n != 0)
    {
        int town=0;
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++)
            {
                tc[i][j]=-1;
            }
            tc[i][i]=0;
        }
        for(int k=0;k<n;k++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            if(a==b)
                continue;
            tc[a][b]=c;
            tc[b][a]=c;
            if(town <a+1)town=a+1;
            if(town <b+1)town=b+1;
        }
#if TEST
        printf("town.num=%d\n",town);
#endif
        int minsum=-1;
        int minnum=-1;
        for(int cnt=0;cnt <10000;cnt++)
        {
            for(int i=0;i<town;i++)
            {   
                for(int j=0;j<town;j++)
                {
                    dist(tc,town,i,j);
                }
            }
        }//try calculating for setting the map.
        for(int i=0;i<town;i++)
        {
            int sum=0;
            for(int j=0;j<town;j++)
            {
                sum+=dist(tc,town,i,j);
            }
            if(minsum<0 || minsum >sum)
            {
                minsum=sum;
                minnum=i;
            }
        }
#if TEST
        dump(tc);
#endif
        printf("%d %d\n",minnum,minsum);
    }
    return 0;

}