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<stdio.h>
#define INF 999999
int route[100][100];
int node[11];
int route_num;

int main()
{
	while(1)
	{
		scanf("%d",&route_num);
		if(route_num==0)
			break;

		int min_cost=INF;
		int min_node=0;
		int node_num=0;
		for(int i=0;i<100;i++)
			for(int j=0;j<100;j++)
				route[i][j]=INF;

		for(int i=0;i<route_num;i++)
		{
			int from,to,cost;
			scanf("%d%d%d",&from,&to,&cost);
			route[from][to] = route[to][from] = cost;
			if(node_num < to)
				node_num=to;
			if(node_num < from)
				node_num=from;
		}

		for(int x=0;x<=node_num;x++)
		{
			for(int i=0;i<=node_num;i++)
				node[i]=INF;
			node[x]=0;

			while(1)
			{
				bool flag=false;
				for(int i=0;i<=node_num;i++)
				{
					for(int j=0;j<=node_num;j++)
					{
						if(node[i]!=INF && route[i][j]!=INF && node[j] > node[i]+route[i][j])
						{
							node[j]=node[i]+route[i][j];
							flag=true;
						}
					}
				}
				if(!flag)
					break;
			}
			int temp=0;
			for(int i=0;i<=node_num;i++)
				temp+=node[i];
			if(min_cost > temp)
			{
				min_cost=temp;
				min_node=x;
			}
		}
		printf("%d %d\n",min_node,min_cost);
	}
}

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<cstdio>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		
		
		int dp[111][111]={0};
		rep(i,111)rep(j,111)dp[i][j]=1000000000;
		
		
		int m=0;
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			dp[a][b]=min(c,dp[a][b]);
			dp[b][a]=min(c,dp[a][b]);
			
			m=max(m,max(a,b));
		}
		m++;
		rep(i,111)dp[i][i]=0;
		
		
		rep(k,111){
			rep(i,111){
				rep(j,111){
					dp[i][j] = min(dp[i][k]+dp[k][j],dp[i][j]);
				}
			}
		}
		
		
		int ans=1000000000;
		int minp=-1;
		rep(i,111){
			int sum=0;
			rep(j,111){
				if(dp[i][j]==1000000000)continue;
				sum+=dp[i][j];
			}
			if(sum==0)continue;
			
			if(ans>sum){
				minp=i;
				ans = sum;
			}
		}
		printf("%d %d\n",minp,ans);
	}
}

C++: #include <iostream>
#include <vector>

using namespace std;
struct edge
{
	int from;
	int to;
	int cost;
};
int d[11][11];
static const int INF = 99999999;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		for(int i = 0; i < 10; ++i)
		{
			for(int j = 0; j < 10; ++j)
			{
				d[i][j] = INF;
			}
			d[i][i] = 0;
		}
		for(int i = 0; i < n; ++i)
		{
			int from, to, dist;
			cin >> from >> to >> dist;
			d[from][to] = dist;
			d[to][from] = dist;
		}

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

		int min_sum_dist = INF;
		int pos = 0;
		for(int i = 0; i < 10; ++i)
		{
			int sum = 0;
			for(int j = 0; j < 10; ++j)
			{
				if(d[i][j] != INF)
				{
					sum += d[i][j];
				}
			}
			if(sum == 0)
			{
				continue;
			}
			if(min_sum_dist > sum)
			{
				min_sum_dist = sum;
				pos = i;
			}
		}
		cout << pos << " " << min_sum_dist << endl;
	}
}

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

C++: #include <cstdio>
#include <algorithm>

using namespace std;

#define chmin(a,b) a=min(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)

const int inf = 1e9;

int d[10][10];
int N;

void wf()
{
	rep(k, 10) rep(i, 10) rep(j, 10) {
		chmin(d[i][j], d[i][k] + d[j][k]);
	}
}

int main()
{
	while (scanf("%d", &N), N) {
		fill(d[0], d[10], inf);
		rep(i, 10) d[i][i] = 0;

		rep(i, N) {
			int a, b, c; scanf("%d %d %d", &a, &b, &c);
			d[a][b] = d[b][a] = c;
		}

		wf();

		int mi = inf, a;

		rep(i, 10) {
			int sum = 0;
			rep(j, 10) {
				if (d[i][j] != inf) sum += d[i][j];
			}
			if (sum != 0 && mi > sum) {
				mi = sum;
				a = i;
			}
		}

		printf("%d %d\n", a, mi);
	}
}

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

#define REP(i,n) for(int i = 0 ; i < n ; ++i)
using namespace std;
typedef long long Int;


Int dp[10][10];
Int INF = 999999999;
int n ;

vector<int> edges;

int main() {
    while(cin >> n , n) {

        REP(i, 100) {
            dp[i / 10][i % 10] = INF;
        }

        REP(i, n) {
            int a, b, c;
            cin >> a >> b >> c;
            dp[a][b] = c;
            dp[b][a] = c;
            dp[a][a] = 0;
            dp[b][b] = 0;

        }


        REP(k, 10) {
            REP(i, 10) {
                REP(j, 10) {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                }
            }
        }
        Int i_min(INF), v_min(INF);
        REP(i, 10) {
            Int sum(0);
            REP(j, 10) {
                if (dp[i][j] != INF)
                    sum += dp[i][j];
            }
            if (sum < v_min && sum) {
                v_min = sum;
                i_min = i;
            }
        }

        cout << i_min << " " << v_min << endl;
    }

    return 0;
}