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 <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using ll = long long;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int n, maxcity = 0, d[12][12], sum[12], ans = INF, anstown;

int main() {
    cin >> n;
    for (int i = 0; i <= 11; i++) {
        for (int j = 0; j <= 11; j++) {
            if (i == j)d[i][j] = 0;
            else d[i][j] = INF;
        }
    }
    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
        maxcity = max(maxcity, b);
    }
    for (int k = 0; k <= maxcity; k++) {
        for (int i = 0; i <= maxcity; i++) {
            for (int j = 0; j <= maxcity; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    for (int i = 0; i <= maxcity; i++) {
        for (int j = 0; j <= maxcity; j++) {
            sum[i] += d[i][j];
        }
    }
    for (int i = 0; i <= maxcity; i++) {
        if (ans > sum[i]) {
            ans = sum[i];
            anstown = i;
        }
    }
    cout << anstown << ' ' << ans << endl;
    return 0;
}

C++: #include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

int INF=1e2;
int dist[15][15];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  while(cin>>n,n){
    fill(dist[0],dist[0]+15*15,INF);
    int m=0,a,b,d;
    rep(i,n){
      cin>>a>>b>>d;
      dist[a][b]=dist[b][a]=min(dist[a][b],d);
      m=max({m,a,b});
    }
    ++m;
    rep(i,m) dist[i][i]=0;
    rep(k,m) rep(i,m) rep(j,m)
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

    pii re=pii(INF,-1);
    rep(i,m){
      int sum=0;
      rep(j,m) sum+=dist[i][j];
      re=min(re,pii(sum,i));
    }
    //rep(i,m){rep(j,m)cout<<dist[i][j]<<",";cout<<endl;}
    cout<<re.Y<<" "<<re.X<<endl;
  }
  return 0;
}

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

int n;
int town[10][10];

void solve(){
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			for(int l=0; l<10; l++){
				int dis = town[j][i]+town[i][l];
				if(dis<town[j][l])
					town[j][l] = dis;
			}
		}
	}
	int ans=0,t[10]={0};
	for(int i=0; i<10; i++){
		for(int k=0; k<10; k++)
			t[i] += town[i][k];
		if(t[ans] > t[i])
			ans = i;
	}
	cout << ans << ' ' << t[ans]%1000000 << endl;
}

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		for(int i=0; i<10; i++)
			for(int k=0; k<10; k++){
				town[i][k] = 1000000;
				if(i==k)
					town[i][k] = 0;
			}
		for(int i=0; i<n; i++){
			int a,b,c;
			cin >> a >> b >> c;
			town[a][b] = c;
			town[b][a] = c;
		}
		solve();
	}
}

C++: #include<stdio.h>
#include<algorithm>
const int N =11;
const int inf=10000000;
using namespace std;
int d[N][N],V;
void warshall_floyd(void)
{
	for(int k=0;k<=V;k++)
	{
		for(int i=0;i<=V;i++)
		{
			for(int j=0;j<=V;j++)
			d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		}
	}
	return ;
}
void init(void)
{
	for(int i=0;i<N;i++)
	for(int j=0;j<N;j++)
        if(i!=j)
        d[i][j]=inf;
}
int main(void)
{
	int n;
	while(scanf("%d",&n)==1)
	{
		if(n==0)
		break;
		init();
		int s,e,c;
		V=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",&s,&e,&c);
			d[s][e]=d[e][s]=c;
			V=max(s,e);
		}
		warshall_floyd();
		int ans=inf;
		int sum=0;
		int id=0;
		for(int i=0;i<=V;i++)
		{
			sum=0;
			for(int j=0;j<=V;j++)
			sum+=d[i][j];
			if(sum<ans)
			{
				ans=sum;
				id=i;
			}
		}
		printf("%d %d\n",id,ans);
	}
	return 0;
}