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>
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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int sum(const vi& a)
{
	return accumulate(allof(a),0);
}

int main()
{
	for(int m;cin>>m,m;){
		int n;
		vvi dist;
		{
			vi a(m),b(m),w(m);
			rep(i,m) cin>>a[i]>>b[i]>>w[i];
			n=max(*max_element(allof(a)),*max_element(allof(b)))+1;
			dist.assign(n,vi(n,1<<29));
			rep(i,m)
				dist[a[i]][b[i]]=dist[b[i]][a[i]]=w[i];
			rep(i,n)
				dist[i][i]=0;
		}
		
		rep(k,n) rep(i,n) rep(j,n)
			dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		
		int res=0;
		rep(i,n)
			if(sum(dist[i])<sum(dist[res]))
				res=i;
		cout<<res<<" "<<sum(dist[res])<<endl;
	}
	
	return 0;
}

C++: /*
靠，真想自己一个大嘴巴，一个比?大小的函数都尼?写?偏了
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define MAXVAL 999999999;
using namespace std;

int dataSet[46][46];
int resultSet[46];
int N;
int result[46];


void Find_Value (int m)
{
	memset(result,0,sizeof(resultSet));
	for (int k=0;k<=m;k++)
	{
		for (int i=0;i<=m;i++)
		{
			for (int j=0;j<=m;j++)
			{
				dataSet[i][j] =  min(dataSet[i][j],dataSet[i][k] + dataSet[k][j]);
			}
		}
	}
}

int main ()
{
	while (cin>>N && N!=0)
	{
		for (int i=0;i<=15;i++)
		{
			for (int j=0;j<=15;j++)
			{
				if ( i == j)
				{
					dataSet[i][j] = 0;
				}
				else
				{
					dataSet[i][j] = 999999;
				}
			}
		}
		int m = 0;
		for (int i=0;i<N;i++)
		{
			int x,y,value;
			cin>>x>>y>>value;
			dataSet[x][y] = dataSet[y][x] = min(dataSet[x][y],value);
			m = max(max(m,x),y);	
		}
		Find_Value (m);
		int ans =  999999;
		int every_total = 0;
		int Find_pos = 0;
		for (int i=0;i<=m;i++)
		{
			every_total = 0;
			for (int j=0;j<=m;j++)
			{
				if (dataSet[i][j] !=  999999)
				{
					every_total += dataSet[i][j];
				}
			}
			if (ans > every_total)
			{
				Find_pos = i;
				ans = every_total;
			}
		}
		cout<<Find_pos<<" ";
		cout<<ans<<endl;

	}
	return 0;
}

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

#define NONE INT_MAX>>1
vector< vector<int> > WarshallFloyd(vector< vector<int> >A)
{
  for(int k=0;k<A.size();k++)
    for(int i=0;i<A.size();i++)
      for(int j=0;j<A.size();j++)
        A[i][j]=min(A[i][j],A[i][k]+A[k][j]);
  return A;
}

int main()
{
  int n,N;
  int a,b,c;
  while(cin>>n,n){
    vector< vector<int> > m(10,vector<int>(10,4000));
    N=0;
    for(int i=0;i<10;i++)m[i][i]=0;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      m[a][b]=m[b][a]=c;
      N=max(N,max(a,b));
    }
    N++;
    m=WarshallFloyd(m);

    int ans1=0;
    int ans2=INT_MAX;
    for(int i=0;i<N;i++){
      int sum=0;
      for(int j=0;j<N;j++){
	sum+=m[i][j];
      }
      if(ans2>sum){
	ans1=i;
	ans2=sum;
      }
    }
    cout<<ans1<<" "<<ans2<<endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
struct edge{int to;int cost;};
typedef pair<int,int> P;
const int Inf=1e8;
int N;
int A,B,C;
vector<edge>X[10];
int d[10];
int cou;
int main()
{
	while(true){

		int ans1=0,ans2=Inf;
		cou=0;
		scanf("%d",&N);
		if(N==0)break;
		for(int i=0;i<N;i++){
			scanf("%d%d%d",&A,&B,&C);
			edge e1={B,C};
			X[A].push_back(e1);
			edge e2={A,C};
			X[B].push_back(e2);
			cou=max(cou,max(A,B));
		}
		for(int s=0;s<=cou;s++){
			for(int i=0;i<=cou;i++)d[i]=Inf;
			d[s]=0;
			priority_queue<P, vector<P>, greater<P> > que;
			que.push(make_pair(0,s));
			while(!que.empty()){
				P p=que.top();que.pop();
				int v=p.second;
				if(d[v]<p.first)continue;
				for(int i=0;i<X[v].size();i++){
					edge e=X[v][i];
					if(d[e.to]>d[v]+e.cost){
						d[e.to]=d[v]+e.cost;
						que.push(make_pair(d[e.to],e.to));
					}
				}
			}
			//for(int i=0;i<=cou;i++)printf("%d %d %d\n",s,i,d[i]);
			int sum=0;
			for(int i=0;i<=cou;i++)sum+=d[i];
			if(ans2>sum){
				ans2=sum;
				ans1=s;
			}
		}
		printf("%d %d\n",ans1,ans2);
	}
	return 0;
}