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;

typedef pair<int, int> P;
int INF = 1 << 10;

struct edge{
  int to;
  int cost;
};

vector<vector<edge> > G(10);
vector<int> d(10, INF);
vector<P> ans;

void init(){
  for(int i = 0; i < 10; i++){
	d[i] = INF;
  }
}

void display_d(){
  for(int i = 0; i < 10; i++){
	if(d[i] == INF) cout << "INF ";
	else cout << d[i] << " ";
  }
  cout << endl;
}

void initG(){
  for(int i = 0; i < 10; i++){
	G[i].clear();
  }
}

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  init();
  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;
	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 n = 0;
  while(1){
	cin >> n;
	if(n == 0) break;
	int a = 0, b = 0, c = 0;
	for(int i = 0; i < n; i++){
	  cin >> a >> b >> c;
	  edge e1, e2;
	  e1.to = b; e1.cost = c;
	  e2.to = a; e2.cost = c;
	  G[a].push_back(e1);
	  G[b].push_back(e2);
	}

	for(int i = 0; i < 10; i++){
	  dijkstra(i);
	  int sum = 0;
	  for(int i = 0; i < 10; i++){
		if(d[i] == INF) continue;
		sum += d[i];
	  }
	  if(sum != 0) ans.push_back(P(sum, i));
	}

	sort(ans.begin(), ans.end());
	cout << ans[0].second << " " << ans[0].first << endl;
	initG();
  }
  return 0;
}

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

#define rep(i,a) for(int i=0;i<(int)(a);i++)
const int INF = 1000000007;
const int MAX_V = 17;

int G[MAX_V][MAX_V];
int A[MAX_V][MAX_V];

int V;

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


int main(){

  int n;
  V = 10;

  while(1){
    cin >> n;
    if(n == 0) break;
    rep(i,V){
      rep(j,V){
	G[i][j] = INF;
      }
      G[i][i] = 0;
    }
    
    V = 0;
    rep(i,n){
      int a,b,c;
      cin >> a >> b >> c;
      V = max(V,max(a,b));
      G[a][b] = c;
      G[b][a] = c;
    }
    V++;

    rep(i,V){
      rep(j,V){
	A[i][j] = G[i][j];
      }
    }

    wf();

    int sum,min = INF,in;
    rep(j,V){
      sum = 0;
      rep(i,V){
	sum += A[j][i];
      }
      if(sum > 0 && sum < min) {
	min = sum;
	in = j;
      }
    }

    cout <<in << " "<< min << endl;
  }

     return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>1
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 50
#define P pair<int,int>
using namespace std;
int n;
int maxx;
int d[Maxn][Maxn];//d[i][j]从i到j的最短距离
void Floyd()
{
    for(int k=0; k<=maxx;k++)
        for(int i=0;i<=maxx;i++)
            for(int j=0;j<=maxx;j++)
                d[i][j]=min(d[i][k]+d[k][j],d[i][j]);
}
int main()
{
    IOS;
    while(cin>>n,n)
    {
        MEM(d,INF);
        for(int i=0;i<=n;i++)
            d[i][i]=0;
        maxx=-1;
        while(n--)
        {
            int a,b,c;
            cin>>a>>b>>c;
            maxx=max(maxx,max(a,b));
            d[a][b]=d[b][a]=c;
        }
        Floyd();
        int ans=INF;
        int pos;
        for(int i=0;i<=maxx;i++)
        {
            int sum=0;
            for(int j=0;j<=maxx;j++)
                sum+=d[i][j];
            if(ans>sum)
            {
                ans=sum;
                pos=i;
            }
        }
        cout<<pos<<" "<<ans<<endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>

using namespace std;

#define INF 100000

int d[10][10];

int main(){
    while(true){
        for(int i = 0; i < 10; i++){
            for(int j =0; j < 10; j++){
                if(i == j) d[i][j] = 0;
                else d[i][j] = INF;
            }
        }
        int n;
        scanf("%d",&n);
        if(n==0)break;
        for(int i = 0; i < n; i++){
            int a,b,c;
            scanf("%d %d %d",&a, &b, &c);
            d[a][b] = d[b][a] = c;
        }
        for(int k = 0; k < 10; k++){
            for(int i =0; i < 10; i++){
                for(int j = 0; j < 10; j++){
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        int ans = 1000000;
        int city = 100;
        for(int i =0; i < 10; i++){
            int tmp = 0;
            for(int j = 0; j < 10; j++){
                if(d[i][j] != INF)tmp += d[i][j];    
            }
            // 問題に記述されていない都市番号のtmpが0と最小になるため除外
            if(ans > tmp && tmp != 0){
                ans = tmp;
                city = i;
            }
        }
        printf("%d %d\n", city, ans);
        // for(int i =0; i < 10; i++){
        //     for(int j = 0; j < 10; j++){
        //         printf("%d ", d[i][j]);
        //     }
        //     printf("\n");
        // }
    }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;


	while (cin >> n && n != 0) {
		int min_ = 1000000000; // 答えの最小値
		int min_num = 1; // 答えの町
		int cost[100][100];
		int max_ = 0; // 町がどれだけあるか
		int from, to, time;

		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				cost[i][j] = 100000000;
			}
		}
		for (int i = 0; i < 100; i++) {
			cost[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> from >> to >> time;
			cost[from][to] = time;
			cost[to][from] = time;
			max_ = max(max(from, to), max_);
		}
		for (int k = 0; k <= max_; k++) {
			for (int i = 0; i <= max_; i++) {
				for (int j = 0; j <= max_; j++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		// 答えを求める
		for (int i = 0; i <= max_; i++) {
			int total = 0;
			for (int j = 0; j <= max_; j++) {
				total += cost[i][j];
			}
			if (total < min_) {
				min_ = total;
				min_num = i;
			}
		}
		cout << min_num << " " << min_ << endl;
  }
	return 0;
}