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 <cstdio>
#include <algorithm>

const int N = 15;
const int INF = 1 << 25;
int dist[N][N];
void chmin(int &a, int b) {
    a = std::min(a, b);
}

int main() {
    while(1) {
        int M; scanf("%d", &M);
        if(M == 0) break;

        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if(i != j) dist[i][j] = INF;
            }
        }

        int T = 0;
        for(int i=0; i<M; i++) {
            int a, b, c; scanf("%d%d%d", &a, &b, &c);
            chmin(dist[a][b], c);
            chmin(dist[b][a], c);
            T = std::max({T, a+1, b+1});
        }

        for(int k=0; k<T; k++) {
            for(int i=0; i<T; i++) {
                for(int j=0; j<T; j++) {
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }

        int ans = INF, idx = 0;
        for(int i=0; i<T; i++) {
            int sum = 0;
            for(int k=0; k<T; k++) {
                sum += dist[i][k];
            }
            if(ans > sum) {
                ans = sum;
                idx = i;
            }
        }
        printf("%d %d\n", idx, ans);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 10000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
struct edge{int to,cost;};
int N;
int d[10];
bool f[10];
vector<edge> G[10];
void dijkstra(int s){
      REP(i,N)d[i]=-1;
      d[s]=0;
      priority_queue<P,vector<P>,greater<P> > Q;
      Q.push(P(0,s));
      while(!Q.empty()){
            P p=Q.top();Q.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            REP(i,G[v].size()){
                  edge e=G[v][i];
                  if(d[e.to]==-1||d[e.to]>d[v]+e.cost){
                        d[e.to]=d[v]+e.cost;
                        Q.push(P(d[e.to],e.to));
                  }
            }
      }
}
int main(){
      while(cin>>N&&N){
            memset(f,false,sizeof(f));
            REP(i,N){
                  int a,b,c;
                  cin>>a>>b>>c;
                  G[a].PB((edge){b,c});
                  G[b].PB((edge){a,c});
                  f[a]=f[b]=true;
            }
            ll ans=-1,pos=-1;
            REP(i,10){
                  if(!f[i])continue;
                  int sum=0;
                  dijkstra(i);
                  REP(j,10)if(f[j])sum+=d[j];
                  if(ans==-1||ans>sum){
                        ans=sum;
                        pos=i;
                  }
            }
            cout<<pos<<" "<<ans<<endl;
      }
}

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

constexpr int INF = 1 << 16;

struct Edge {
    int start;
    int cost = INF;
    std::vector<int> to;
    std::unordered_map<int, int> time;
};

bool operator>(const Edge& lhs, const Edge& rhs)
{
    return lhs.cost > rhs.cost;
}

bool operator<(const Edge& lhs, const Edge& rhs)
{
    return lhs.cost < rhs.cost;
}

std::vector<Edge> makeEdgeFromData(int data_num, int& max_city);

int calcMinimumTimeToAllCitys(int start_city, int max_city,
    std::vector<Edge> edge);

int main()
{
    int data_num;
    while (std::cin >> data_num) {
        if (data_num == 0) {
            break;
        }
        int max_city;
        const auto edge = makeEdgeFromData(data_num, max_city);

        int min_cost
            = calcMinimumTimeToAllCitys(edge.at(0).start, max_city, edge);
        int min_city = 0;

        for (int i = 1; i <= max_city; ++i) {
            int cost = calcMinimumTimeToAllCitys(edge.at(i).start, max_city, edge);
            if (cost < min_cost) {
                min_cost = cost;
                min_city = i;
            }
        }

        std::cout << min_city << " " << min_cost << std::endl;
    }

    return 0;
}

std::vector<Edge> makeEdgeFromData(int data_num, int& max_city)
{
    std::vector<Edge> edge(10);

    max_city = 0;
    for (int i = 0; i < data_num; ++i) {
        int start, goal, time;
        std::cin >> start >> goal >> time;
        edge.at(start).start = start;
        edge.at(start).to.push_back(goal);
        edge.at(start).time[goal] = time;

        edge.at(goal).start = goal;
        edge.at(goal).to.push_back(start);
        edge.at(goal).time[start] = time;

        max_city = std::max({start, goal, max_city});
    }

    return edge;
}

int calcMinimumTimeToAllCitys(
    int start_city,
    int max_city,
    std::vector<Edge> edge)
{
    for (auto& e : edge) {
        e.cost = INF;
    }

    edge.at(start_city).cost = 0;

    std::priority_queue<Edge> Q;
    Q.push(edge.at(start_city));

    while (!Q.empty()) {
        auto q = Q.top();
        Q.pop();

        for (int to : q.to) {
            if (edge.at(to).cost > q.cost + q.time.at(to)) {
                edge.at(to).cost = q.cost + q.time.at(to);
                Q.push(edge.at(to));
            }
        }
    }

    int cost = 0;
    for (int i = 0; i <= max_city; ++i) {
        cost += edge.at(i).cost;
    }

    return cost;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX 11
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];

int dijkstra(int s){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = 0 ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = 0; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            v[i] = min(v[i],t);
        }
    }
    
    int sum = 0;
    for(int i = minnum ; i <= maxnum ; i++) sum += v[i];
    
    return sum;
}


int main(){
    int a,b,c;
    
    while(cin >> n,n){
        for(int i = 0 ; i < MAX ; i++)
            for(int j = 0 ; j < MAX ; j++)
                r[i][j] = INF;
        
        maxnum = 0; minnum = INF;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
            minnum = min(minnum,min(a,b));
        }
        
        int ans = INF, e;
        for(int i = 0; i <= maxnum ; i++){
            if(dijkstra(i) < ans){
                ans = dijkstra(i);
                e = i;
            }
        }
        cout << e << ' ' << ans << endl;
    }
    
    return 0;
}