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 IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

const int MAX_V = 1e5+10;
int V,E;
vector<edge> G[MAX_V];
int d[MAX_V];

void DS(int s) {
	priority_queue<P,vector<P>,greater<P>> que;
	for(int i = 0; i <= V; i++) d[i] = INF; d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (auto e : G[v]) {
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	vector<P> vvv;
	while(1){
		for(int i = 0; i < MAX_V; i++) G[i].clear();
		V = 0;
		cin >> E;
		if(E == 0) break;
		for(int i = 0; i < E; i++){
			int f,t,c;
			cin >> f >> t >> c;
			G[f].push_back({t,c});
			G[t].push_back({f,c});
			V = max({V,f,t});
		}
		E *= 2;
		V++;
		int a1 = -1,a2 = INF;
		for(int i = 0; i < V; i++){
			DS(i);
			int sum = 0;
			for(int j = 0; j < V; j++){
				if(d[j] != INF) sum += d[j];
			}
			if(sum < a2) {a1 = i,a2 = sum;};
		}
		vvv.push_back(P(a1,a2));

		//cout << a1 << " " << a2 << endl;
	}
	for(int i = 0; i  <vvv.size(); i++){
		cout << vvv[i].first << " " << vvv[i].second << endl;
	}

	return 0;
}

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

const int INF = 200;
const int town_max = 10;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int T[town_max][town_max];
		for(int i=0;i<town_max;i++){
			for(int j=0;j<town_max;j++){
				if(i==j)
					T[i][j] = 0;
				else
					T[i][j] = INF;
			}
		}

		int m = 0;	//頂点の数
		for(int i=0;i<n;i++){
			int a, b, c;	//町の番号は0から
			cin >> a >> b >> c;
			T[a][b] = T[b][a] = c;
			if(a+1>m)
				m = a+1;
			if(b+1>m)
				m = b+1;
		}

		for(int i=0;i<town_max;i++){
			for(int j=0;j<town_max;j++){
				for(int k=0;k<town_max;k++){
					if(T[j][k]>T[j][i]+T[i][k])
						T[j][k] = T[j][i]+T[i][k];
				}
			}
		}

		int T_sum[town_max];
		int T_min = INF*town_max;
		int town_min = -1;

		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				T_sum[i] += T[i][j];
			}
			if(T_sum[i]<T_min){
				T_min = T_sum[i];
				town_min = i;
			}
		}

		cout << town_min << " " << T_min << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <iterator>

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

using namespace std;

typedef pair<int,int> P;


struct edge
{
	int to;
	int cost;

	edge(int to,int cost) : to(to),cost(cost) {}
};


vector<edge> G[10];
int d[10];

void dijkstra(int s,int n)
{
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+n,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty())
	{
		P p = que.top();
		que.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] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main()
{
	int n;
	
	while(cin >> n && n)
	{
		vector<int> t;
		rep(i,n)
		{
			int a,b,c;
			cin >> a >> b >> c;

			G[a].push_back(edge(b,c));
			G[b].push_back(edge(a,c));

			vector<int>::iterator ite = find(t.begin(),t.end(),a);
			if(ite == t.end())
			{
				t.push_back(a);
			}

			ite = find(t.begin(),t.end(),b);
			if(ite == t.end())
			{
				t.push_back(b);
			}

		}

		P ans;
		ans.first = t[0];
		ans.second = INF;
		
		rep(i,t.size())
		{
			dijkstra(t[i],10);

			int sum = 0;

			rep(j,t.size()) sum += d[t[j]];

			if(ans.second > sum)
			{
				ans.first = i;
				ans.second = sum;
			}	
		}
		cout << ans.first << " " << ans.second << endl;
	}

	return 0;
	
}

C++: #include <iostream>

using namespace std;
int a, b, c, i, j, s, n, mi,  d[10][10], cost[10];

void dic(int ans[]) {
  for(s = 0; s < 10; s++) {
    for(i = 0; i < 10;i++) cost[i] = 100000000;
    int sum = 0, f[10] = {};
    cost[s] = 0;
    mi = s;
    for(i = 0; i < 10; i++) {
      f[mi] = 1;
      for(j = 0; j < 10; j++)  if(!f[j] && cost[j] > cost[mi] + d[mi][j]) cost[j] = cost[mi] + d[mi][j];
      int min = 200000000;
      for(j = 0; j < 10; j++)  if(!f[j] && min > cost[j])  min = cost[mi = j];
    }
    for(i = 0; i < 10; i++)  if(cost[i] != 100000000) sum += cost[i];
    //    cout << sum << endl;
    if(ans[1] > sum && sum != 0){
      ans[0] = s;
      ans[1] = sum;
    }
  }
}


int main() {
  while(cin >> n, n != 0) {
    for(i = 0; i < 10; i++)
      for(j = 0; j < 10; j++)  d[i][j] = 100000000;
    while(n--) {
      cin >> a >> b >> c;
      d[a][b] = d[b][a] = c;
    }
    int ans[2] = {100000000, 100000000};
    dic(ans);
    cout << ans[0] << ' ' << ans[1] << endl;
  }
  return 0;
}