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 <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=1e3;
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>
#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>
const int INF = 100000000, mod = 1000000007;
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<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, a, b, c, dp[111][111], eki, an[3], ans;
	while (1) {
		eki = 0;
		cin >> n;
		if (n == 0) {
			goto a;
		}
		for (int i = 0; i <= 88; i++) {
			for (int z = 0; z <= 88; z++) {
				dp[i][z] = 9999999;
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> a >> b >> c;
			dp[a][b] = c;
			dp[b][a] = c;
			eki = max(eki, max(a, b));
		}
		for (int i = 0; i <= eki; i++) {
			dp[i][i] = 0;
		}
		for (int i = 0; i <= eki; i++) {
			for (int z = 0; z <= eki; z++) {
				for (int m = 0; m <= eki; m++) {
					dp[i][z] = min(dp[i][z], dp[i][m] + dp[m][z]);
				}
			}
		}
		ans = 0;
		an[2] = 9999999;
		for (int i = eki; i >= 0; i--) {
			ans = 0;
			for (int z = 0; z <= eki; z++) {
				if (i == z) {

				}
				else {
					ans += dp[i][z];
				}
			}
			if (an[2] >= ans) {
				an[2] = ans;
				an[1] = i;
			}
		}
		cout << an[1] << " " << an[2] << endl;
	}
a:;
}

C++: #include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <functional>
#include <complex>
#include <cmath>
#include <vector>
#include <climits>
#include <set>
using namespace std;

int main()
{	
	int n;
	int g[10][10];

	while (cin >> n, n) {
		
		set<int> pat;
		fill((int *)g, (int *)(g + 10), INT_MAX / 2);
		 
		for (int i = 0; i < n; i++) {
			int to, from, cost;
			cin >> to >> from >> cost;
			pat.insert(to);
			pat.insert(from);
			g[to][from] = cost;
			g[from][to] = cost;
		}
		
		int m = pat.size();
		
		for (int k = 0; k < m; k++) {
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < m; j++) {
					if (i == j) continue;
					g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
				}
			}
		}
		
		int r = INT_MAX, index;
		for (int i = 0; i < m; i++) {
			int sum = 0;
			for (int j = 0; j < m; j++) {
				if (i == j) continue;
				sum += g[i][j];
			}
			if (r > sum) {
				r = sum;
				index = i;
			}
		}
		
		cout << index << " " << r << endl;
	}
		
	return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
void f(int a[][10],int b[],int c,int e,int n,int t){
  int i;
  if(c==e){
    if(b[c]==-1||b[c]>t)
      b[c]=t;
  }else if(b[c]==-1||b[c]>t){
    b[c]=t;
    for(i=0;i<n;i++){
      if(a[c][i]!=-1)
	f(a,b,i,e,n,t+a[c][i]);
    }
  }
  return;
}    
int main(){
  int i,j;
  int z[10][10],a[10][10],b[10],bmn,tmn,sum,n,m;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    memset(a,-1,sizeof(a));
    m=0;
    for(i=0;i<n;i++){
      int p,q,r;
      cin>>p>>q>>r;
      a[p][q]=r;
      a[q][p]=r;
      m=max(max(m,p),q);
    }
    m++;
    for(i=0;i<m-1;i++){
      for(j=i+1;j<m;j++){
	memset(b,-1,sizeof(b));
	f(a,b,i,j,m,0);
	z[i][j]=b[j];
	z[j][i]=b[j];
      }
    }
    tmn=-1;
    for(i=0;i<m;i++){
      sum=0;
      for(j=0;j<m;j++){
	if(i!=j)
	  sum+=z[i][j];
      }
      if(tmn==-1||tmn>sum){
	tmn=sum;
	bmn=i;
      }
    }
    cout<<bmn<<" "<<tmn<<endl;
  }
  return 0;
}