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>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)

const int INF = 10000000;
const int MAX_V = 10;
int d[MAX_V][MAX_V];
int E;

void init() {
    REP(i, MAX_V) {
        REP(j, MAX_V) {
            if (i == j) d[i][j] = 0;
            else        d[i][j] = INF;
        }
    }
}

void make() {
    REP(i, E) {
        int u, v, c;
        cin >> u >> v >> c;
        d[u][v] = c; d[v][u] = c;
    }
}

void wf() {
    REP(k, MAX_V) {
        REP(i, MAX_V) {
            REP(j, MAX_V) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

void answer() {
    int town = 0, min_sum = INF;

    REP(i, MAX_V) {
        int row_sum = 0;
        REP(j, MAX_V) {
            if (d[i][j] < INF)
                row_sum += d[i][j];
        }

        //row_sum > 0 means i is not isolate
        if (row_sum > 0 && row_sum < min_sum) {
            min_sum = row_sum;
            town = i;
        }
    }

    cout << town << ' ' << min_sum << endl;
}

void solve() {
    while (true) {

        cin >> E;

        if (E == 0) break;

        init();

        make();

        wf();

        answer();
    }
}


int main() {
    solve();
    return 0;
}

C++: #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 count1[10];
		for(int k=0;k<m;k++){
			int count=0;
			for(int i=0;i<m;i++){
				count=T[k][i]+count;
			}
			count1[k]=count;
		}
		int count2=count1[0];
		for(int k=0;k<m;k++){
			if(count1[k]<count2)
				count2=count1[k];
		}
		for(int k=0;k<m;k++){
			if(count1[k]==count2)
				cout<<k<<" "<<count2<<endl;
		}

	}

	return 0;
}

C++: // g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int d[10][10];

int main(){
	while(1){
		cin>>n;
		if(n==0) break;
		REP(i,10)REP(j,10)d[i][j]=INF;
		REP(i,10)d[i][i]=0;
		int v = 0;
		REP(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			v = max(v,max(a,b));
			d[a][b]=c; d[b][a]=c;
		}
		v++;

		REP(k,v)REP(i,v)REP(j,v) d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
		int resa = 0, resb = INF;
		REP(i,v){
			int sum = 0;
			REP(j,v) sum+=d[i][j];
			if(resb>sum){
				resa=i; resb=sum;
			}
		}
		cout<<resa<<" "<<resb<<endl;
	}

	return 0;
}

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

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n;
struct Edge {
    int to, cost;
    Edge(int to, int cost) : to(to), cost(cost) {}
};
using P = pair<int, int>;
vector<Edge> G[50];
set<int> vs;
int dijkstra(int s) {
    int dp[50];
    rep(i, 50) dp[i] = INF;
    priority_queue<P> que;
    que.push(P(0, s));
    dp[s] = 0;
    while (que.size()) {
        auto p = que.top();
        que.pop();
        int v = p.second;
        if (dp[v] < -p.first) continue;
        rep(i, G[v].size()) {
            auto e = G[v][i];
            if (dp[e.to] > dp[v] + e.cost) {
                dp[e.to] = dp[v] + e.cost;
                que.push(P(-dp[e.to], e.to));
            }
        }
    }
    int ret = 0;
    for (auto v : vs) {
        ret += dp[v];
    }
    return ret;
}
int main() {
    while (cin >> n, n) {
        vs.clear();
        rep(i, n) {
            int a, b, c;
            cin >> a >> b >> c;
            G[a].push_back(Edge(b, c));
            G[b].push_back(Edge(a, c));
            vs.insert(a);
            vs.insert(b);
        }
        int ans = INF;
        int ans_v = -1;
        for (auto v : vs) {
            auto ret = dijkstra(v);
            if (ans > ret) {
                ans = ret;
                ans_v = v;
            }
        }
        cout << ans_v << " " << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#define inf 1000000000
using namespace std;
unsigned long long d[10][10],sum[10];
int v;

int main()
{
	int n;
	while(cin>>n,n)
	{
		bool used[10];
		memset(used,0,sizeof(used));
		memset(d,0,sizeof(d));
		memset(sum,0,sizeof(sum));
		for(int i=0;i<n;i++)
		{
			int s,t,c;
			cin>>s>>t>>c;
			used[s]=used[t]=true;
			d[s][t]=d[t][s]=c;
		}
		v=0;
		for(int i=0;i<10;i++)
		{
			if(used[i]) v++;
			for(int j=0;j<10;j++)
			{
				if(d[i][j]==0&&i!=j) d[i][j]=inf;
			}
		}

		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 ans;
		for(int i=0;i<v;i++)
		{
			for(int j=0;j<v;j++)
			{
				sum[i]+=d[i][j];
			}
		}
		ans=min_element(sum,sum+v)-sum;
		cout<<ans<<" "<<sum[ans]<<endl;

	}
	return 0;
}