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<bits/stdc++.h>
#define SIZE 100005
#define MAX_V 100001
#define INF (1e9 + 1)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int g[10][10];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i,10;i++){
			for(int j=0;j<10;j++){
				if(i==j)g[i][j]=0;
				else g[i][j]=999999999;
			}
		}
		int t=0;
		for(int i=0;i<a;i++){
			int c,d,e;
			scanf("%d%d%d",&c,&d,&e);
			if(t<c)t=c;
			if(t<d)t=d;
			g[c][d]=e;
			g[d][c]=e;
		}
		t++;
		for(int k=0;k<t;k++){
			for(int i=0;i<t;i++){
				for(int j=0;j<t;j++){
					if(g[i][k]+g[k][j]<g[i][j]) g[i][j]=g[i][k]+g[k][j];
				}
			}
		}
		int n=0;
		ll ans = 9999999999;
		for(int i=0;i<t;i++){
			ll now=0;
			for(int j=0;j<t;j++) now+=g[i][j];
			if(ans>now){
				ans=now;
				n=i;
			}
		}
		printf("%d %lld\n",n,ans);
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <memory>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

int n;
struct Edge
{
    int from;
    int to;
    int cost;
};
vector<Edge> es;
vector<int> ds;

// Bellman-Ford algorithm that computes shortest paths from a single
// source vertex to all of the other vertices in a weighted digraph.
void shortest_path_bf(int s)
{
    fill(ds.begin(), ds.end(), INT_MAX);
    ds[s] = 0;
    while (true)
    {
        bool update = false;
        for (int i = 0; i < es.size(); ++i)
        {
            const Edge& e = es[i];
            if (ds[e.from] != INT_MAX && ds[e.to] > ds[e.from] + e.cost)
            {
                ds[e.to] = ds[e.from] + e.cost;
                update = true;
            }
        }
        if (!update) break;
    }
}

int main(int argc, char *argv[])
{
    while (true)
    {
        scanf("%d", &n);
        if (n == 0) break;
        es.clear();
        int num_town = 0;
        for (int i = 0; i < n; ++i)
        {
            Edge e;
            scanf("%d%d%d", &e.from, &e.to, &e.cost);
            num_town = max(max(num_town, e.from), e.to);
            es.push_back(e);
            swap(e.from, e.to);
            es.push_back(e);
        }
        ds.resize(num_town + 1);
        int min_town;
        int min_value = INT_MAX;
        for (int i = 0; i < ds.size(); ++i)
        {
            shortest_path_bf(i);
            int val = 0;
            for (int j = 0; j < ds.size(); ++j)
            {
                if (ds[j] != INT_MAX) val += ds[j];
            }
            if (val < min_value)
            {
                min_value = val;
                min_town = i;
            }
        }
        printf("%d %d\n", min_town, min_value);
    }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<cstring>
#include<cmath>
using namespace std;
const int N = 10;
const int M = 10;
const int INF = 0x3f3f3f3f;
int d[N][N],n;
int main()
{
    int m,a,b,c;
    while(cin>>m&&m){
        for(int i=0;i<N;i++)
            fill(d[i],d[i]+N,INF);
        n=0;
        while(m--){
            scanf("%d%d%d",&a,&b,&c);
            d[a][b]=d[b][a]=c;
            n=max(max(n,a+1),b+1);
        }
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
        int sum,msum=INF;
        int id=0;
        for(int i=0;i<n;i++){
            sum=0;
            for(int j=0;j<n;j++){
                if(i==j)continue;
                sum+=d[i][j];
            }
            if(sum<msum){
                msum=sum;
                id=i;
            }
        }
        printf("%d %d\n",id,msum);
    }

    return 0;
}

C++: #include <iostream>

#define MAX 10
#define INF 400000000
using namespace std;

int d[MAX][MAX];
int n, num_ver = 0;
int min_t = INF;
int min_ver;

void init();
void input();
void wf();

int main(){

  while(cin >> n, n){
    init();
    input();  
    wf();
    
   
    for(int i = 0; i <= num_ver; i++){
      int tmp = 0;
      for(int j = 0; j <= num_ver; j++){
	tmp += d[i][j];
      }
      if(min_t > tmp) {min_t = tmp; min_ver = i;}
    }
    cout << min_ver << " " << min_t << endl;
  }
}

void init(){
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      d[i][j] = (i==j)? 0: INF;
    }
  }
  num_ver = 0;
  min_t = INF;
  min_ver = 0;
}

void input(){
  for(int i = 0; i < n; i++){
    int a, b, c;
    cin >> a >> b >> c;
    d[a][b] = c;
    d[b][a] = c;
    if(num_ver < b) num_ver = b;
  }
}

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

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>

using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;

int main() {
	int n;
	while (scanf("%d", &n)) {
		if (!n)
			return 0;
		array<array<int, 11>, 11> graph = {};
		int m = 0;
		for (int i = 0; n > i; i++) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);

			graph[a][b] = c;
			graph[b][a] = c;
			m = max({a,b,m});
		}
		m++;
		pii Min = { INT_MAX,INT_MAX };
		for (int i = 0; m > i; i++) {
			priority_queue<pii, vector<pii>, greater<pii>> que;
			vector<int> al(m, -1);
			for (int j = 0; m > j; j++) {
				if (graph[i][j]) {
					que.push({ graph[i][j], j });
				}
			}
			al[i] = 0;
			while (!que.empty()) {
				pii num = que.top();
				que.pop();
				if (al[num.second] != -1)
					continue;
				al[num.second] = num.first;
				for (int j = 0; m > j; j++) {
					if (graph[num.second][j] && al[j] == -1) {
						que.push({ num.first + graph[num.second][j], j });
					}
				}
			}
			Min = min(Min, { accumulate(al.begin(), al.end(),0),i });
		}
		printf("%d %d\n", Min.second, Min.first);
	}
	return 0;
}