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<climits>
using namespace std;

int w[10][10];

int d[10][10];

int x[10];

int tw;

void erace(bool flag){
	for(int i=0; i<10; i++){
		if(flag){
			x[i] = 0;
			continue;
		}
		for(int j=0; j<10; j++)
				w[i][j] = INT_MAX;
	}
}

void copy(){
	for(int i=0; i<10; i++)
		for(int j=0; j<10; j++)
			d[i][j] = w[i][j];
}

int min(){
	int tmp = x[0];
	int ans = 0;
	for(int i=1; i<tw; i++){
		if(tmp > x[i]){
			tmp = x[i];
			ans = i;
		}
	}
	return ans;
}

int solve(){
	copy();
	for(int k=0; k<tw; k++){
		for(int i=0; i<tw; i++){
			for(int j=0; j<tw; j++){
				if(d[i][k] >= INT_MAX || d[k][j] >= INT_MAX)
					continue;
				int dis = d[i][k] + d[k][j];
				if(dis < d[i][j])
					d[i][j] = dis;
			}
		}
	}
	erace(true);
	for(int i=0; i<tw; i++){
		for(int k=0; k<tw; k++){
			if(k == i)
				continue;
			x[i] += d[i][k];
		}
	}

	return min();
}

int main(){
	int n,a,b,c;
	while(true){
		tw = 0;
		erace(false);
		cin >> n;
		if(!n)
			return 0;
		for(int i=0; i<n; i++){
			cin >> a >> b >> c;
			w[a][b] = c;
			w[b][a] = c;
			if(tw < a+1)
				tw = a+1;
			if(tw < b+1)
				tw = b+1;
		}
		n = solve();
		cout << n << ' ' << x[n] << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

const int MAXT = 11, MAXN = 45, INF = 10000;

int cost[MAXT][MAXT];
int d[MAXT];
bool used[MAXT];
int a, b, c, t, n, anst, ansc, tcost;

int main()
{
    while(cin >> n && n)
    {
        memset(cost, INF, sizeof(cost));
        t = 0;

        REP(n)
        {
            cin >> a >> b >> c;
            cost[a][b] = cost[b][a] = c;
            t = max(t, a+1);
            t = max(t, b+1);
        }
        anst = MAXT, ansc =INF;

        rep(k,t)
        {
            memset(d, INF, sizeof(d));
            memset(used, false, sizeof(used));

            d[k] = 0;
            tcost = 0;
            
            while(true)
            {
                int v = -1;
                rep(i,t)if(!used[i] && (v == -1 || d[i] < d[v])) v = i;
                
                if(v == -1) break;

                used[v] = true;

                rep(i,t) d[i] = min(d[i], d[v] + cost[v][i]);

            }
            REP(t) tcost += d[i];
            if(tcost < ansc) { anst = k; ansc = tcost;}
        }
        cout << anst <<" " << ansc << endl;

    }

    return 0;
}

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

#define MAX_V 11
#define INF (INT_MAX/2)
void floydwarshall(int V, vector< vector<int> > &dist){
  for(int k = 0; k < V; k++){
    for(int i = 0; i < V; i++){
      for(int j = 0; j < V; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
  }
}

int main(void){
  int E;
  while(cin >> E && E != 0){
    int V, s, d, c;
    vector< vector<int> > dist(MAX_V, vector<int>(MAX_V, INF));
    V = -INF;

    while(E--){
      cin >> s >> d >> c;
      dist[s][d] = c;
      dist[d][s] = c;
      V = max(V, max(s, d));
    }
    V += 1;

    for(int i = 0; i < MAX_V; i++) dist[i][i] = 0;
    floydwarshall(V, dist);

    int ans, min_cost = INF;
    for(int i = 0; i < V; i++){
      int cost = 0;
      for(int j = 0; j < V; j++){
        cost += dist[i][j];
      }
      if(min_cost <= cost) continue;
      min_cost = cost;
      ans = i;
    }

    cout << ans << " " << min_cost << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
const int INF=1e9;
struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b){}
    edge(){}
};
struct data{
    int At,cost;
    data(int a,int b):At(a),cost(b){}
    data(){}
    bool operator>(const data &d)const{
        return cost>d.cost;
    }
};
vector<vector<edge> >E;
int all;
int dijkstra(int s){
    vector<int>D(all,INF);
    priority_queue<data,vector<data>,greater<data> >Q;
    Q.push(data(s,0));
    while(!Q.empty()){
        int At=Q.top().At,cost=Q.top().cost;
        Q.pop();
        if(D[At]<=cost)continue;
        D[At]=cost;
        for(int i=0;i<E[At].size();i++){
            edge e=E[At][i];
            Q.push(data(e.to,e.cost+cost));
        }
    }
    int sum=0;
    for(int i=0;i<all;i++)sum+=D[i];
    return sum;
}
int main(){
    int n;
    while(cin>>n,n){
        E.clear();
        E.resize(10);
        all=0;
        for(int i=0;i<n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            all=max(max(a,b),all);
            E[a].push_back(edge(b,c));
            E[b].push_back(edge(a,c));
        }
        all++;
        int Min=INF,p;
        for(int i=0;i<all;i++){
            int latte=dijkstra(i);
            if(Min>latte){
                Min=latte;
                p=i;
            }
        }

        cout<<p<<" "<<Min<<endl;

    }
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define scanf scanf_s

int n;
int cost[11][11];
int main()
{
	while (cin >> n,n)
	{
		REP(i, 11)REP(j, 11) cost[i][j] = INF;
		REP(i, 11) cost[i][i] = 0;
		int city = 0;
		REP(i, n)
		{
			int a, b, c;
			cin >> a >> b >> c;
			city = max(city, max(a, b));
			cost[a][b] = c;
			cost[b][a] = c;
		}
		city++;
		REP(i, city)REP(j, city)REP(k, city)
		{
			cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
		}
		int lcost[11] = {};
		REP(i, city)
		{
			REP(j, city) lcost[i] += cost[i][j];
		}
		int ansc = INF;
		int ans;
		REP(i, city)
		{
			if (ansc > lcost[i])
			{
				ansc = lcost[i];
				ans = i;
			}
		}
		cout << ans << " " << ansc << endl;
	}
	return 0;
}