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<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 100000
using namespace std;

int main(){
	//int town[11][11];
	int to,from,cost;
	int n;
	while(1){
		cin>>n;
		if(!n)break;
		int maxsize=0;
		int dt[11][11];
		for(int i=0;i<11;i++){
			for(int j=0;j<11;j++){
				//town[i][j]=INF;
				if(i!=j)dt[i][j]=INF;
				else dt[i][j]=0;
				//out<<"yeah "<<i<<" "<<j<<endl;
			}
		}
		for(int i=0;i<n;i++){
			cin>>to>>from>>cost;
			//cout<<"analize"<<endl;
			dt[to][from]=cost;
			dt[from][to]=cost;
			maxsize=max(maxsize,to);
			maxsize=max(maxsize,from);
		}
		for(int k=0;k<maxsize+1;k++){
			for(int i=0;i<maxsize+1;i++){
				for(int j=0;j<maxsize+1;j++){
					dt[i][j]=min(dt[i][j],dt[i][k]+dt[k][j]);
				}
			}
		}
		int sum[maxsize+1];
		rep(i,maxsize+1){
			sum[i]=0;
			rep(j,maxsize+1){
				sum[i]+=dt[i][j];
			}
			//cout<<sum[i]<<" ";
		}
		//cout<<endl;
		int ans[maxsize+1];
		rep(i,maxsize+1)ans[i]=sum[i];
		sort(sum,sum+maxsize+1);
		//cout<<sum[0]<<endl;
		for(int i=0;i<maxsize+1;i++){
			if(ans[i]==sum[0]){
				cout<<i<<" "<<sum[0];
				break;
			}
		}
		cout<<endl;
		//cout<<"finish"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int MAX_V=10;
int d[10][10];
int V;
const int INF=100000000;

void warshall_floyd(){
	for(int k = 0; k < V; k++){
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
}

int main(){

	int n;
	while(cin>>n&&n!=0){
		for(int i = 0; i < 10; i++)
			fill(d[i],d[i]+10,INF);
		set<int> s;
		for(int i = 0; i < n; i++){
			int a,b,c;
			cin>>a>>b>>c;
			d[a][b]=c;
			d[b][a]=c;
			s.insert(a);
			s.insert(b);
		}
		V=s.size();
		for(int i = 0; i < V; i++){
			d[i][i]=0;
		}

		warshall_floyd();
		int idx;
		int minValue=INF;
		for(int i = 0; i < V; i++){
			int sum=0;
			for(int j = 0; j < V; j++){
				if(i!=j&&d[i][j]!=INF){
					sum+=d[i][j];
				}
			}
			if(minValue>sum){
				minValue=sum;
				idx=i;
			}
		}
		cout<<idx<<" "<<minValue<<endl;
	}


	return 0;
}

C++: /*
Á·Ï°Ìâ£ºConvenient Location_AOJ 0189 
*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;

const int MAX_V=17, INF=0x3f3f3f3f;

struct edge {
	int to, cost;
};
typedef pair<int, int> P;//ÀûÓÃfirst±íÊ¾×î¶Ì¾àÀë£¬second±íÊ¾¶¥µãµÄ±àºÅ 

vector<edge> G[MAX_V]; //ÏÂ±ê³äµ±from
int d[MAX_V];
int sum[MAX_V];

void dijkstra(int s)
{
	//°´ÕÕfirst´ÓÐ¡µ½´óË³ÐòÅÅÁÐ£¬ÏÈÈ¡³ö×î¶Ì¾àÀëºÍ¶ÔÓ¦µÄ¶¥µã 
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d+10, INF);
	d[s]=0;
	que.push(P(0,s));
	
	while(que.size()) //¸´ÔÓ¶ÈÎªO(|E|Xlog|V|) 
	{
		P p = que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first)
			continue;
		for(int i=0; i<G[v].size(); i++)
		{
			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 E;
	while(scanf("%d", &E)!=EOF)
	{
		if(E==0)
			break;
		
		memset(sum, 0, sizeof(sum));
		for(int i=0; i<10; i++)
			G[i].clear();
		
		for(int i=0; i<E; i++)
		{
			int f,t,c;
			scanf("%d%d%d", &f, &t, &c);
			G[f].push_back((edge){t,c});
			G[t].push_back((edge){f,c});
		}
		
		for(int i=0; i<10; i++)
		{
			dijkstra(i);
			for(int j=0; j<10; j++)
			{
				if(d[j]!=INF)
					sum[i]+=d[j];
			}
		}
		
		int ans1, ans2=0x3f3f3f3f;
		for(int i=0; i<10; i++)
		{
			if(sum[i]!=0&&ans2>sum[i])
			{
				ans2=sum[i];
				ans1=i;
			}
		}
		
		printf("%d %d\n", ans1, ans2);
		
		
	}
	
	return 0;
}

C++: #include <algorithm>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

typedef struct {
  int u, v, cost;
} Edge;

void solve(vector<Edge> es){
  VI d(10, INF);
  bool update = true;
  VI ans(10, 0);
  int lim = 10;

  REP(i, 0, lim){

    bool reach[10] = {false};
    REP(j, 0, 10){
      d[j] = INF;
    }
    d[i] = 0;
    reach[i] = true;
    update = true;

    while(update){
      update = false;
      REP(j, 0, es.size()){
        Edge e = es[j];
        if(d[e.u] != INF && d[e.v] > d[e.u] + e.cost){
          cout << e.u << ":" << e.v << endl;

          d[e.v] = d[e.u] + e.cost;
          update = true;
          reach[e.v] = true;
        }
      }
    }
    REP(j, 0, lim){
      if(reach[j]){
        ans[i] += d[j];
      } else {
        lim = j;
      }
    }
  }

  int f = INF;
  int v = -1;
  REP(i, 0, lim){
    if(f > ans[i]){
      f = ans[i];
      v = i;
    }
  }
  cout << v << " " << f << endl;

  return;
}

int main(){
  int N;

  while(1){
    cin >> N;
    if(N == 0){
      break;
    }
    vector<Edge> es(2*N);
    REP(i, 0, N){
      int a, b, c;
      cin >> a >> b >> c;
      es[i].u = a; es[i].v = b; es[i].cost = c;
      es[i+N].v = a; es[i+N].u = b; es[i+N].cost = c;
    }
    solve(es);
  }

  return 0;
}