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>
using namespace std;

const int INF = 1000000000;

void WarshallFloyd(int d[10][10],int x){
	for(int k=0;k<x;k++){
		for(int i=0;i<x;i++){
			for(int j=0;j<x;j++){
				if(d[i][j]>d[i][k]+d[k][j]){
					d[i][j]=d[i][k]+d[k][j];
				}
			}
		}
	}
	return;
}

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;
			}
		}

		int A=INF,c;
		WarshallFloyd(T,10);
		for(int i=0;i<m;i++){
			int B=0;
			for(int j=0;j<m;j++){
				if(T[i][j]!=INF) B+=T[i][j];
			}
			if(A>B&&B!=0){
				A=B;
				c=i;
			}
		}
		
		cout<<c<<' '<<A<<endl;

	}

	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int map[15][15],n,i,j,k,a,b,c,o,ans[15],zans;
int main()
{
	while(1)
	{
		o=0;
		scanf("%d",&n);
		if(n==0)
			return 0;
		for(i=0;i<=10;i++)
		{
			for(j=0;j<=10;j++)
				map[i][j]=2147483647;
		}
		for(i=1;i<=n;i++)
		{
			scanf("%d %d %d",&a,&b,&c);
			o=max(a,o);
			o=max(b,o);
			map[a][b]=min(c,map[a][b]);
			map[b][a]=min(c,map[b][a]);
		}
		for(k=0;k<=o;k++)
		{
			for(i=0;i<=o;i++)
			{
				for(j=0;j<=o;j++)
				{
					if(map[i][k]!=2147483647&&map[k][j]!=2147483647)
					map[i][j]=min(map[i][j],map[i][k]+map[k][j]);
				}
			}
		}
		zans=0;
		for(i=0;i<=o;i++)
		{
			ans[i]=0;
			for(j=0;j<=o;j++)
			{
				if(i!=j)
				ans[i]=ans[i]+map[i][j];
			}
			if(ans[i]<ans[zans])
				zans=i;
		}
		printf("%d %d\n",zans,ans[zans]);
	}
}

C++: #include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
const int max_n = 15;
const int INF = 0x3f3f3f3f;
int dis[max_n][max_n];

/*********************************************************/

void floyd(int m){
    for(int k = 0; k <= m; ++k)
        for(int i = 0; i <= m; ++i)
            for(int j = 0; j <= m; ++j)
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}

int main(){
    ios::sync_with_stdio(false);
    for(int i = 0; i < max_n; ++i) fill(dis[i], dis[i] + max_n, INF), dis[i][i] = 0;
    while(cin >> n && n){
        int m = 0;
        while(n--){
            int x, y, d;
            cin >> x >> y >> d;
            m = max(m, x);
            m = max(m, y);
            dis[x][y] = dis[y][x] = d;
        }
        floyd(m);
        int ans = INF, index = 0;
        for(int i = 0; i <= m; ++i){
            int temp = 0;
            for(int j = 0; j <= m; ++j) temp += dis[i][j];
            if(temp < ans){
                ans = temp;
                index = i;
            }
        }
        cout << index << " " << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
struct edge{int to;int cost;};
typedef pair<int,int> P;
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;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <climits> 
#include <map>
using namespace std;
const int MAX_V = 1000; 
const int MAX_E = 2000; 
const int INF = 100000; 


struct E {
  int to, cost;
  E(int t, int c) : to(t), cost(c) {};
};

int v; 
vector<E> g[MAX_V]; 
int d[MAX_V]; 

bool bellmanford(int s)
{
  fill(d, d + v, INF);
  d[s] = 0;
  for(int k = 0; k < v; ++k){
    for(int j = 0; j < v; ++j){
      int from = j;
      for(int i = 0; i < g[from].size(); ++i){
	int to = g[from][i].to;
	int cost = g[from][i].cost;
	if(d[from] != INF && d[to] > d[from] + cost){
	  d[to] = d[from] + cost;
	  if(k == v - 1)return false;
	}
      }
    }
  }
  return true;
}
int main()
{
  for(;;){
    int gv, ge;
    cin >> ge;
    if(ge==0){return 0;}
    set<int> s;

    for(int i = 0; i < ge; ++i){
      int gs, gt, gd;
      cin >> gs >> gt >> gd;
      g[gs].push_back(E(gt,gd));
      g[gt].push_back(E(gs,gd));
      s.insert(gs);
      s.insert(gt);
    }

    gv=s.size();
    v = gv;

    vector<pair<int,int> > p(s.size());

    set<int>::iterator it= s.begin();

    int count=0;
    while(it!=s.end()){
      bellmanford(*it);
      int sum=0;
      for(int i=0;i<v;i++){sum+=d[i];}
      //cout << sum << ":" << *it << endl;
      p[count].first=sum;
      p[count].second=*it;
      it++;
      count++;
    }

    sort(p.begin(),p.end());
  
    //for(int i=0;i<p.size();i++)
    cout << p[0].second << " " << p[0].first << endl;
  }
  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)
#define inf 99999999
int main(){
	int n,a,b,c;
	int cost[64][64];
	while(cin >> n, n) {
		rep(i,64) {
			rep(j,64) {
				cost[i][j] = inf;
			}
		}
		int max = 0;
		rep(i,n) {
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			cost[a][a] = 0;
			cost[b][b] = 0;
			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[j][i] + cost[i][k];
					if(len < cost[j][k]) {
						cost[j][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;
}