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 <iostream>
#include <algorithm>
int cost[11][11];
#define INF 1e9

using namespace std;

int main(void){
	int n,a,b,d;
	int cmax;
	int t,rmin,tmin;
	while(cin >> n,n){
		tmin=INF;
		cmax=0;
		for(int i=0;i<11;i++)
				for(int j=0;j<11;j++)
					cost[i][j]=INF;
					
		for(int i=0;i<11;i++)
			cost[i][i]=0;
			
		for(int i=0;i<n;i++){
			cin >> a >> b >> d;
			if(cmax<a)
				cmax=a;
			if(cmax<b)
				cmax=b;
			cost[a][b]=cost[b][a]=d;
		}
		for(int k=0;k<=cmax;k++)
			for(int i=0;i<=cmax;i++)
				for(int j=0;j<=cmax;j++)
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
		
		for(int i=0;i<=cmax;i++){
			t=0;
			for(int j=0;j<=cmax;j++)
					t+=cost[i][j];
			if(t<tmin)
				tmin=t,rmin=i;
		}
		cout << rmin << ' ' << tmin << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
#define INF (long)1e6
long dp[10][10];
int main() {
	int n ;
	while(1){
		cin >> n ; if(!n) break;
		for(int i=0;i<10;i++) for(int j=0;j<10;j++) dp[i][j]=INF;
		for(int i=0;i<10;i++) dp[i][i]=0;
		int V=0;
		for(int i=0;i<n;i++){
			int a,b,c; cin >> a >> b >> c ;
			V=max(V,max(a,b));
			dp[a][b]=dp[b][a]=c;
		}
		for(int k=0;k<=V;k++) for(int i=0;i<=V;i++) for(int j=0;j<=V;j++)
			dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
		long NUM=0, MIN=INF;
		for(int i=0;i<=V;i++){
			int sum=0;
			for(int j=0;j<=V;j++) sum+=dp[i][j];
			if(sum<MIN) MIN=sum,NUM=i;
		}
		cout << NUM << ' ' << MIN << '\n' ;
	}
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <stack>
#include <queue>

using namespace std;

#define INF 10000000

int main(void)
{
    int n;

    while (cin >> n, n)
    {
        int road[45][45];

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

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

        n = m+1;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                for (int k = 0; k < n; k++)
                {
                    road[j][k] = min(road[j][k], road[j][i] + road[i][k]);
                }
            }
        }

        int min = INF;
        int min_p;
        for (int i = 0; i < n; i++)
        {
            int sum = 0;
            for (int j = 0; j < n; j++)
            {
                if (i != j && road[i][j] != INF)
                {
                    //cout << i << " " << j << " " << road[i][j] << endl;
                    sum += road[i][j];
                }
            }
            if (sum > 0 && sum < min)
            {
                min = sum;
                min_p = i;
            }
        }
        cout << min_p << " " << min << endl;
    }

    return 0;
}

C++: #include <list>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#define INF (1LL << 60)
using namespace std;
bool used[10]; long long dist[10];
void dijkstra(int V, int E, int s, vector<pair<int, long long> > X[]) {
	priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > Q;
	for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
	dist[s] = 0; Q.push(make_pair(0, s));
	int cnt = 0;
	while (!Q.empty()) {
		if (cnt > E) return; // NEGATIVE_CYCLE
		pair<long long, int> p = Q.top(); used[p.second] = true; Q.pop();
		for (int i = 0; i < X[p.second].size(); i++) {
			int to = X[p.second][i].first; long long leng = X[p.second][i].second;
			if (dist[to] > dist[p.second] + leng && !used[to]) {
				dist[to] = dist[p.second] + leng;
				Q.push(make_pair(dist[to], to));
			}
		}
	}
}
int n, u, v, w; bool r[10]; vector<pair<int, long long> > G[10];
int main() {
	while(cin >> n, n) {
		for(int i = 0; i < 10; i++) G[i].clear(), r[i] = false;
		for(int i = 0; i < n; i++) {
			cin >> u >> v >> w; r[u] = true, r[v] = true;
			G[u].push_back(make_pair(v, w));
			G[v].push_back(make_pair(u, w));
		}
		int x = -1; long long y = INF;
		for(int i = 0; i < 10; i++) {
			long long res = 0;
			if(!r[i]) continue;
			dijkstra(10, n, i, G);
			for(int j = 0; j < 10; j++) {
				if(r[i]) res += dist[j];
			}
			y = min(y, res);
		}
		cout << x << ' ' << y << endl;
	}
}

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++: // 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 = m - 1;
		int value = INF;
		for(int i = m - 1; i >= 0; i--){
			int tempValue = 0;
			for(int j = 0; j < m; j++){
				tempValue += T[i][j];
			}
			if(value > tempValue){
				value = tempValue;
				town = i;
			}
		}
		cout << town << ' ' << value << endl;
	}

	return 0;
}