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<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vector<vi> v(100,vi(100));
    rep(i,100)rep(j,100)
      if(i==j)v[i][j]=0;
      else v[i][j]=INF;
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      v[a][b]=c;
      v[b][a]=c;
    }
    rep(k,100)rep(i,100)rep(j,100)
      v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
    int ans=INF;
    int num;
    rep(i,100)
      if(v[i][0]==INF)break;
    n=i;
    rep(i,n){
      int sum=0;
      rep(j,n)
        sum+=v[i][j];
      if(ans>sum){
        ans=sum;
        num=i;
      }
    }
    cout<<num<<" "<<ans<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

const int INF = 1<<20;
const int maxn = 15;
int d[maxn][maxn];
int E,V;

long long x[maxn];

void warshall_floyd(){
	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]);
}

int main(){
	while(scanf("%d",&E) && E){
		for(int i=0; i<maxn; i++)
			fill(d[i],d[i]+maxn,INF);

		for(int i=0; i<maxn; i++) d[i][i] = 0;

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

		warshall_floyd();

		memset(x,0,V*sizeof(int));
		int ans = INF, pos;
		for(int i=0; i<V; i++){
			for(int j=0; j<V; j++)
				x[i] += d[i][j];
			if(ans > x[i]){
				ans = x[i];
				pos = i;
			}
		}

		printf("%d %d\n",pos,ans);

			

	}
}

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

using namespace std;

int cost[10][10];
int N;
int nTown;

static const int INT_MAX = 1e6;

void init() {
	fill(cost[0], &cost[9][10], INT_MAX);
	for (int i = 0; i < 10; i++) {
		cost[i][i] = 0;
	}
	nTown = -1;
}

void solve() {
	for (int k = 0; k < nTown; k++) {
		for (int i = 0; i < nTown; i++) {
			for (int j = 0; j < nTown; j++) {
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
	int mn = INT_MAX, idx = -1;
	for (int t = 0; t < nTown; t++) {
		int sum = 0;
		for (int i = 0; i < nTown; i++) {
			sum += cost[t][i];
		}
		if (sum < mn) {
			idx = t, mn = sum;
		}
	}
	printf("%d %d\n", idx, mn);
}

int main() {
	while (scanf("%d ", &N) != EOF) {
		if (N == 0) {
			return 0;
		}
		init();
		for (int i = 0; i < N; i++) {
			int a, b, c;
			scanf("%d %d %d ", &a, &b, &c);
			cost[a][b] = c;
			cost[b][a] = c;
			nTown = max(a, max(b, nTown));
		}
		nTown++;
		solve();
	}	
}

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>
typedef long long ll;
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() {
    while (cin >> n,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 <bits/stdc++.h>
using namespace std;

const int MAX = 10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

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

        int E[MAX][MAX];
        for(int i = 0; i < MAX; i++){
            for(int j = 0; j < MAX; j++){
                if(i == j) E[i][j] = 0;
                else E[i][j] = 1e9;
            }
        }

        map<int, bool> mp;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            mp[a] = true;
            mp[b] = true;
            E[a][b] = c;
            E[b][a] = c;
        }
        
        for(int i = 0; i < MAX; i++){
            for(int j = 0; j < MAX; j++){
                for(int k = 0; k < MAX; k++){
                    E[j][k] = min(E[j][i] + E[i][k], E[j][k]);
                }
            }
        }

        int idx, cost = 1e9;
        for(int i = 0; i < MAX; i++){
            if(!mp[i]) continue;
            int tmp = 0;
            for(int j = 0; j < MAX; j++){
                if(mp[j]) tmp += E[i][j];
            }
            if(cost > tmp){
                idx = i;
                cost = tmp;
            }
        }

        cout << idx << ' ' << cost << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    int d[10][10],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] = 1000000;
      }
    }
    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]);
    int ans,cost=10000000;
    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 = t;ans = i;}
    }
    cout <<ans<<" "<<cost<<endl;
  }
  return 0;
}