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 <cstring>
#include <iostream>
#include <queue>
using namespace std;

int n, m; // 道の数，街の数
int edges[10][10];

int dijkstra(int from, int to) {
    bool visited[m];
    fill(visited, visited + m, false);
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
    que.push(make_pair(0, from));
    visited[0] = true;
    while (!que.empty()) {
        pair<int, int> current = que.top();
        que.pop();
        
        const int dist = current.first;
        const int pos = current.second;
        
        if (pos == to) {
            return dist;
        }
        
        for (int i = 0; i < m; i++) {
            if (!visited[i] && edges[pos][i] != 0x7f7f7f7f) {
                visited[i] = true;
                que.push(make_pair(dist + edges[pos][i], i));
            }
        }
    }
    return -1;
}

int main() {
    while (cin >> n, n) {
        memset(edges, 0x7f, sizeof(edges));
        
        for (int i = 0; i < n; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            edges[a][b] = edges[b][a] = c;
            m = max(a, max(b, m));
        }
        m++;
        
        int res, res_time = 0x7fffffff;
        for (int i = 0; i < m; i++) {
            int total = 0;
            for (int j = 0; j < m; j++) {
                total += dijkstra(i, j);
            }
            if (total < res_time) {
                res_time = total;
                res = i;
            }
        }
        
        cout << res << ' ' << res_time << endl;
    }
    
    return 0;
}

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

using namespace std;
static const int INF = 999999999;
typedef pair<int, int> P;
struct SEdge
{
	int To;
	int Cost;
};
vector<int> d;
vector<SEdge> G[10];

void Dijkstra(int s)
{
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > PQue;
	PQue.push(P(0, s));
	while(!PQue.empty())
	{
		P p = PQue.top();
		PQue.pop();
		if(d[p.second] < p.first)
		{
			continue;
		}
		int v = p.second;
		for(int i = 0; i < G[v].size(); ++i)
		{
			SEdge e = G[v][i];
			if(d[e.To] > d[v] + e.Cost)
			{
				d[e.To] = d[v] + e.Cost;
				PQue.push(P(d[e.To], e.To));
			}
		}
	}
}

void solve()
{
	int E;
	while(cin >> E, E)
	{
		int V = 0;
		for(int i = 0; i < 10; ++i)
		{
			G[i].clear();
		}
		for(int i = 0; i < E; ++i)
		{
			int From, To, Cost;
			cin >> From >> To >> Cost;
			V = max(V, max(From, To));
			SEdge e1, e2;
			e1.To = To;
			e2.To = From;
			e1.Cost = e2.Cost = Cost;
			G[From].push_back(e1);
			G[To].push_back(e2);
		}
		++V;
		d.clear();
		d.resize(V);
		unsigned long long int Min = INF;
		int pos = 0;
		for(int i = 0; i < V; ++i)
		{
			Dijkstra(i);
			unsigned long long int sum = 0;
			for(int j = 0; j < V; ++j)
			{
				sum += d[j];
			}
			if(Min > sum)
			{
				Min = sum;
				pos = i;
			}
		}
		cout << pos << " " << Min << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
#define MAX_N 50
#define MAX 1e9 + 1
int d[MAX_N][MAX_N];
int n;

void floyd(int n) {
	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 main() {
	int a,b,c;
	int sum;
	int s;
	int max_s;
	while(scanf("%d",&n)&&n!=0) {
		sum = MAX;
		max_s = 0;
		for(int i=0; i<10; i++) {
			for(int j=0; j<10; j++) {
				d[i][j] = MAX;
			}
		}
		for(int i=0; i<10; i++) d[i][i] = 0;

		for(int i=0; i<n; i++) {
			scanf("%d%d%d",&a,&b,&c);
			max_s = max(max_s,max(a,b));
			d[a][b] = d[b][a] = c;
		}
		
		floyd(max_s);
		for(int i=0;i<=max_s;i++){
			int x =0;
			for(int j=0;j<=max_s;j++){
				x+=d[i][j];
			}
			if(sum>x){
				sum = x;
				s = i;
			} 
		}
		printf("%d %d\n",s,sum);
	}
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define INF   (1e9+7)
#define MAX_V (10)
#define MAX_E (45)
#define MAX_C (100)

int V, E;
int D[MAX_V][MAX_V];

void warshall_floyd() {
  for (size_t u = 0; u < V; u++)
    for (size_t v = 0; v < V; v++)
      for (size_t w = 0; w < V; w++) D[u][v] = D[v][u] = min(D[u][v], D[u][w] + D[w][v]);
}

void solve() {
  int ans_c, ans_d = INF;

  warshall_floyd();

  for (size_t v = 0; v < V; v++) {
    int cost = 0;
    for (size_t u = 0; u < V; u++) cost += (D[u][v] < INF)? D[u][v]: 0;
    if (cost < ans_d) {
      ans_c = v;
      ans_d = cost;
    }
  }

  printf("%d %d\n", ans_c, ans_d);
}

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

    for (size_t u = 0; u < MAX_V; u++)
      for (size_t v = 0; v < MAX_V; v++) D[u][v] = (u == v)? 0: INF;

    V = 0;
    for (size_t i = 0; i < E; i++) {
      int v, u, cost;
      scanf("%d %d %d", &u, &v, &cost);
      D[u][v] = D[v][u] = cost;
      V = max(V, (max(u, v)));
    }
    V++;

    solve();
  }

  return 0;
}

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;
    }
}