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<bits/stdc++.h>
using namespace std;
#define INF (1<<20)
typedef pair<int,int> P;

vector<P> edge[10];

int dijkstre(int pos){
  int min_cost[10];
  fill_n(min_cost,10,INF);
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,pos));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int cost = p.first;
    int now = p.second;
    if(min_cost[now] < cost) continue;
    min_cost[now] = cost;
    for(int i=0;i<edge[now].size();i++){
      int nc = edge[now][i].second;
      int next = edge[now][i].first;
      que.push(P(cost+nc,next));
    }
  }
  int sum = 0;
  for(int i=0;i<10;i++){
    if(min_cost[i] != INF){
      sum += min_cost[i];
    }
  }
  return sum;
}

int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;
    int l=100,r=0;
    for(int i=0;i<10;i++){
      edge[i].clear();
    }
    for(int i=0;i<n;i++){
      int a,b,c;
      cin >> a >> b >> c;
      edge[a].push_back(P(b,c));
      edge[b].push_back(P(a,c));
      l = min(min(l,a),b);
      r = max(max(r,a),b);
    }
    int ans = INF;
    int pos = l;
    for(int i=l;i<=r;i++){
      int tmp = dijkstre(i);
      if(ans > tmp){
	pos = i;
	ans = tmp;
      }
    }
    cout << pos << " " << ans << endl;
  }
}

C++: #include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>

using namespace std;

int INF=1e8;
int dist[15][15];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  while(cin>>n,n){

    //??\????????£??\???????????¢?????????
    fill(dist[0],dist[0]+15*15,INF);
    int m=0,a,b,d;
    for(int i=0; i<n; ++i){
      cin>>a>>b>>d;
      dist[a][b]=dist[b][a]=min(dist[a][b],d);
      m=max({m,a,b});
    }
    ++m;

    for(int i=0; i<m; ++i)  //i??????i????????¢???0
      dist[i][i]=0;
    //???????????£???????????????
    for(int k=0; k<m; ++k)
      for(int i=0; i<m; ++i)
	for(int j=0; j<m; ++j)
	  dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

    //(?????¢?????????,????????????)
    pair<int,int> re=pair<int,int>(INF,-1);
    for(int i=0; i<m; ++i){

      int sum=0; //??????????¨????
      for(int j=0; j<m; ++j) sum+=dist[i][j];

      //????°??????´??°
      re=min(re,pair<int,int>(sum,i));
    }
    cout<<re.second<<" "<<re.first<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define Inf 1000000
int dist[105][105];
int main()
{
    int n,a,b,s;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        //memset(dist,0,sizeof(dist));
        for(int i=0; i<20; ++i)
        {
            for(int j=0; j<20; ++j)
            {
                dist[i][j]=Inf;
                dist[j][i]=Inf;
                if(i==j) dist[i][j]=0;
            }
        }
        int m=0;
        for(int i=0; i<n; ++i)
        {
            scanf("%d%d%d",&a,&b,&s);
            dist[a][b]=s;
            dist[b][a]=s;
            m=max(m,max(a,b)+1);
        }
        for(int k=0; k<m; ++k)
        {
            for(int i=0; i<m; ++i)
            {
                for(int j=0; j<m; ++j)
                {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        int x[100];
        memset(x,0,sizeof(x));
        for(int i=0; i<m; ++i)
        {
            for(int j=0; j<m; ++j)
            {
                x[i]+=dist[i][j];
            }
        }
        int ans=min_element(x,x+m)-x;
        printf("%d %d\n",ans,x[ans]);
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

#define INF 1e+9;

int E, V;
int cost[50][50];
int d[100];

int main(){

    while(cin >> E, E){
        V = 0;
        fill(d, d+100, 0);
        for(int i=0; i < 50; i++){
            for(int j=0; j < 50; j++){
                cost[i][j] = (i==j)? 0:INF
            }
        }
        for(int i=0; i < E; i++){
            int a, b, c;
            cin >> a >> b >> c;
            cost[a][b] = c;
            cost[b][a] = c;
            V = max(V, max(a, b));
        }
        for(int k=0; k <= V; k++){
            for(int i=0; i <= V; i++){
                for(int j=0; j <= V; j++){
                    cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
                }
            }
        }

        int minCost = INF;
        for(int i=0; i <= V; i++){
            for(int j=0; j <= V; j++){
                d[i] += cost[i][j];
            }
            minCost = min(minCost, d[i]);
        }

        for(int i=0; i <= V; i++){
            if(minCost == d[i]) cout << i << " " << d[i] << endl;
        }
    }
}

C++: #include <iostream>

#define MAX 10
#define INF 400000000
using namespace std;

int d[MAX][MAX];
int n, num_ver = 0;
int min_t = INF;
int min_ver;

void init();
void input();
void wf();

int main(){

  while(cin >> n, n){
    init();
    input();  
    wf();
    
   
    for(int i = 0; i <= num_ver; i++){
      int tmp = 0;
      for(int j = 0; j <= num_ver; j++){
	tmp += d[i][j];
      }
      if(min_t > tmp) {min_t = tmp; min_ver = i;}
    }
    cout << min_ver << " " << min_t << endl;
  }
}

void init(){
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      d[i][j] = (i==j)? 0: INF;
    }
  }
  num_ver = 0;
  min_t = INF;
}

void input(){
  for(int i = 0; i < n; i++){
    int a, b, c;
    cin >> a >> b >> c;
    d[a][b] = c;
    d[b][a] = c;
    if(num_ver < b) num_ver = b;
  }
}

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