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 FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 25)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;

int N;
int G[64][64];

int main() {
	while(scanf("%d", &N), N) {
		int mini = 10, maxi = -1;
		rep(i, 10) rep(j, 10) {
			if(i == j) G[i][i] = 0;
			else G[i][j] = INF;
		}
		rep(i, N) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			G[a][b] = c; G[b][a] = c;
			if(maxi < a) maxi = a;
			if(maxi < b) maxi = b;
			if(mini > a) mini = a;
			if(mini > b) mini = b;
		}
		FOR(k, mini, maxi + 1) FOR(i, mini, maxi + 1) FOR(j, mini, maxi + 1) {
			G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
		}
		int ans_num, ans_cost = INF;
		FOR(i, mini, maxi + 1) {
			int sum = 0;
			FOR(j, mini, maxi + 1) {
				sum += G[i][j];
			}
			if(ans_cost > sum) {
				ans_cost = sum;
				ans_num = i;
			}
		}
		printf("%d %d\n", ans_num, ans_cost);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>

using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;

//int main() {
//	int n,c,v;
//	array<array<pii, 50>, 50> graph = {};
//	scanf("%d %d %d", &n, &c, &v);
//	vector<pii> roads(v, {0,0});
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		roads[i].first = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		roads[i].second = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		graph[roads[i].first][roads[i].second].first = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		graph[roads[i].first][roads[i].second].second = s;
//	}
//
//	array<int> 
//
//	return 0;
//}

int main() {
	int n;
	while (scanf("%d", &n)) {
		if (!n)
			return 0;
		array<array<int, 10>, 10> graph = {};
		int m = 0;
		for (int i = 0; n > i; i++) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);

			graph[a][b] = c;
			graph[b][a] = c;
			m = max(m, max(a, b));
		}
		m++;
		pii Min = { INT_MAX,INT_MAX };
		for (int i = 0; m > i; i++) {
			priority_queue<pii, vector<pii>, greater<pii>> que;
			vector<int> al(m, -1);
			for (int j = 0; m > j; j++) {
				if (graph[i][j]) {
					que.push({ graph[i][j], j });
				}
			}
			al[i] = 0;
			while (!que.empty()) {
				pii num = que.top();
				que.pop();
				if (al[num.second] != -1)
					continue;
				al[num.second] = num.first;
				for (int j = 0; m > j; j++) {
					if (graph[num.second][j] && al[j] == -1) {
						que.push({ num.first + graph[num.second][j], j });
					}
				}
			}
			Min = min(Min, { accumulate(al.begin(), al.end(),0),i });
		}
		printf("%d %d\n", Min.second, Min.first);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define INF 1e+9

int main() {
	int n;
    while(cin>>n){
        if(!n)break;
        
        int a,b,c,v=0,d[11][11];
        
        for(int i=0;i<11;i++){
            for(int j=0;j<11;j++){
                if(i==j)d[i][j]=0;
                else d[i][j]=INF;
            }
        }
        
        for(int i=0;i<n;i++){
            cin>>a>>b>>c;
            d[a][b]=c;
            d[b][a]=c;
            v=max(max(v,a),b);
        }
        
        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  ans1=INF,ans2;
        for(int i=0;i<=v;i++){
            int count=0;
            for(int j=0;j<=v;j++){
                count+=d[i][j];
            }
            if(ans1>count){
                ans1=count;
                ans2=i;
            }
        }
        
        cout<<ans2<<" "<<ans1<<endl;
    }
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int d[10][10];
int sum[10];
const int INF=10000;
int main(void){
  while(1){
   int n;
   cin>>n;
   if(n==0)break;
   for(int i=0;i<10;i++){
       for(int j=0;j<10;j++){
           d[i][j]=INF;
           if(i==j)d[i][j]=0;
       }
   }
   for(int i=0;i<n;i++){
       int s,t,c;
       cin>>s>>t>>c;
       d[s][t]=d[t][s]=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=10000000,ansn=0;
   for(int i=0;i<10;i++)sum[i]=0;
      for(int i=0;i<10;i++){
          for(int j=0;j<10;j++){
              if(d[i][j]>=INF)continue;
              sum[i]+=d[i][j];
          }
          if(sum[i]==0)continue;
          if(ans>sum[i]){
              ansn=i;
              ans=sum[i];
          }
      }
      cout<<ansn<<' '<<ans<<endl;
  }
}

C++: // 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

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

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}
//???????????§???????????????
//????????????????????????
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}
//????°???????????????¢???
		int town;//????????????
		int x=INF;//????????????
		for(int i=0;i<m;i++){
			int r=0;//i?????§???????????????
			for(int j=0;j<m;j++){
				r=r+T[i][j];
			}
			if(r<x){
				x=r;
				town=i;
			}
		}
		cout<<town<<' '<<x<<endl;

	}

	return 0;
}