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<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) % 10 << ' ' << search(n) / 10 << endl;
	}
}

C++: #include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

map<int, int> convert_table;

int convert(int x) {
	if(convert_table.count(x))
		return convert_table[x];

	convert_table.insert(make_pair(x, convert_table.size()));
	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<long long> > dist(10, vector<long long>(10, INT_MAX));
		for(int i = 0; i < 10; ++i)
			dist[i][i] = 0;

		convert_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;
		long long ans = LLONG_MAX;
		for(int i = 0; i < m; ++i) {
			long long sum = 0;
			for(int j = 0; j < m; ++j)
				sum += dist[i][j];

			if(ans > sum) {
				ans = sum;
				city = i;
			}
		}

		cout << city << " " << ans << endl;
	}


	return EXIT_SUCCESS;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF 10000
#define dm(x) cerr << #x << " = " << x << endl;
using namespace std;

int main()
{
  int n, d[10][10], city, s[10], ms, mc;
  while(scanf("%d",&n),n){
    city=0;

    rep(i,10) rep(j,10)
      if (i==j) d[i][j]=0;
      else d[i][j]= INF;
    
    rep(i,n) {
      int a,b,c;
      scanf("%d %d %d", &a, &b, &c);
      d[a][b]=c;
      d[b][a]=c;
      city = max(max(a,b),city);
    }

    rep(k,10) rep(i,10) rep(j,10){
      d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    }
    
    // rep(i,city+1) rep(j,city+1)
    //   printf("%d %d: %d\n", i,j,d[i][j]);

    ms=-1;mc=INF;
    rep(i,city){
      s[i]=0;
      rep(j,city+1)
        s[i]+=d[i][j];
      if(s[i] < mc) {
        ms = i;
        mc = s[i];
      }
    }
    
    printf("%d %d\n", ms, mc);
  }
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
const int N = 100000+5;
int mp[15][15];
const int inf = 10000;
int d[15][15];
int main()
{
   int n;
   while(cin >> n && n)
   {
   for(int i = 0; i <= 10; i++)
   {
       for(int j = 0; j <= 10; j++)
       {
           mp[i][j] = inf;
       }
       mp[i][i] = 0;
   }
   int m = 0;
   for(int i = 0; i < n; i++)
   {
       int a,b,c;
       scanf("%d%d%d",&a,&b,&c);
       mp[a][b] = mp[b][a] = min(mp[a][b],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++)
           {
               mp[i][j] = min(mp[i][k] + mp[k][j],mp[i][j]);
           }
       }
   }
   int ans = 10000,p = 0;
   for(int i = 0; i <= m; i++)
   {
       int now = 0;
    //   cout <<i <<endl;
       for(int j = 0; j <= m; j++)
       {
           if(mp[i][j] != inf)
           {
               now += mp[i][j];
             //  cout <<now <<"      " <<mp[i][j] << endl;
           }
       }
       if(now < ans)
       {
           p = i;
           ans = now;
       }
   }
   printf("%d %d\n",p,ans);
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while(cin>>n,n){  //,演算子、最後の式を評価
        if(n==0) break;
        vector<vector<int>> graph(10,vector<int>(10,99999999));
        int used[10]={0};
        for(int i=0;i<n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            graph[a][b]=c;
            graph[b][a]=c;
            used[a]++;
            used[b]++;
        }
        for(int i=0;i<10;i++){
            graph[i][i]=0;
        }
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<10;k++){
                    if(graph[i][j]>graph[i][k]+graph[k][j])
                        graph[i][j]=graph[i][k]+graph[k][j];
                }
            }
        }
        int min=99999999;
        int minpos;
        for(int i=0;i<10;i++){
            if(used[i]==0) continue;
            int sum=0;
            for(int j=0;j<10;j++){
                if(used[j]>0){
                    sum+=graph[i][j];
                }
            }
            if(min>sum){
                min=sum;
                minpos=i;
            }
        }
        cout<<minpos<<" "<<min<<endl;
    }
}