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 <vector>
#include <sstream>
//#include <fstream>

using namespace std;

const int MAX_N = 100000000;
typedef pair<int, int> P; // shortnest city, length order

P dijkstra (vector <vector <int> > path )
{
	P res (-1, MAX_N );	// shortnest city, length order
	int i,j;

	for (i = 0; i < 10; ++i){
		vector <int>  d (10, MAX_N );
		vector <bool> v (10, false );

		d[i] = 0;
		int mind = MAX_N;
		int p;

		do{
			mind = MAX_N;

			for (int k = 0; k < 10; ++k){
				if (!v[k] && d[k] < mind ){
					mind = d[k];
					p = k;
				} // end if
			} // end for

			v[p] = true;
		
			for (int k = 0; k < 10; ++k){
				if (d[p] + path[p][k] < d[k] ){
					d[k] = d[p] + path[p][k];
				} // end if
			} // end for
		}while (mind != MAX_N );

		int sum = 0;
		for (j = 0; j < 10; ++j){
			if (j != i && d[j] != MAX_N ){
				sum += d[j];
			} // end if
		} // end for
		if (sum == 0 ){
			continue;
		} // end if

		if (res.second > sum ){
			res.first  = i;
			res.second = sum;
		} // end if
	} // end for

	return res;
}			

int main()
{
//	cut here before submit 
//	freopen ("testcase.convenientlocation", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;

		if (n == 0 ){
			break;
		} // end if		

		vector <vector <int> > path (10, vector <int> (10, MAX_N ) ); 
		int i;
		for (i = 0; i < n; ++i){
			getline (cin, str );
			int from, to, time;
			stringstream ss(str);
			ss >> from >> to >> time;
			path[from][to] = time;
			path[to][from] = time;
		} // end for
		P res;
		res = dijkstra (path );

		cout << res.first << ' ' << res.second << endl;
	} // end loop
		
	return 0;
}

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

#define INF 10000

int E;
int cost[50][50];
int d[100];

int main(){

    while(cin >> E, E){
        int minCost = 100000;
        fill(d, d+100, 0);
        for(int i=0; i < 50; i++){
            cost[i][i] = 0;
            for(int j=0; j < 50; j++){
                if(i != j)cost[i][j] = INF;
            }
        }
        for(int i=0; i < E; i++){
            int a, b, c;
            cin >> a >> b >> c;
            cost[a][b] = c;
            cost[b][a] = c;
        }
        for(int k=0; k < 50; k++){
            for(int i=0; i < 50; i++){
                for(int j=0; j < 50; j++){
                    cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
                }
            }
        }

        for(int i=0; i < 50; i++){
            for(int j=0; j < 50; j++){
                if(cost[i][j] != INF) d[i] += cost[i][j];
            }
            if(d[i] != 0) minCost = min(minCost, d[i]);
        }

        for(int i=0; i < 50; i++){
            if(minCost == d[i] && d[i] != 0) cout << i << " " << d[i] << endl;
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

const int INF = 1000;

void pp(int (*v)[10]){
	rep(i, 10){
		rep(j, 10){
			printf("%5d", v[i][j]);
		}
		cout << endl;
	}
	cout << endl;
}

int sum_v(int *v){
	int sum = 0;
	rep(i, 10){
		if(v[i] == 1000) break;
		sum += v[i];
	}

	return sum;
}

int main(){

	while(1){
		int n;
		cin >> n;
		if(!n) break;

		int v[10][10];
		rep(i, 10){
			rep(j, 10){
				v[i][j] = INF;
				if(i == j)v[i][j] = 0;
			}
		}

		rep(i, n){
			int a, b, c;
			cin >> a >> b >> c;
			v[a][b] = v[b][a] = c;
		}

		//pp(v);

		rep(i, 10){
			rep(j, 10){
				rep(k, 10){
					v[j][k] = min(v[j][k], v[j][i] + v[i][k]);
				}
			}
		}

		int idx = 0;
		int sum = sum_v(v[0]);
		rep(i, 10){
			if(sum_v(v[i]) == 0)continue;
			if( sum_v(v[i]) < sum){
				idx = i;
				sum = sum_v(v[i]);
			}
		}

		//pp(v);

		cout << idx << ' ' << sum << endl;
	}

	

	return 0;
}

C++: /*************************************************************************
    > File Name: aoj0189.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017??´06???20??\ ????????? 14??¶54???14?§?
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int MAX_N = 100;
const int INF = 1e9;
int G[MAX_N][MAX_N];
int m , n;

void init(){
	for(int i = 0 ; i < MAX_N ; i++){
		for(int j = 0 ; j < MAX_N ; j++){
			if( i == j )	G[i][j] = 0;
			else			G[i][j] = INF;
		}
	}
}
void floyd(){
	for(int k = 0 ; k < n ; k++){
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				if( G[i][j] > G[i][k] + G[k][j] ){
					G[i][j] = G[i][k] + G[k][j];
				}
			}
		}
	}
}
void solve(){
	ll sum , num = -1 , maxsum = INF;
	for(int i = 0 ; i < n ; i++){
		sum = 0;
		for(int j = 0 ; j < n ; j++)	sum += (ll)G[i][j];
		if( maxsum > sum ){
			num = i ,	maxsum = sum;
		}
	}
	printf("%lld %lld\n",num , maxsum);
}
int main(){
	int u , v , cost;
	while(~scanf("%d",&m) && m){
		init();		n = -1;
		for(int i = 0 ; i < m ; i++){
			scanf("%d%d%d",&u,&v,&cost);
			G[u][v] = G[v][u] = cost;
			n = max( n , u );	n = max( n , v );
		}
		n++;		
		floyd();
		solve();
	}
	return 0;
}

C++: # include <iostream>
# include <algorithm>
# define MAX_N 10
# define INF 1e6

int n, m;

int d[MAX_N][MAX_N];

std::pair<int,int> solve(){
	for (int k = 0; k < n; ++k){
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < n; ++j){
				d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			std::cout << d[i][j] << ' ';
		}
		std::cout << std::endl;
	}

	int min = (INF), minv;
	for (int i = 0; i < n; ++i){
		int plus = 0;
		for (int j = 0; j < n; ++j)
			plus += d[i][j];
		if (min > plus){
			min = plus;
			minv = i;
		}
	}
	return std::pair<int, int>(minv, min);
}

int main(){
	while (1){
		for (int i = 0; i < 10; ++i){
			for (int j = 0; j < 10; ++j)
				d[i][j] = INF;
		}
		int f, t, c;
		std::cin >> m;
		if (m == 0)
			break;
		
		for (int i = 0; i < m; ++i){
			std::cin >> f >> t >> c;
			n = std::max(n, f);
			n = std::max(n, t);
			d[f][t] = c;
			d[t][f] = c;
		}
		for (int i = 0; i < n; ++i)
			d[i][i] = 0;
		std::cout << solve().first << ' ' << solve().second << std::endl;
	}
	return 0;
}