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 <iostream>
#include <algorithm>
#include <numeric>
#include <string.h>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <vector>
#define N 211
using namespace std;
typedef long long ll;
int a[N][N];
int main()
{
    int inf = 99999999;
    int m, n;
    while (~scanf("%d",&m))//floyd
    {
        if (m == 0)  return 0;
        int i, j, k;
        for (i=0; i<=11; i++)
            for (j=i; j<=11; j++)
                if (i == j)  a[i][j] = 0;
                else  a[i][j] = a[j][i] = inf;

        n = -1;
        for (i=0; i<m; i++)
        {
            int q, w, e;
            scanf("%d%d%d",&q,&w,&e);
            n = max(n,q);
            n = max(n,w);
            if (e < a[q][w])  a[q][w] = a[w][q] = e;
        }

        for (k=0; k<=n; k++)
            for (i=0; i<=n; i++)
                for (j=0; j<=n; j++)
                    a[i][j] = min(a[i][j],a[i][k]+a[k][j]);

        int ans , sum = inf;
        for (i=0; i<=n; i++)
        {
            int temp = 0;
            for (j=0; j<=n; j++)
                temp += a[i][j];
            if (temp < sum)
            {
                sum = temp;
                ans = i;
            }
        }
        cout << ans << " " << sum << endl;
    }
    return 0;
}

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

int n, m, a, b, c, _end;
int x[10][10];

int bfs(int p, int a) {
	int s[10], minx = 114514, sum;
	sum = 0;
	memset(s, 127, sizeof(s));
	s[a] = 0;
	for (int l = 0; l < p; l++) {
		for (int o = 0; o < p; o++) {
			if (s[o] < 114514) {
				for (int q = 0; q < p; q++) {
					if (x[o][q] < 114514) {
						s[q] = min(s[q], s[o] + x[o][q]);
					}
				}
			}
		}
	}
	for (int l = 0; l < p; l++) {
		sum += s[l];
	}
	minx = min(minx, sum);
	return minx;
}

int search(int p) {
	int t[10], maxn = 114514, maxid;
	for (int k = 0; k < p; k++) {
		t[k] = bfs(p, k);
	}
	for (int k = 0; k < p; k++) {
		if (maxn > t[k]) {
			maxn = t[k];
			maxid = k;
		}
	}
	return maxn * 100 + maxid;
}

void _cin() {
	memset(x, 51, sizeof(x));
	n = 0;
	_end = 0;
	cin >> m;
	if (m == 0) { _end = 1; return; }
	for (int i = 0; i < m; i++) {
		cin >> a >> b >> c;
		n = max(n, max(a, b));
		x[a][b] = c;
		x[b][a] = c;
	}
	n += 1;
}

int main() {
	while (true) {
		_cin();
		if (_end == 1) { break; }
		cout << search(n) % 100 << ' ' << search(n) / 100 << endl;
	}
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int INF=99999999;
int N;
int a[45],b[45],c[45];
int d[10][10];
int m;
void print(){
  for(int i=0;i<=m;i++){
    for(int j=0;j<=m;j++){
      printf("%d ",d[i][j]);
    }
    printf("\n");
  }
  printf("\n");
}
int main(){
  while(1){
    m=0;
    scanf("%d",&N);
    if(N==0)break;
    for(int i=0;i<N;i++){
      scanf("%d %d %d",&a[i],&b[i],&c[i]);
      a[i];b[i];
      m=max(m,b[i]);
    }
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	if(i==j)d[i][j]=0;
	else d[i][j]=INF;
      }
    }
    for(int i=0;i<N;i++){
      d[a[i]][b[i]]=min(d[a[i]][b[i]],c[i]);
      d[b[i]][a[i]]=min(d[b[i]][a[i]],c[i]);
    }
    for(int k=0;k<=m;k++){
      for(int j=0;j<=m;j++){
	for(int i=0;i<=m;i++){
	  d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	}
      }
    }
    int x,ans=INF;
    for(int i=0;i<=m;i++){
      int sum=0;
      for(int j=0;j<=m;j++){
	if(d[i][j]!=INF && d[i][j]!=0)sum+=d[i][j];
      }
      if(ans>sum){ans=sum;x=i;}
    }
    printf("%d %d\n",x,ans);
  }
  return 0;
}

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

#define N 10
#define INF 1000000
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)

int main() {
	int n, cost[N][N], ans, num, sum, m, a, b, c;
	while(1) {
		cin >> n;
		if(!n) break;
		for(int i=0; i<N; ++i) for(int j=0; j<N; ++j) {
			cost[i][j] = (i==j?0:INF);
		}
		m = 0;
		for(int i=0; i<n; ++i) {
			cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
			m = max(m, max(a, b));
		}
		for(int k=0; k<=m; ++k) {
			for(int i=0; i<=m; ++i) {
				for(int j=0; j<=m; ++j) {
					cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
				}
			}
		}
		ans = INF; num = -1;
		for(int i=0; i<=m; ++i) {
			sum = 0;
			for(int j=0; j<=m; ++j) {
				sum += cost[i][j];
			}
			if(ans>sum) {
				num = i;
				ans = sum;
			}
		}
		cout << num << " " << ans << endl;
	}
	return 0;
}

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

using namespace std;

// BEGIN_LIBRARY ///////////////////
#define MAX_V (1000)
#define INF (999999)

namespace NLibrary{
	class Dijkstra {
	private:
		int cost[MAX_V][MAX_V];
		int d[MAX_V];
		bool used[MAX_V];
		int V;
	public:
		Dijkstra() {
			for (int i = 0; i < MAX_V; i++) {
			  fill(cost[i], cost[i] + MAX_V, INF);
			}
		}

		void setV(int V) {
			this->V = V;
		}

		void setCost(int a, int b, int c, bool bidirect = false) {
			this->cost[a][b] = c;
			if (bidirect) {
				this->cost[b][a] = c;
			}
		}

		void calc(int s) {
			// s??????????????????????????¢????±???????
			fill(d, d + MAX_V, INF); 
			fill(used, used + MAX_V, false);
			d[s] = 0;
			while (true) {
				int v = -1;
				for (int u = 0; u < V; u++) {
					if (!used[u] && (v == -1 || d[u] < d[v])) {
						v = u;
					}
				}

				if (v == -1) break;
				used[v] = true;
				for (int u = 0; u < V; u++) {
					d[u] = min(d[u], d[v] + cost[v][u]);
				}
			}
		}

		int getL(int a) {
			return d[a];
		}
	};

}

// END_LIBRARY ////////////////////

int main() {
	NLibrary::Dijkstra dijkstra;
	int n;
	bool flag[100];
	while (cin >> n, n != 0) {
		fill(flag, flag + 100, false);
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
		  dijkstra.setCost(a, b, c, true);
			flag[a] = true;
			flag[b] = true;
		}
		int V = 0;
		for (int i = 0; i < 100; i++) {
			if (flag[i] == true) {
				V++;
			}
		}
		
		dijkstra.setV(V);
		for (int i = 0; i < n; i++) {
			
		}
		int m = INF, town = -1;
		for (int i = 0; i < V; i++) {
			int sum = 0;
			dijkstra.calc(i);
			for (int j = 0; j < V; j++) {
				sum += dijkstra.getL(j);
			}

			if (sum < m) {
				town = i;
				m = sum;
			}
		}
		cout << town << " " << m << endl;
	}
	return 0;
}