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 <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

class Graph{
	private:
	int V,E;
	public:
	vvi Pro;
	void add_V(int v){
		V=v;
		Pro=vvi(V,vi(V,inf));
		for(int i=0;i<V;i++) Pro[i][i]=0;
	}
	void add_edge(int x,int y,int c){
		Pro[x][y]=c;
		Pro[y][x]=c;
	}
	void WARSALL(){
		for(int k=0;k<V;k++) for(int i=0;i<V;i++) for(int j=0;j<V;j++) Pro[i][j]=min(Pro[i][j],Pro[i][k]+Pro[k][j]);
	}
};

int V=-1,E;

int main(){
	while(1){
		cin>>E;
		if(!E) break;
		V=0;
		Graph gra;
		vi S,T,C;
		int s,t,c;
		for(int i=0;i<E;i++){
			cin>>s>>t>>c;
			S.push_back(s);
			T.push_back(t);
			C.push_back(c);
			V=max(V,max(s,t));
		}
		V++;
		gra.add_V(V);
		for(int i=0;i<E;i++) gra.add_edge(S[i],T[i],C[i]);
		gra.WARSALL();
		P ans(-1,inf);
		for(int i=0;i<V;i++){
			int sum=0;
			for(int j=0;j<V;j++) sum+=gra.Pro[i][j];
			if(sum<ans.second) ans=P(i,sum);
		}
		cout<<ans.first<<' '<<ans.second<<endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
const int INF = 11111111;
int main(void){
  int n,a,b,c,cost[50][50];
  int t,s,ans;

  for(;;){
    cin >> n;
    if(!n) break;
    int f[15] = {0};
    ans = INF;

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

    for(int i = 0;i < n;i++){
      cin >> a >> b >> c;
      f[a] = f[b] = 1;
      cost[a][b] = cost[b][a] = c;
    }

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

    for(int i = 0;i <= 10;i++){
      s = 0;
      if(!f[i]) continue;
      for(int j = 0;j <= 10;j++){
	if(!f[j]) continue;
	s += cost[i][j];
      }
      if(s < ans){
	ans = s;
	t = i;
      }
    }

    cout << t << " " << ans << endl;

  }
}

C++: #include<iostream>

using namespace std;
const int MAX = 11;
const int INF = (1<<20);
int D[MAX][MAX];
int n, pos;

void init(){
  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++)
      D[i][j] = INF;

  pos = 0;
}

void solve(){

  for(int i = 0; i < MAX; i++)
    D[i][i] = 0;

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

  int city = -1, T = INF;

  for(int i = 0; i <= pos; i++){
    int tmp = 0;
    for(int j = 0; j <= pos; j++)
      tmp += D[i][j];
    
    if(T > tmp){
      city = i;
      T = tmp;
    }
  }
  cout << city << " " << T << endl;
}
int main(){
 
  while(cin >> n && n){
    init();
    for(int i = 0; i < n; i++){
      int f,t,c;
      cin >> f >> t >> c;
      pos = max(pos,max(f,t));
      D[f][t] = D[t][f] = c;
    }
    solve();
  }
  return 0;
}

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

const int INF = (int)1e9 + 1;

int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;

		int d[10][10];
		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++) {
			int a, b, c;
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
		}
		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		int ans = INF;
		int num = 0;
		for (int i = 0; i < 10; i++) {
			int sum = 0;
			for (int j = 0; j < 10; j++) {
				if (d[i][j] < INF) sum += d[i][j];
			}
			if (sum > 0 && ans > sum) {
				ans = sum;
				num = i;
			}
		}
		cout << num << " " << ans << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
const int INF=(1<<21);
int main(){

  int n;
  
  while( cin >> n, n ) {
    int town[11][11];
    int a, b, c;
    int min_total = INF;
    int min_town = 0;
    int s[11] = {0};
    for(int i=0; i<11; i++) {
      for(int j=0; j<11; j++) {
	town[i][j] = (i == j) ? 0 : INF;
      }
    }
 
    int v = 0;
    for(int i=0; i<n; i++) {
    cin >> a >> b >> c;
    town[a][b] = c;
    town[b][a] = c;
    v = max(max(v, a), b);
  }

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

    for(int i=0; i<=v; i++) {
      int total = 0;
      for(int j=0; j<=v; j++) {
	total += town[i][j];
      }
      s[i] = total;
      min_total = min(min_total, total);
    }
    for(int i=0; i<=v; i++) {
      if( s[i] == min_total ) {
	cout << i << ' ';
	cout << min_total << endl;
	break;

      }
    }
  }
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int d[10][10];
int m;

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

bool vis[10];

int main() {
  int i, j, a, b, c, n;
  while (scanf("%d", &n) != EOF && n) {
    memset(d, 0x3f, sizeof(d));
    m = 0;
    memset(vis, 0, sizeof(vis));
    while (n--) {
      scanf("%d%d%d", &a, &b, &c);
      d[a][b] = d[b][a] = c;
      m = max(m, max(a + 1, b + 1));
      vis[a] = vis[b] = 1;
    }
    floyd();
    int ans, p, tmp;
    ans = 0x7fffffff;
    for (i = 0; i < 10; ++i) {
      if (!vis[i]) continue;
      tmp = 0;
      for (j = 0; j < 10; ++j) {
        if (!vis[j] || i == j) continue;
        tmp += d[i][j];
        if (tmp >= ans) break;
      }
      if (tmp < ans) {
        ans = tmp;
        p = i;
      }
    }
    printf("%d %d\n", p, ans);
  }
  return 0;
}