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<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int N=11;

int mp[N][N];


int bfs(int n,int p){
  vector<int> time(n);
  queue<int> que;
  rep(i,n)time[i]=INF;
  time[p]=0;
  que.push(p);
  int u;
  while(!que.empty()){
    u=que.front(),que.pop();
    rep(i,n){
      if(time[i]>time[u]+mp[u][i]){
        time[i]=time[u]+mp[u][i];
        que.push(i);
      }
    }
  }
  int sum=0;
  rep(i,time.size())sum+=time[i];
  return sum;
}

signed main(){
  int n;
  while(cin>>n,n!=0){ 
    rep(i,N)rep(j,N) mp[i][j]=(i==j?0:INF);
    int machi[N]={};
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      mp[a][b]=mp[b][a]=c;
      machi[a]++;
      machi[b]++;
    }
    int c=0;
    rep(i,N){
      if(machi[i]>0)c++;
    }
    int minsum=INF,city;
    rep(i,n){
      int tmp=bfs(c,i);
    
      if(minsum>tmp){
        minsum=tmp;
        city=i;
      }
    }
    cout<<city<<' '<<minsum<<endl;

  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>  
#include<math.h>  
  
//#include<map>   
//#include<set>
#include<deque>  
#include<queue>  
#include<stack>  
#include<bitset> 
#include<string>  
#include<iostream>  
#include<algorithm>  
using namespace std;  
  
#define ll long long  
#define INF 0x3f3f3f3f  
#define clean(a,b) memset(a,b,sizeof(a))// 水印 
#define mod 1000000


int shuzu[15][15];
int shuaxin[15];
bool biaoji[15];
int maxx[15];
int n;

void prime(int x)
{
	clean(biaoji,0);
	clean(shuaxin,INF);
	shuaxin[x]=0;
	for(int i=0;i<n;++i)
	{
		int can=-1;
		int min=INF;
		for(int j=0;j<n;++j)
		{
			if(biaoji[j]==0&&shuaxin[j]<min)
			{
				can=j;
				min=shuaxin[j];
			}
		}
		if(can==-1)
			break;
		biaoji[can]=1;
		for(int j=0;j<n;++j)
		{
			if(biaoji[j]==0&&shuzu[can][j]+shuaxin[can]<shuaxin[j])
				shuaxin[j]=shuzu[can][j]+shuaxin[can];
		}
	}
}

int main()
{
	int t;
	while(cin>>t&&t!=0)
	{
		n=0;
		clean(shuzu,INF);
		for(int i=0;i<t;++i)
		{
			int s,e,l;
			cin>>s>>e>>l;
			shuzu[s][e]=l;
			shuzu[e][s]=l;
			n=n>s?n:s;
			n=n>e?n:e;
		}
		n++;
		for(int i=0;i<n;++i)
			shuzu[i][i]=0;
		clean(maxx,0);
		for(int i=0;i<n;++i)
		{
			prime(i);
//			for(int j=0;j<n;++j)
//				cout<<shuaxin[j]<<" ";
//			cout<<endl;
			for(int j=0;j<n;++j)
				maxx[i]=maxx[i]+shuaxin[j];
		}
		int res=0,resl=maxx[0];
		for(int i=0;i<n;++i)
		{
			if(maxx[i]<resl)
			{
				resl=maxx[i];
				res=i;
			}
		}
		cout<<res<<" "<<resl<<endl;
	}
	
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
typedef pair<int,int> P;

#define INF 1000000
struct road{int to,cost;};

int main(){
  while(1){
    vector<road> roads[10];
    int d[10];
    int n,m;

    cin >> n;
    if(!n)break;
    m = 0;
    for(int i=0;i<n;i++){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      if(m<x||m<y){
        m = max(x,y);
      }
      roads[x].push_back((road){y,z});
      roads[y].push_back((road){x,z});
    }
    m++;

    int minIndex;
    int mini = INF;
    for(int i=0;i<m;i++){
      priority_queue<P, vector<P>, greater<P> > que;
      que.push(P(0,i));
      fill(d,d+m,INF);
      d[i] = 0;
      while(que.size()){
        P p = que.top(); que.pop();
        int dist = p.first;
        int pos = p.second;
        if(d[pos]<dist) continue;
        for(int j=0;j<roads[pos].size();j++){
          int to = roads[pos][j].to;
          int cost = roads[pos][j].cost;
          if(d[to]>d[pos]+cost){
            d[to] = d[pos] + cost;
            que.push(P(d[to],to));
          }
        }
      }
      int sum = 0;
      for(int j=0;j<m;j++){
        //printf("%3d%c",d[j],j==m-1?'\n':' ');
        sum += d[j];
      }
      if(mini>sum){
        mini = sum;
        minIndex = i;
      }
    }
    cout << minIndex << " " << mini << 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=1e7;
int N;
int A,B,C;
vector<edge>X[10];
int d[10];
int cou;
int main()
{
	while(true){

		for(int i=0;i<=cou;i++)X[i].clear();
		int ans1=0,ans2=1e9;
		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;
}

C++: #include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
const int inf = 999999999;
int main(){
	int n,a,b,c;
	while(cin >> n, n) {
		int cost[10][10] = {};
		rep(i,10) {
			rep(j,10) {
				if(i==j)continue;
				cost[i][j] = inf;
			}
		}
		int max = 0;
		rep(i,n) {
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			if(max < a) max = a;
			if(max < b) max = b;
		}

		rep(i,max+1) {
			rep(j,max+1) {
				rep(k,max+1) {
					int len = cost[i][j] + cost[j][k];
					if(len < cost[i][k]) {
						cost[i][k] = len;
					}
				}
			}
		}
		int min = inf, rmin = -1;
		rep(i,max+1) {
			int ret = 0;
			rep(j,max+1) {
				ret += cost[i][j];
			}
			if(min > ret) {
				min = ret;
				rmin = i;
			}
		}
		cout << rmin << " " << min << endl;
	}
	return 0;
}