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++: /*
P135
AOJ 0189 Convenient Location
*/

#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
#include <cmath>

using namespace std;

const int MAXN = 15;

int d[MAXN][MAXN];
int M, N;

bool read()
{
    scanf("%d", &M);
    if(M==0) return false;
    for(int i=0; i<=10; i++){
        for(int j=0; j<=10; j++)
        {
            d[i][j] = 1<<20;
        }
        d[i][i] = 0;
    }
    N = 0;
    int s, e, m;
    for(int i=0; i<M; ++i){
        scanf("%d%d%d", &s, &e, &m);
        d[s][e] = m;
        d[e][s] = m;
        N = max(N, s);
        N = max(N, e);
    }
    return true;
}

void floyd(int n)
{
    for(int k=0; k<n; ++k)
    for(int i=0; i<n; ++i)
    for(int j=0; j<n; ++j)
    {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
}
void solve()
{
    floyd(N+1);
    int dmin = 1<<20, idx = 0;
    for(int i=0; i<N; ++i){
        int dis = 0;
        for(int j=0; j<=N; ++j)
            dis += d[i][j];
        if(dis < dmin) dmin = dis, idx = i;
    }
    printf("%d %d\n", idx, dmin);

}

int main()
{
    while(read()){
        solve();
    }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<utility>
#include<numeric>
#include<iterator>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cassert>
using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
#define FOR(i,init,len) for(int i=(init);i<(len);++i)
#define For(i,init,len) for(int i=(init);i<=(len);++i)
#define fi first
#define se second
#define pb push_back
#define is insert
namespace IO {
	inline char getchar() {
		static const int BUFSIZE=5201314;
		static char buf[BUFSIZE],*begin,*end;
		if(begin==end) {
			begin=buf;
			end=buf+fread(buf,1,BUFSIZE,stdin);
			if(begin==end) return -1;
		}
		return *begin++;
	}
}
inline void read(int &in) {
	int c,symbol=1;
	while(isspace(c=IO::getchar()));
	if(c=='-') { in=0;symbol=-1; }
	else in=c-'0';
	while(isdigit(c=IO::getchar())) { in*=10;in+=c-'0'; }
	in*=symbol;
}
inline int read() { static int x;read(x);return x; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
#define PA(name,init,len) cout<<#name"["<<(len-init)<<"]=";FOR(_,init,len) cout<<name[_]<<" \n"[_==(len-1)];
#define Pa(name,init,len) cout<<#name"["<<(len-init+1)<<"]=";For(_,init,len) cout<<name[_]<<" \n"[_==(len)];
#define PV(name) cout<<#name"="<<name<<'\n';

int n;
const int maxn=15;
const int INF=1e5;
int d[maxn][maxn];

int main() {
#ifdef MengLan
	int Beginning=clock();
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
#endif // MengLan

    while(scanf("%d",&n)==1&&n){
        For(i,0,9) For(j,0,9) d[i][j]=INF;
        For(i,0,9) d[i][i]=0;
        int ma=0;
        FOR(i,0,n){int a,b,c;scanf("%d%d%d",&a,&b,&c);d[a][b]=d[b][a]=c;ma=std::max({ma,a,b});}
        For(k,0,ma) For(i,0,ma) For(j,1,ma) d[i][j]=std::min(d[i][j],d[i][k]+d[k][j]);
        int idx=0,ans=INF;
        For(i,0,ma){
            int t=0;
            For(j,0,ma) t+=d[i][j];
            if(t<ans) {idx=i;ans=t;}
        } 
        printf("%d %d\n",idx,ans);
    }


#ifdef MengLan
	printf("Time: %d\n",clock()-Beginning);
    system("pause");
#endif // MengLan
	return 0;
}

C++: #include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <utility>

#define dprintf(s,...) printf("%s:%d" s,__func__,__LINE__,__VA_ARGS__)
using namespace std;

typedef pair<int,int> P;
typedef long long int ll;

class Edge{
public:
  int to,cost;
  Edge(int t,int c){
    to = t;
    cost = c;
  }
};

int n,k;
int d[10][10];
vector<Edge> G[10];

void dijekstra(int s){

  priority_queue<P, vector<P>, greater<P> > qu;

  qu.push(P(0,s));
  d[s][s]=0;
  
  while(!qu.empty()){

    P p = qu.top();
    int v = p.second; 
    qu.pop();

    if(d[s][v] < p.first) continue;

    for(int i=0; i<G[v].size(); i++){
      Edge e = G[v][i];
      
      if(d[s][v]+e.cost < d[s][e.to]){
	d[s][e.to] = d[s][v]+e.cost;
	qu.push(P(d[s][e.to], e.to));
      }
    }
    
  }

}

void solve(){

  for(int i=0;i<k;i++)
    for(int j=0;j<k;j++){
      d[i][j]=INT_MAX/3;
    }

  for(int i=0;i<k;i++){
    dijekstra(i);
  }
}


int main(){

  ios_base::sync_with_stdio(false);
  
  while(1){

    k=0;
    
    cin>>n;
    if(n==0) break;
    
    
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b>>c;
      Edge e1(a,c),e2(b,c);
      G[a].push_back(e2);
      G[b].push_back(e1);
      k = max(k,max(a,b));
    }
    k++;
    //cout<<"k="<<k<<endl;
    solve();
    
    int sum[10];
    int ans, min_cost=INT_MAX/3;
    fill(sum,sum+10,0);

    for(int i=k-1;i>=0;i--){
      //cout<<i<<":";
      for(int j=0; j<k; j++){
	//cout<<d[i][j]<<" ";
	sum[i] += d[i][j];
      }
      //cout<<endl;
      if(sum[i] <= min_cost){
	ans = i;
	min_cost = sum[i];
      }
    }
    cout<<ans<<" "<<min_cost<<endl;
    for(int i=0;i<10;i++){
      G[i].erase(G[i].begin(), G[i].end());
    }    
  }


  
  
  return 0;
}

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

using namespace std;

#define MAX_N	50
#define INF		100000000


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

struct P
{
	int from , to;
};

edge input[MAX_N];


int dp[MAX_N][MAX_N];



int n;


int main(void)
{
	while (cin >> n && n != 0){

		int map_max = 0;

		int min = 2100000000;
		int index = 0;

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				dp[i][j] = INF;
			}
		}

		for (int i = 0; i < n; i++){
			cin >> input[i].from >> input[i].to >> input[i].cost;
		
			dp[input[i].from][input[i].to] = input[i].cost;
			dp[input[i].to][input[i].from] = input[i].cost;

			map_max = std::max(map_max , std::max(input[i].from , input[i].to));
		}

		

		for (int i = 0; i <= map_max; i++){
			dp[i][i] = 0;
			for (int j = 0; j <= map_max; j++){
				for (int k = 0; k <= map_max; k++){
					dp[j][k] = std::min(dp[j][k] , dp[j][i] + dp[i][k]);
				}
			}
		}

		for (int i = 0; i <= map_max; i++){
			int now = 0;
			for (int j = 0; j <= map_max; j++){
				now += dp[i][j];
			}

			if (now < min){
				min = now;
				index = i;
			}
		}

		cout << index << " " << min << endl;
	}
	
	return 0;
}