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 <vector>
#include <algorithm>
#include <climits>

using namespace std;

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

		if(n == 0){
			break;
		}

		int* start = new int[n];
		int* goal = new int[n];
		int* cost = new int[n];

		for(int i = 0; i < n; i++){
			cin >> start[i] >> goal[i] >> cost[i];
		}

		int town = 0;

		for(int i = 0; i < n; i++){
			town = max(town, max(start[i], goal[i]));
		}

		town++;

		vector<vector<int> > dist(town, vector<int>(town, INT_MAX / 2));

		for(int i = 0; i < n; i++){
			dist[start[i]][goal[i]] = cost[i];
			dist[goal[i]][start[i]] = cost[i];
		}

		for(int i = 0; i < town; i++){
			dist[i][i] = 0;
		}


		for(int k = 0; k < town; k++){
			for(int i = 0; i < town; i++){
				for(int j = 0; j < town; j++){
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
		int* total = new int[town];
		int TOTAL = INT_MAX / 2;
		int S = 0;

		for(int i = 0; i < town; i++){
			total[i] = 0;
		}

		for(int i = 0; i < town; i++){
			for(int j = 0; j < town; j++){
				total[i] += dist[i][j];
			}
			if(TOTAL > total[i]){
				TOTAL = min(TOTAL, total[i]);
				S = i;
			}
		}

		cout << S << " " << TOTAL << endl;
		delete [] start;
		delete [] goal;
		delete [] cost;
		delete [] total;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXC 12
int N,dis[MAXC][MAXC];
int main()
{
	int m;
	while(~scanf("%d",&N)&&N)
	{
		memset(dis,0x3F,sizeof dis);
		for(int i=1;i<=9;i++)
			dis[i][i]=0;
		m=0;
		for(int i=1,a,b,c;i<=N;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			m=max(m,max(a,b));
			dis[a][b]=dis[b][a]=c;
		}
		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 mn=0x7FFFFFFF,id,sum;
		for(int i=0;i<=m;i++)
		{
			sum=0;
			for(int j=0;j<=m;j++)
				sum+=dis[i][j];
			if(mn>sum)
			{mn=sum;id=i;}
		}
		printf("%d %d\n",id,mn);
	}
	return 0;
}

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 ;
  long long int costtime ,cost;
  while(1){
    road[MAX_N][MAX_N] ={};
    d[MAX_N][MAX_N] ={};
      cin >> n;
    if(n == 0) break;
    city = mincity = 0; costtime ;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2>>temp3;
      if(road[temp1][temp2] != 0 ){
        if(road[temp1][temp2] > temp3) {
          road[temp1][temp2] = temp3;
          road[temp2][temp1] = temp3;
        }
      }
      else
      {
        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[i][k] !=INFINITY && 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(i == 0) costtime = cost;
      if (costtime > cost) {costtime = cost;mincity = i;}
    }
    cout<< mincity << " "<<costtime<<endl;

  }


  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <climits> 
#include <map>
using namespace std;
const int MAX_V = 11; 
const int MAX_E = 46; 
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>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <iterator>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<28

using namespace std;

typedef pair<int,int> P;


struct edge
{
	int to;
	int cost;

	edge(int to,int cost) : to(to),cost(cost) {}
};


vector<edge> G[10];
int d[10];

void dijkstra(int s,int n)
{
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+n,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty())
	{
		P p = que.top();
		que.pop();

		int v = p.second;
		if(d[v] < p.first) continue;

		rep(i,G[v].size())
		{
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main()
{
	int n;
	
	while(cin >> n && n)
	{
		vector<int> t;
		rep(i,n)
		{
			int a,b,c;
			cin >> a >> b >> c;

			G[a].push_back(edge(b,c));
			G[b].push_back(edge(a,c));

			vector<int>::iterator ite = find(t.begin(),t.end(),a);
			if(ite == t.end())
			{
				t.push_back(a);
			}

			ite = find(t.begin(),t.end(),b);
			if(ite == t.end())
			{
				t.push_back(b);
			}

		}

		P ans;
		ans.first = t[0];
		ans.second = INF;
		
		rep(i,t.size())
		{
			dijkstra(t[i],n);

			int sum = 0;

			rep(j,t.size()) sum += d[t[j]];

			if(ans.second > sum)
			{
				ans.first = i;
				ans.second = sum;
			}	
		}
		cout << ans.first << " " << ans.second << endl;
	}

	return 0;
	
}