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 <utility>
#include <algorithm>
using namespace std;

const int INF = 10000000;

int main() {
	int n;
	while(cin >> n, n) {
		int tab[16][16];
		int m = 0;
		for(int i = 0; i < 16; i++) {
			for(int j = 0; j < 16; j++)
				tab[i][j] = INF;
			tab[i][i] = 0;
		}
		for(int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			tab[a][b] = tab[b][a] = c;
			m = max(m, max(a, b));
		}
		m++;
		for(int i = 0; i < 16; i++) {
			for(int j = 0; j < 16; j++) {
				for(int k = 0; k < 16; k++) {
					tab[j][k] = min(tab[j][k], tab[j][i] + tab[i][k]);
				}
			}
		}

		/*
		for(int i = 0; i < 16; i++) {
			for(int j = 0; j < 16; j++) {
				cout << tab[i][j] << " ";
			}
			cout << endl;
		}
		*/

		pair<int,int> ans(INF,-1);
		for(int i = 0; i < m; i++) {
			pair<int,int> tmp(0,i);
			for(int j = 0; j < m; j++) {
				tmp.first += tab[i][j];
			}
			ans = min(ans, tmp);
		}
		cout << ans.second << " " << ans.first << endl;
	}
}

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 && !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;

    while(cin >> n,n){
        
        for(int i = 0 ; i < MAX ; i++)
            for(int j = 0 ; j < MAX ; j++)
                r[i][j] = INF;
        
        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++: // 2016/06/16 AOJ0200:「Convenient Location」 Sae.I
#include <iostream>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n;		//道の数
		cin >> n;

		if(n==0)	//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;	//同じ町から町へは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;	//a町からb町、b町からa町までの時間

			if(a+1>m){	
				m = a+1;
			}
			if(b+1>m){		
				m = b+1;
			}
		}

		//ワーシャルフロイド法
		int time[1000][1000];		//最短時間
		for(int i=0;i<m;i++){		//重み配列で初期化
			for(int j=0;j<m;j++){
				time[i][j]=T[i][j];
			}
		}
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(time[i][j]>time[i][k]+time[k][j]){	//時間
						time[i][j] = time[i][k]+time[k][j];
					}
				}
			}
		}

		int machi=0;		//町の総数
		int Time=0;		//最短時間総和
		int time2[1000];	//各町からの移動時間総和
	
		for(int i=0;i<m;i++){
			time2[i]=0;	//初期化
			for(int j=0;j<m;j++){	//i町からj〜m町までの時間を足し合わせる
				time2[i]= time2[i]+time[i][j];
			}
	
			if(i!=0){			//0（最初）でないとき	
				if(time2[i]<time2[i-1]){
					Time=time2[i];
					machi=i;
				}
			}
			else{				//0(最初)のときは比較せずその値をいれる
				Time=time2[i];
				machi=i;
			}
		}


		cout << machi << " " << Time << '\n';


	}

	return 0;
}

C++: //#include <bits/stdc++.h>

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_V = 12, MAX_L = 2505;
const int INF = 1e+9+1;

int  V,E;
int G[MAX_V][MAX_V];


//弗洛伊德模板题
void solve(){
    for(int k = 0;k < V;k++){
        for(int i =0 ;i < V;i++){
            for(int j = 0;j <V;j++){
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }

    int minSum = INF, minarg = 0;
    for(int i = 0;i < V;i++){
        int sum = 0;
        for(int j = 0;j < V;j++){
            sum+=G[i][j];
        }
        if(sum < minSum){
            minSum = sum;
            minarg = i;
        }
    }
    cout<<minarg<<' '<<minSum<<endl;
}

/*
6
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0
 */


int main(){
    ios::sync_with_stdio(false);
    while(cin>>E)
    {
        if(E == 0) break;
        V = 0;
        for(int i = 0;i < MAX_V;i++){
            for(int j = 0;j < MAX_V;j++){
                G[i][j] = INF;
                if(i == j) G[i][j] = 0;
            }
        }

        for(int i = 0;i < E;i++){
            int u,v,c;
            cin>>u>>v>>c;
            V = max(V, max(u, v));
            G[u][v] = G[v][u] = c;
        }
        V++;
        solve();

    }

    return 0;

}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

#define INF 1<<24
#define MAX_V 999

using namespace std;

int dat[10][10];

int main(){
	int a, b, c, num;
	int n;
	while(cin>>n,n){
		num=0;
		rep(i,10){
			rep(j,10){
				if(i==j){
					dat[i][j]=0;
				}else{
					dat[i][j]=INF;
				}
			}
		}
		rep(i,n){
			cin>>a>>b>>c;
			dat[a][b]=c;dat[b][a]=c;
			num=max(num,max(a,b));
		}
		num++;
		rep(i,n){
			rep(j,n){
				rep(k,n){
					dat[j][k]=min(dat[j][k],dat[j][i]+dat[i][k]);
				}
			}
		}
		
		
		int sum, mC=INF,id;
		rep(i,num){
			sum=0;
			rep(j,num){
				sum+=dat[i][j];
			}
			if(sum<mC){
				mC=sum;id=i;
			}
		}
		cout<<id<<" "<<mC<<endl;
	}
	return 0;
}