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<cmath>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
#define INF 1000000
#define N 10


int main() {
	int n;
	while (1) {
		cin >> n;
		if (n==0)break;
		int dp[N][N];
		//?????????
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				dp[i][j] = INF;
			}
		}

		int a, b, c;
		while (n--) {
			cin >> a >> b >> c;
			dp[a][b] = c;
			dp[b][a] = c;
		}

		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
				}
			}
		}

		int sum[N];
		for (int i = 0; i < N; i++) {
			sum[i] = 0;
			for (int j = 0; j < N; j++) {
				if (i != j && dp[i][j] != INF) {
					sum[i] += dp[i][j];
				}
				
			}
		}

		int res = 0;
		for (int i = 1; i < N; i++) {

			if (sum[i] < sum[res] && sum[i] != 0) {
				res = i;
			}
		}

		cout << res << ' ' << sum[res] << endl;
	}


	return 0;
}

C++: #include <iostream>

#define UB 2000

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n == 0) break;
		int D[10][10];
		for (int i=0; i<10; i++) {
			for (int j=0; j<10; j++) D[i][j] = (i==j) ? 0 : UB;
		}
		int towns = 0;
		for (int i=0; i<n; i++) {
			int s, t, cost;
			std::cin >> s >> t >> cost;
			towns = std::max(towns, std::max(s, t));
			D[s][t] = D[t][s] = cost;
		}
		for (int k=0; k<=towns; k++) {
			for (int i=0; i<=towns; i++) {
				for (int j=0; j<=towns; j++) {
					D[i][j] = std::min(D[i][j], D[i][k] + D[k][j]);
				}
			}
		}
		int res = UB;
		int argres;
		for (int i=0; i<=towns; i++) {
			int sum = 0;
			for (int j=0; j<=towns; j++) sum += D[i][j];
			if (sum < res) { res = sum; argres = i; }
		}
		std::cout << argres << " " << res << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x>y?y:x)
#define INF 1000000
typedef long long ll;
typedef pair<int,ll> P;

ll cost[15][15];

int main()
{
	int n,max,num;
	ll sum,min;
	vector<P> vec;
	P min_p;

	while(cin>>n,n){
		num=0;
		min=INF;
		max=0;
		vec.clear();
		
		for(int i=0;i<15;i++){
			for(int j=0;j<15;j++){
				cost[i][j]=(i==j?0:INF);
			}
		}
		
		for(int i=0;i<n;++i){
			int a,b;
			ll c;
			cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
			if(max<MAX(a,b))max=MAX(a,b);

		}
		
		for(int i=0;i<=max;i++){
			for(int j=0;j<=max;j++){
				for(int k=0;k<=max;k++){
					cost[i][j]=MIN(cost[i][j],cost[i][k]+cost[k][j]);
				}
			}
		}
		
		for(int i=0;i<=max;i++){
			sum=0;
			for(int j=0;j<=max;j++){
				sum+=cost[i][j];
			}
			if(min>sum){
				min=sum;
				num=i;
			}	
		}
		cout<<num<<" "<<min<<endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:>
 ?????????============================================================
 
 =================================================================
 
 ?§£??¬=============================================================
 
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    ll G[10][10];
    bool used[10];
    while(cin >> n){
        if(n==0) break;
        for(int i = 0; i < 10;i++)for(int j = 0;j < 10;j++) G[i][j] = INF;
        for(int i = 0; i < 10;i++){
            used[i] = false;
            G[i][i] = 0;
        }
        for(int i = 0; i < n;i++){
            ll a,b,c; cin >> a >> b >> c;
            G[a][b] = min(G[a][b],c);
            G[b][a] = min(G[b][a],c);
            used[a] = used[b] = true;
        }
        for(int i = 0; i < 10;i++){
            for(int j = 0;j <10;j++){
                for(int k = 0;k < 10;k++){
                    G[i][j] = min(G[i][j],G[i][k]+G[k][j]);
                }
            }
        }
        ll id = -1,sum = INF;
        for(int i = 0; i < 10;i++){
            if(used[i] == false)continue;
            ll tmp = 0;
            for(int j = 0; j < 10;j++){
                if(i == j)continue;
                if(used[j] == false)continue;
                tmp += G[i][j];
            }
            if(tmp < sum){
                sum = tmp;
                id = i;
            }
        }
        cout << id << " " << sum << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main()
{
    int n;
    while (cin >> n, n) {
        int d[10][10];
        fill_n((int *)d, 10 * 10, INF);
        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            d[from][to] = d[to][from] = cost;
        }
        for (int k = 0; k < 10; k++) {
            for (int i = 0; i < 10; i++) {
                for (int j = i+1; j < 10; j++) {
                    d[i][j] = d[j][i] = min(d[i][k] + d[k][j], d[i][j]);
                }
            }
        }
        vi sums;
        for (int i = 0; i < 10; i++) {
            int sum = 0;
            for (int j : d[i]) {
                if (j != INF) sum += j;
            }
            if (sum != 0) sums.pb(sum);
        }
        int m = sums[0];
        int ind = 0;
        for (int i = 0; i < sums.size(); i++) {
            if (m > sums[i]) {
                m = sums[i];
                ind = i;
            }
        }
        cout << ind << " " << m << endl;
    }
    return 0;
}