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>
#define INFINITY 1000000
int main (){
    int minArr[50],minIndexArr[50];
    int count = 0;
    while (1)
    {
            
        int n = 0,m = 0;
        std::cin >> n;
        if(n == 0)break;

        int table[100][100];
        for (size_t i = 0; i < 100; i++)
        {
            for (size_t j = 0; j < 100; j++)
            {
                if(i==j){
                    table[i][j] = 0;
                }else{
                    table[i][j] = INFINITY;
                }
            }
            
        }
        
        for (size_t i = 0; i < n; i++)
        {
            int a,b,c;
            std::cin >> a >> b >> c;
            m = std::max(m,std::max(a+1,b+1));
            table[a][b] = c;
            table[b][a] = c;

        }

        for (size_t i = 0; i < m; i++)
        {
            for (size_t j = 0; j < m; j++)
            { 
                for (size_t k = 0; k < m; k++)
                {
                    table[i][j] = std::min(table[i][k] + table[k][j], table[i][j]);
                }
            }
        }
    
        int sum[100];
        for (size_t i = 0; i < m; i++)
        {
            for (size_t j = 0; j < m; j++)
            {
                sum[i] = 0; 
            }
        }
        for (size_t i = 0; i < m; i++)
        {
            for (size_t j = 0; j < m; j++)
            {
                sum[i] += table[i][j]; 
            }
        }
        int min = INFINITY,minIndex = 0;
        for (size_t i = 0; i < m; i++)
        {
            if(min>sum[i]){
                min = sum[i];
                minIndex = i;
            }
        }
        
        minIndexArr[count] = minIndex;
        minArr[count] = min;
        count++;
    }
    for (size_t i = 0; i < count; i++)
    {
        std::cout << minIndexArr[i] << " " << minArr[i] << std::endl;
    }
    
}

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

int main() {
  for(int tci = 0; ; tci++) {
    int m; scanf("%d", &m);
    if(m==0) break;
    int n = 0;
    int tbl[10][10];
    for(int i = 0; i < 10; i++)
      for(int j = 0; j < 10; j++)
        tbl[i][j] = i==j ? 0 : INT_MAX/2;
    for(int i = 0; i < m; i++) {
      int a,b,c; scanf("%d%d%d", &a, &b, &c);
      tbl[a][b] = tbl[b][a] = min(tbl[b][a],c);
      n = max(n,max(a+1,b+1));
    }
    for(int k = 0; k < n; k++)
      for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
          tbl[i][j] = min(tbl[i][j], tbl[i][k]+tbl[k][j]);
    pair<int,int> result(INT_MAX,INT_MAX);
    for(int i = 0; i < n; i++) {
      int sum = 0;
      for(int j = 0; j < n; j++) {
        sum += tbl[i][j];
      }
      result = min(result,make_pair(sum,i));
    }
    printf("%d %d\n", result.second, result.first);
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
long n,p[10][10],i,j,k,m,s,ii,ss;
while(cin>>n){
if(n==0)break;
for(i=0;i<10;i++)
for(j=0;j<10;j++)p[i][j]=p[j][i]=-1;
m=0;
for(s=k=0;k<n;k++){
cin>>i>>j;
cin>>p[i][j];
s+=p[i][j];
if(m<i)m=i;if(m<j)m=j;
}
s*=45;
m++;
for(i=0;i<10;i++){
p[i][i]=0;
for(j=0;j<10;j++)if(p[i][j]<0)p[i][j]=s;
}
for(k=0;k<m;k++)
for(i=0;i<m;i++)
for(j=0;j<m;j++)p[i][j]=p[j][i]=min(p[i][j],p[i][k]+p[k][j]);
for(ss=j=0;j<m;j++)ss+=p[0][j];ii=0;
for(i=0;i<m;i++){
for(s=j=0;j<m;j++)s+=p[i][j];
if(s<ss){ss=s;ii=i;}
}
cout<<ii<<" "<<ss<<endl;
}
return 0;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#define INF 100000000
typedef long long int lli;
using namespace std;

struct edge{int from,to,cost;};
int shortest_path(int s,int V,int E,vector<int> d,vector<edge> es){
	int result=0;
	for(int i=0; i<V; ++i) d[i]=INF;
	d[s]=0;
	while(true){
		bool update = false;
		for(int i=0; i<E; ++i){
			edge e=es[i];
			if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
			if(d[e.to]!=INF&&d[e.from]>d[e.to]+e.cost){
				d[e.from]=d[e.to]+e.cost;
				update=true;
			}
		}
		if(!update) break;
	}
	for(int i=0; i<V; ++i){
		result+=d[i];
	}
	return result;
}

int main(){
	int n;
	while(cin>>n&&n){
		vector<edge> es(n);
		int m=0;
		for(int i=0; i<n; ++i){
			int a,b,c;
			cin >> a >> b >> c;
			m=max(a,max(b,m));
			es[i].from=a;
			es[i].to=b;
			es[i].cost=c;
		}
		vector<int> d(m+1);
		int ans_d=INF;
		int ans_s;
		for(int i=m; i>=0; --i){
			int tmp=shortest_path(i,m+1,n,d,es);
			//cout << tmp << "\n";
			if(ans_d>tmp){
				ans_d=tmp;
				ans_s=i;
			}
		}
		cout << ans_s << " " << ans_d << "\n";
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const double PI=acos(-1.0);
int floyd[50][50],w[50][50];
bool exist[50];
int main()
{
	int n;
	while( cin>>n && n )
	{
		memset(w,INF,sizeof(w));
		memset(floyd,INF,sizeof(floyd));
		memset(exist,false,sizeof(exist));
		for(int i=0;i<n;i++)
		{
			int x,y,z;
			cin>>x>>y>>z;
			w[x][y]=w[y][x]=z;
			floyd[x][y]=floyd[y][x]=z;
			floyd[x][x]=floyd[y][y]=w[x][x]=w[y][y]=0;
			exist[x]=exist[y]=true;
		}
		for(int k=0;k<10;k++)
			for(int i=0;i<10;i++)
				for(int j=0;j<10;j++)
					floyd[i][j]=min(floyd[i][j],floyd[i][k]+w[k][j]);
		int minn=INF,ans=0;
		for(int i=0;i<10;i++)
			if( exist[i] )
			{
				int temp=0;
				for(int j=0;j<10;j++)
					if( exist[j] )
						temp+=floyd[i][j];
				if( temp<minn )
				{
					minn=temp;
					ans=i;
				}
			}
		cout<<ans<<" "<<minn<<endl;
	}
}