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>

#define inf 1000000000

using namespace std;

int main(){
	while(1){
		int n;
		int in1[100];
		int in2[100];
		int in3[100];
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>in1[i]>>in2[i]>>in3[i];
		}
		int maxi=0;
		for(int i=0;i<n;i++){
			maxi=max(maxi,in1[i]);
			maxi=max(maxi,in2[i]);
		}
		
		
		int m=maxi+1;
		
		int C[100][100];
		for(int i=0;i<100;i++){
			for(int j=0;j<100;j++){
				C[i][j]=inf;
			}
		}
		for(int i=0;i<n;i++){
			C[in2[i]][in1[i]]=C[in1[i]][in2[i]]=in3[i];
		}
		
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					C[i][j]=min(C[i][j],C[i][k]+C[k][j]);
				}
			}
		}
		
		
		int maxo;
		int maxn=inf;
		int ans[100];
		for(int i=0;i<m;i++){
			ans[i]=0;
			for(int j=0;j<m;j++){
				ans[i]+=C[i][j];
			}
			ans[i]-=C[i][i];
			if(maxn>ans[i]){
				maxn=ans[i];
				maxo=i;
			}
		}
		
		printf("%d %d\n",maxo,maxn);
	}
}

C++: #include <iostream>
#define INFINITY (1 << 30)
#define MAX_N 10

using namespace std;

int n,road[MAX_N][MAX_N] = {},d[MAX_N][MAX_N] = {};
int main() {
  int temp1,temp2,temp3,city ,alt,mincity ,costtime= INFINITY ,cost ;

  while(1){
      cin >> n;
    if(n == 0) break;
    city = mincity = 0; costtime = INFINITY;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2>>temp3;
      road[temp1][temp2] = temp3;
      road[temp2][temp1] = temp3;
      if(city < temp1|| city < temp2)  {city = (temp1 > temp2)?  temp1: temp2; }
    }
    //cout << city <<endl;
    city++;

    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j < city; ++j) {
        if(i != j ) d[i][j] = INFINITY;
        if (road [i][j] !=0) d[i][j] =road[i][j];
      }
    }




    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j <city ; ++j) {
        for (int k = 0; k < city; ++k) {
          if(d[k][j] != INFINITY){
            alt = d[i][k]+ d[k][j];
            if (alt < d[i][j]) d[i][j] = alt;
          }

        }

      }
    }

    for (int i = 0; i < city; ++i) {
        cost =0;
      for (int j = 0; j < city ; ++j) {
        cost += d[i][j];
        //cout << d[i][j]<<" ";
      }
      //cout<<endl;
      if (costtime > cost) {costtime = cost;mincity = i;}
    }
    cout<< mincity << " "<<costtime<<endl;

  }


  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
const int INF=(1<<21);
int main(){

  int n;
  int town[11][11];
  int a,b,c;
  int min_total=INF;
  int min_town=0;
  int s[11];

  while(cin>> n,n){
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
	town[i][j]=(i==j)?0:INF;
      }
    }
 
    int v=0;
    for(int i=0;i<n;i++){
    cin>> a>> b>> c;
    town[a][b]=c;
    town[b][a]=c;
    v=max(max(v,a),b);
  }

    for(int i=0;i<=v;i++){
      for(int j=0;j<=v;j++){
	for(int k=0;k<=v;k++){
	  town[j][k]=min(town[j][k],town[j][i]+town[i][k]);
	}
      }
    }

    for(int i=0;i<=v;i++){
      int total=0;
      for(int j=0;j<=v;j++){
	total+=town[i][j];
      }
      s[i]=total;
      min_total=min(min_total,total);
    }
    for(int i=0;i<=v;i++){
      if(s[i]==min_total){
	cout<< i<< ' ';
	cout<< min_total<< endl;
	break;
      }
    }
  }
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF=999999;
const int maxx=11;
int ma[maxx][maxx];
 int n,m;

void init()
{
   for(int i=0;i<maxx;i++)
        for(int j=0;j<maxx;j++)
            if(i!=j)
            ma[i][j]=INF;

}

int main()
{




    while(~scanf("%d",&n)&&n)
    {
        init();
        m=0;
        for(int i=0;i<n;i++)
        {
            int a,b,c;
            scanf("%d %d %d",&a,&b,&c);
            ma[a][b]=ma[b][a]=c;
            m=max(m,max(a,b)+1);
        }



        for(int i=0;i<m;i++)
            for(int j=0;j<m;j++)
                for(int k=0;k<m;k++)
                    ma[j][k]=min(ma[j][k],ma[j][i]+ma[i][k]);



        int ans=INF;int k;
        for(int i=0;i<m;i++)
        {
            int sum=0;
            for(int j=0;j<m;j++)
                if(ma[i][j]!=INF)
                    sum+=ma[i][j];
            if(sum<ans)
            {
                k=i;
                ans=sum;
            }

        }


        printf("%d %d\n",k,ans);
    }
}

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}
    for(int i =0;i<m;i++){
      for(int j =0;j<m;j++){
        for(int k = 0;k<m;k++){
          if(T[j][k]>T[j][i]+T[i][k]){
            T[j][k]=T[j][i]+T[i][k];
          }
        }
      }
    }
    int anstown,anstime=INF;
    for(int i =0;i<m;i++){
      int sumtime=0;
      for(int j = 0;j<m;j++){
        sumtime+=T[i][j];
      }
      if(anstime>sumtime){
        anstown = i;
        anstime = sumtime;
      }
    }
    cout << anstown <<" "<<anstime<<endl;
  }
  return 0;
}