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 <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;

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

struct edge{
	int to, cost;
};

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

		vector<vector<int> > v(10, vector<int>(10, INF));
		int m=0;
		REP(i, n){
			int f, t, c;
			scanf("%d %d %d", &f, &t, &c);
			m=max(m, f);
			m=max(m, t);
			v[f][t]=c;
			v[t][f]=c;
		}
		m++;
		REP(i, m) v[i][i]=0;

		REP(i, m){
			REP(j, m){
				REP(k, m){
					if(v[i][j]>v[i][k]+v[k][j]){
						v[i][j]=v[i][k]+v[k][j];
					}
				}
			}
		}

		int ans=0;
		vector<int> sum(10, 0);
		REP(i, m){
			REP(j, m){
				if(v[i][j]>=INF) continue;
				sum[i]+=v[i][j];
			}
			if(sum[ans]>sum[i]) ans=i;
		}

		printf("%d %d\n", ans, sum[ans]);
	}
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int MAX_V = 10;
LL d[MAX_V][MAX_V];//d[i][j]???e={u,v}????????????(?????¨???????????¨??????INF,i==j?????¨??????0)
int v;

void warshall_floyd() {
	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 main() {
	while (cin >> v&&v) {
		REP(i, MAX_V)REP(j, MAX_V) {
			if (i == j)d[i][j] = 0;
			else d[i][j] = INF;
		}
		int a, b, c;
		REP(i,v) {
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
		}
		REP(i, MAX_V) {
			REP(j, MAX_V) {
				cout << d[i][j] << " ";
			}
			cout << endl;
		}

		warshall_floyd();
		LL ans = INF;
		int ans2;
		REP(i, MAX_V) {
			LL num = 0;
			REP(j, MAX_V) {
				if (d[i][j] == INF)continue;
				num += d[i][j];
			}
			if (num != 0 && ans > num) {
				ans = num;
				ans2 = i;
			}
		}
		cout << ans2 << " " << ans << endl;
	}
}

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

int main() {
  int a,b,c,n,i,j,k,d[10][10];
  while(cin >> n && n!=0) {
	  for (i=0;i<10;i++) for (j=0;j<10;j++) d[i][j]=999999999;
	  for (i=0;i<n;i++) {
		   cin >> a >> b >> c;
		   d[a][b]=d[b][a]=c; d[a][a]=d[b][b]=0;
	   }
	   for (i=0;i<10;i++) for (j=0;j<10;j++) for (k=0;k<10;k++) d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
	   c=999999999;
	   for (i=0;i<10;i++) {
		   if (d[i][i]>0) continue;
		   for (j=0,b=0;j<10;j++) if (d[i][j]<999999999) b+=d[i][j];
		   if (c>b) { a=i; c=b;}
	   }
	   cout << a << ' ' << c << endl;
	}
 return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>
 
#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max)) 
 
using namespace std;
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    while(1){
        int n,ans_k,ans_sum = INT_MAX,m = 0;
        cin >> n;
        if(n == 0) break;
        VI a(n),b(n),c(n);
        rep(i,n){
            cin >> a[i] >> b[i] >> c[i];
            if(m < a[i] || m < b[i])
                m = a[i] > b[i]? a[i]:b[i];
        }
        VI cost(m + 1);
        priority_queue<PII,vector<PII >,greater<PII> > que;
        rep(k,cost.size()){
            int res = 0;
            fill(all(cost), INT_MAX);
            que.push(mp(0,k));
            cost[k] = 0;
            while(!que.empty()){
                int d = que.top().first, u = que.top().second;
                que.pop();
                if(cost[u] < d) continue;
                rep(i,n){
                    if(u == a[i] && cost[u] + c[i] < cost[b[i]]){
                        cost[b[i]] = cost[u] + c[i];
                        que.push(mp(cost[b[i]], b[i]));
                    }
                    if(u == b[i] && cost[u] + c[i] < cost[a[i]]){
                        cost[a[i]] = cost[u] + c[i];
                        que.push(mp(cost[a[i]], a[i]));
                    }
                }
            }
            rep(i,cost.size()){
                res += cost[i];
            }
            if(res < ans_sum){
                ans_k = k;
                ans_sum = res;
            }
        }
        cout << ans_k << " " << ans_sum << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string.h>

using namespace std;

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

struct Road
{
	int a, b, c;
};

int n, a, b, c;

int table[10][10];
Road roads[45];

int main()
{
	while( 1 )
	{
		cin >> n;
		if(n == 0) break;

		memset(table, 0, sizeof(int) * 100);

		rep(i, n)
		{
			cin >> roads[i].a >> roads[i].b >> roads[i].c;
		}

		//Warhsall-Floyd
		int t = 0;
		rep(i, 10)
		{
			rep(j, 10)
			{
				rep(k, n)
				{
					if((roads[k].a == i && roads[k].b == j) ||
					   (roads[k].a == j && roads[k].b == i))
					{
						table[i][j] = roads[k].c;
						if(t < max(i, j))
							t = max(i, j);
						break;
					}
					else if(i == j)
					{
						table[i][j] = 0;
					}
					else
					{
						table[i][j] = 100000;
					}
				}
			}
		}

		rep(k, t+1)
		{
			rep(i, t+1)
			{
				rep(j, t+1)
				{
					if(table[i][j] > table[i][k] + table[k][j])
					{
						table[i][j] = table[i][k] + table[k][j];
					}
				}
			}
		}

		int min_cost = 100000;
		int town = 0;
		rep(i, t+1)
		{
			int total = 0;
			rep(j, t+1)
			{
				total += table[i][j];
			}

			if(total < min_cost)
			{
				town = i;
				min_cost = total;
			}
		}

		printf("%d %d\n", town, min_cost);
	}
}