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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; 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;
			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<m;i++){
      for(int j =0;j<m;j++){
        for(int k = 0;k<m;k++){
          if(T[j][k]>T[j][i]+T[i][k]){
            T[j][k]=T[j][i]+T[i][k];
          }
        }
      }
    }
    int anstown,anstime=INF;
    for(int i =0;i<m;i++){
      int sumtime=0;
      for(int j = 0;j<m;j++){
        sumtime+=Time[i][j];
      }
      if(anstime>sumtime){
        anstown = i;
        anstime = sumtime;
      }
    }
    cout << anstonw <<" "<<anstime<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 100000000;
using namespace std;

void warshallFloyd(int m[50][50], int n){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
            }
        }
    }
}

int main(){
    int n;
    while(cin >> n, n){
        map<int, int> t;
        int m[50][50];
        int ans[2];
        ans[1] = INF;

        rep(i,50) rep(j,50) m[i][j] = INF;
        rep(i,50) m[i][i] = 0;
        rep(i,n){
            int a, b , c;
            cin >> a >> b >> c;
            m[a][b] = m[b][a] = c;
            t[a] = 1;
            t[b] = 1;
        }

        warshallFloyd(m, n);

        for(auto i = t.begin(); i != t.end(); i++){
            int sum = 0;
            for(auto j = t.begin(); j != t.end(); j++){
                sum+=m[i->first][j->first];
                //show(sum)
            }
            if(sum < ans[1] || (sum == ans[1] && ans[0] > i->first)){
                ans[0] = i->first;
                ans[1] = sum;
            }
        }
        cout << ans[0] << ' ' << ans[1] << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <utility>
using namespace std;

typedef long long ll;

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


int d[20][20];
int cost[20][20];
int n;
int numTown;
int t;
void show(){
  for(int i=0;i<t;i++){
    for(int j=0;j<t;j++){
      printf("%10d ",cost[i][j]);
    }
    cout<<endl;
  }
  cout<<endl;
}

void solve(){
  for(int i=0;i<t;i++)for(int j=0;j<t;j++)cost[i][j]=d[i][j];
  for(int k=0;k<t;k++){
    for(int i=0;i<t;i++){
      for(int j=0;j<t;j++){
	if(i==j||i==k||j==k)continue;
	cost[i][j]=cost[j][i]=min(cost[i][j],cost[i][k]+cost[k][j]);
	//	show();
      }
    }
  }
  int ans=INT_MAX;
  int p=0;
  for(int i=0;i<t;i++){
    int sum=0;
    for(int j=0;j<t;j++){
      sum+=cost[i][j];
    }
    if(ans>sum){
      ans=sum;
      p=i;
    }
  }
  cout<<p<<" "<<ans<<endl;

}

int main(void){
  
  while(cin>>n,n){
    t=0;
    for(int i=0;i<22;i++){
      for(int j=0;j<22;j++){
	if(i==j)d[i][j]=0;
	else d[i][j]=10000000;
      }
    }
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b>>c;
      d[a][b]=d[b][a]=c;
      t=max(t,max(a+1,b+1));
    }
    solve();
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    long long int d[10][10];
    int m=0;
    for(int i=0; i<10; i++){
      for(int j=0; j<10; j++){
	if(i == j) d[i][j] = 0;
	else d[i][j] = 1000000000;
      }
    }
    for(int i=0,a,b,c; i<n; i++){
      cin >>a>>b>>c;
      d[a][b] = c;
      d[b][a] = c;
      m = max(m,max(a,b));
    }
    for(int i=0; i<=m; i++) for(int j=0; j<=m; j++) for(int k=0; k<=m; k++) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    long long int ans,cost=-1;
    for(int i=0,t; i<=m; i++){
      t = 0;
      for(int j=0; j<=m; j++) t+=d[i][j];
      if(cost>t || cost == -1){cost = t;ans = i;}
    }
    cout <<ans<<" "<<cost<<endl;
  }
  return 0;
}

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

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

const int INF = 100001;

int d[100][100];

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

        rep(i, 10) {
            rep(j, 10) {
                d[i][j] = (i != j ? INF : 0);
            }
        }

        int m = 0;

        rep(i, n) {
            int a, b, cost;
            cin >> a >> b >> cost;
            m = max(m, max(a, b));
            d[a][b] = d[b][a] = cost;
        }

        m++;

        rep(i, m) {
            rep(j, m) {
                rep(k, m) {
                    d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
                }
            }
        }

        int ansd = 10000000, ansi;
        rep(i, m) {
            int sum = 0;
            rep(j, m) {
                sum += d[i][j];
            }
            if(sum < ansd) {
                ansd = sum;
                ansi = i;
            }
        }
        cout << ansi << ' ' << ansd << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>

const int MAX_V = 10, INF = 1 << 24;
int V;
int d[MAX_V], used[MAX_V], cost[MAX_V][MAX_V];

void dijkstra(int s){
	std::fill(d, d+MAX_V, INF);
	std::fill(used, used+MAX_V, 0);

	d[s] = 0;

	while(true){
		int v = -1;
		for(int u=0;u<V;u++){
			if(!used[u] && (v == -1 || d[u] < d[v])){
				v = u;
			}
		}

		if(v == -1){
			break;
		}

		used[v] = 1;
		for(int u=0;u<V;u++){
			d[u] = std::min(d[u], d[v] + cost[v][u]);
		}
	}
}

int getCost(int s){
	dijkstra(s);
	int res = 0;
	for(int i=0;i<V;i++){
		if(i != s){
			res += d[i];
		}
	}

	return res;
}

int main(){
	int n = 0;
	while(std::cin >> n, n){
		for(int i=0;i<MAX_V;i++){
			std::fill(cost[i], cost[i]+MAX_V, INF);
		}
		V = 0;

		for(int i=0;i<n;i++){
			int a, b, c;
			std::cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			V = std::max(V, std::max(a+1, b+1));
		}

		int res = INF, town = 0;
		for(int i=V-1;i>=0;i--){
			int v = getCost(i);
			if(v < res){
				res = v;
				town = i;
			}
		}
		std::cout << town << " " << res << std::endl;
	}
}