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 <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 200000000
int main()
{
	int e;
	while(cin >> e,e)
	{
		int i,j,k,s=INF,v=0,ans=INF;
		int d[10][10];
		int cost_count[10] = {0};
		for(i=0;i<10;i++)
		{
			for(j=0;j<10;j++)
			{
				d[i][j] = INF;
				if(i==j)
				{
					d[i][j] = 0;
				}
			}
		}
		for(i=0;i<e;i++)
		{
			scanf("%d %d %d",&i,&j,&k);
			v = max(v,max(i,j));
			d[i][j] = k;
			d[j][i] = k;
		}
		for(k=0;k<v;k++)
		{
			for(i=0;i<v;i++)
			{
				for(j=0;j<v;j++)
				{
					d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		for(i=0;i<v;i++)
		{
			int cost = 0;
			for(j=0;j<v;j++)
			{
				cost += d[i][j];
			}
			cost_count[i] = cost;
			ans=min(ans,cost_count[i]);

		}
		for(i=0;i<v;i++)
		{
			if(cost_count[i]==ans)
			{
				printf("%d %d\n",i,ans);
				break;
			}
		}
	}
	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(s=j=0;j<m;j++)s+=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<bits/stdc++.h>
#define F first
#define S second
#define INF (1<<30)
using namespace std;
typedef pair<int,long long> P;
typedef struct{
  vector<P> to;
  long long min;
}Node;
int n;
int m;
long long daikusutora(int s);
Node node[15];
main(){
  int a,b;
  long long c;
  while(1){
    m=0;
    scanf("%d",&n);
    if(n==0){
      break;
    }
    for(int i=0;i<10;i++){
      node[i].to.clear();
    }
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&a,&b,&c);
      m=max(m,a);
      m=max(m,b);
      node[a].to.push_back(P(b,c));
      node[b].to.push_back(P(a,c));
    }
    m++;
    long long mins=INF;
    int pos=0;
    for(int i=0;i<m;i++){
      long long cnt=0;
      cnt=daikusutora(i);
      //cout<<cnt<<endl;
      if(mins>cnt){
	mins=min(mins,cnt);
	pos=i;
      }
    }
    printf("%d %d\n",pos,mins);
  }
}
long long daikusutora(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  for(int i=0;i<m;i++){
    node[i].min=INF;
  }
  node[s].min=0;
  que.push(P(s,0));
  while(!que.empty()){
    P now=que.top();
    que.pop();
    int basyo=now.F;
    int nowcos=now.S;
    for(int i=0;i<node[basyo].to.size();i++){
      int nbasyo=node[basyo].to[i].F;
      int ncost=node[basyo].to[i].S;
      if(node[nbasyo].min>nowcos+ncost){
	node[nbasyo].min=nowcos+ncost;
	que.push(P(nbasyo,nowcos+ncost));
      }
    }
  }
  long long cnt=0;
  for(int i=0;i<m;i++){
    cnt+=node[i].min;
  }
  return cnt;
}

C++: #include<iostream>

#define TOWN_MAX 10
#define ROAD_MAX 45
#define INF 1000000000

int solve(int);

int main(int argc, char const* argv[]) {
    int n;

    while (true) {
        std::cin >> n;
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

int solve(int road_num) {
    int distances[TOWN_MAX][TOWN_MAX];

    for (int i = 0; i < TOWN_MAX; i++)
        for (int j = 0; j < TOWN_MAX; j++)
            distances[i][j] = (i == j) ? 0 : INF;

    for (int i = 0; i < road_num; i++) {
        int src, dest, cost;
        std::cin >> src >> dest >> cost;
        distances[src][dest] = cost;
        distances[dest][src] = cost;
    }

    for (int infix_road = 0; infix_road < road_num; infix_road++) {
        for (int begin_town = 0; begin_town < TOWN_MAX; begin_town++) {
            for (int end_town = 0; end_town < TOWN_MAX; end_town++) {
                distances[begin_town][end_town] = std::min(distances[begin_town][end_town],
                        distances[begin_town][infix_road] + distances[infix_road][end_town]);
            }
        }
    }

    int min_cost = INF;
    int min_cost_index = 0;
    for (int i = 0; i < TOWN_MAX; i++) {
        int sum_cost = 0;
        for (int j = 0; j < TOWN_MAX; j++) {
            if (distances[i][j] == INF) break;
            sum_cost += distances[i][j];
        }

        if (sum_cost < min_cost && sum_cost != 0) {
            min_cost       = sum_cost;
            min_cost_index = i;
        }
    }

    std::cout << min_cost_index << " " << min_cost << std::endl;

    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#define INF 10000
using namespace std;

struct edge {
    int from, to, cost;
};

edge es[100];
int d[11];
int n,maxV=0;

int shortest_path(int s){
    int sum=0;
    for(int i=0;i<maxV+1;i++){
        d[i] = INF;
    }
    d[s] = 0;
    while(1){
        bool update = false;
        for(int i=0;i<2*n;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(!update){
            break;
        }
    }
    for(int i=0;i<maxV+1;i++){
        if(d[i] != INF){
        	// cout << i << " " << d[i] << endl;
            sum += d[i];
        }
    }
    return sum;
}

int main(void){
    
    while(cin >> n && n){
    	maxV = 0;
        int a, b, c, tmp, min,sum2=100000;
        for(int i=0;i<n;i++){
            cin >> a >> b >> c;
            es[i].from = a;
            es[i].to = b;
            es[i].cost = c;

            es[i+n].from = b;
            es[i+n].to = a;
            es[i+n].cost = c;
            
            if(maxV < b){
           		maxV = b;
           	}
           	
        }
        //??????????????°?????????
        for(int i=0;i<maxV+1;i++){
            int tmp = shortest_path(i);
            // cout << tmp << endl;
            if(sum2 > tmp){
                sum2 = tmp;
                min = i;
            }
        }
        cout << min << " " << sum2 << endl;
    }
    return 0;
}