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;

int main(){
        int N;
        while(cin>>N,N){
                vector<vector<int>>data;
                set<int>d;
                data.resize(N);
                for (int i = 0; i < N; i++) {
                        data[i].resize(N);
                        for (int j = 0; j < N; j++) {
                                data[i][j]=INT_MAX/6;
                        }
                        data[i][i]=0;
                }
                for (int i = 0; i < N; i++) {
                        int a,b,c;
                        cin>>a>>b>>c;
                        data[a][b]=c;
                        data[b][a]=c;
                        d.insert(a);
                        d.insert(b);
                }
                for (int k = 0; k < N; k++) {
                        for (int i = 0; i < N; i++) {
                                for (int j = 0; j < N; j++) {
                                        data[i][j]=min(data[i][j],data[i][k]+data[k][j]);
                                        data[j][i]=data[i][j];
                                }
                        }
                }
                long long int ans=INT_MAX;
                int memo2;
                for(auto x:d){
                        long long int memo=0;
                        for(auto y:d){
                                memo+=data[x][y];
                        }
                        if(ans>memo){
                                memo2=x;
                                ans=memo;
                        }
                }
                cout<<memo2<<" "<<ans<<endl;
                data.clear();
                d.clear();
        }

}

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 min_town_n;
    int min_town_time;
    for(int k=0;k<m;k++){
      int sub;
      for(int i=0;i<m;i++){
        sub += T[k][i];
      }
      if(min_town_time > sub){
        min_town_time = sub;
        min_town_n = k;
      }
    }
    cout << min_town_n << ' ' << min_town_time << endl;
	}

	return 0;
}

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

#define MAX_V 11
#define INF 1e9

int min(int a, int b){
  return a < b ? a : b;
}

int main(void){
  int n, a, b, c;
  int dp[MAX_V][MAX_V];
  
  while(true){
    cin >> n;
    if(n == 0) break;

    // ?????????
    for(int i = 0; i < MAX_V; i++)
      for(int j = 0; j < MAX_V; j++)
        dp[i][j] = INF;

    for(int i = 0; i < MAX_V; i++)
      dp[i][i] = 0;
    
    for(int i = 0; i < n; i++){
      cin >> a >> b >> c;
      dp[a][b] = c;
      dp[b][a] = c;
    }

    // ???????????£???????????????
    for(int k = 0; k < MAX_V; k++)
      for(int i = 0; i < MAX_V; i++)
        for(int j = 0; j < MAX_V; j++)
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);


    // ??????????¨????
    int minpoint, mincost = INF;
    for(int i = 0; i < MAX_V; i++){
      // ???????????????????????????????????????????±???????
      int nowcost = 0;
      for(int j = 0; j < MAX_V; j++){
        if(dp[i][j] != INF){ nowcost += dp[i][j]; } 
      }

      // ?????????????????????????????????????????????????°?????????????
      if(nowcost != 0 && mincost > nowcost){
        mincost = nowcost;
        minpoint = i;
      }
    }
    
    // ??????
    cout << minpoint << " " << mincost << endl;
    
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX 11
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];

int dijkstra(int s){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = 0 ; i <= maxnum ; i++){
            if((v[i] < mini || mini == INF) && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = 0; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            v[i] = min(v[i],t);
        }
    }
    
    int sum = 0;
    for(int i = 0 ; i <= maxnum ; i++){
        sum += v[i];
    }
    
    return sum;
}


int main(){
    int a,b,c;
    
    for(int i = 0 ; i < MAX ; i++)
        for(int j = 0 ; j < MAX ; j++)
            r[i][j] = INF;

    while(cin >> n,n){
        maxnum = 0;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = c;
            r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
        }

        int mx = INF, e;
        for(int i = 0 ; i <= maxnum ; i++){
            int val = mx;
            mx = min(mx,dijkstra(i));
            if(val > mx) e = i;
        }
        cout << e << " " << mx << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define inf 999999999
int main(){
	int n,a,b,c;
	int cost[64][64];
	while(cin >> n, n) {
		rep(i,64) {
			rep(j,64) {
				cost[i][j] = inf;
			}
		}
		int max = 0;
		rep(i,n) {
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			cost[a][a] = 0;
			cost[b][b] = 0;
			if(max < a) max = a;
			if(max < b) max = b;
		}

		rep(i,max+1) {
			rep(j,max+1) {
				rep(k,max+1) {
					int len = cost[i][j] + cost[j][k];
					if(len < cost[i][k]) {
						cost[i][k] = len;
					}
				}
			}
		}
		int min = inf, rmin = -1;
		rep(i,max+1) {
			int ret = 0;
			rep(j,max+1) {
				ret += cost[i][j];
			}
			if(min > ret) {
				min = ret;
				rmin = i;
			}
		}
		cout << rmin << " " << min << endl;
	}
	return 0;
}