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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define INF 1 << 29
using namespace std;

int cost[10][10];

int main(){

  int n, town, from, to, c;
  while(scanf("%d", &n) && n){
    rep(i, 10) rep(j, 10) cost[i][j] = INF;
    rep(i, 10) cost[i][i] = 0;
    town = 0;
    rep(i, n){
      scanf("%d%d%d", &from, &to, &c);
      town = max(town, max(from, to));
      cost[from][to] = cost[to][from] = c;
    }
    town++;
    rep(k, town) rep(i, town) rep(j, town)
      cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);

    /*    rep(i, town){
      rep(j, town) printf("%d ", cost[i][j]<INF?cost[i][j]:-1);
      puts("");
      }*/

    int res1, res2 = INF;
    rep(i, town){
      int sum = 0;
      rep(j, town) if(cost[i][j] < INF) sum += cost[i][j];
      if(res2 > sum){
	res2 = sum;
	res1 = i;
      }
    }
    printf("%d %d\n", res1, res2);
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#define INF 0xfffffff
using namespace std;

int main() {
	int n;
	int a, b, c;
	int d[10][10];
	while (1) {
		for (int i = 0; i<10; i++)
			for (int j = 0; j<10; j++) {
				if (i == j)
					d[i][j] = 0;
				else d[i][j] = INF;
			}



		cin >> n;
		if (!n) return 0;
		for (int i = 0; i<n; i++) {
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;

		}

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


		int m, sc = INF;
		for (int i = 0; i<10; i++) {
			int a = 0;
			bool flag = false;
			for (int j = 0; j<10; j++) if (d[i][j] != INF && i!=j) { a += d[i][j]; flag = true; }
			if (sc>a && flag) { m = i; sc = a; }
		}
		cout << m << " " << sc << endl;
	}
}

C++: #include <iostream>

unsigned int inf = 1 << 28;

int dijk(int n,int s, int **g) {
	unsigned int sum = 0;
	bool *used = new bool[n];
	unsigned int *d = new unsigned int[n];

	// std::cout << "n = " << n << " " << "s = " << s << std::endl;

	for(int i = 0; i < n; i++)
		d[i] = inf;
	d[s] = 0;

	while(true) {
		int u = -1;
		for(int v = 0; v < n; v++)
			if(!used[v] && (u == -1 || d[v] < d[u]))
				u = v;

		// std::cout << "u = " << u << std::endl;

		if(u == -1) break;
		used[u] = true;

		for(int v = 0; v < n; v++)
			if(d[v] > d[u] + g[u][v])
				d[v] = d[u] + g[u][v];
	}

	for(int i = 0; i < n; i++) {
		sum += d[i];
	}

	// for(int i = 0; i < n; i++) {
	// std::cout << d[i] << std::endl;
	// }

	return sum;
}

int main() {
	do {
		int **g; // adjacency matrix, ?
		unsigned int *d;
		int *a, *b, *c;
		int edge = 0, min = 0, max = 0;
		unsigned int tmp = 0;

		std::cin >> edge;
		if(!edge) break;

		a = new int[edge];
		b = new int[edge];
		c = new int[edge];

		for(int i = 0;i < edge;i++) {
			std::cin >> a[i];
			std::cin >> b[i];
			std::cin >> c[i];
		}

		for(int i = 0; i < edge; i++) {
			if(max < a[i])
				max = a[i];
		}
		for(int i = 0; i < edge; i++) {
			if(max < b[i])
				max = b[i];
		}
		max++;

		g = new int*[max];
		d = new unsigned int[max];

		for(int i = 0; i < max; i++) {
			g[i] = new int[max];
		}

		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				g[i][j] = inf;

		for(int i = 0; i < edge; i++)
			g[b[i]][a[i]] = g[a[i]][b[i]] = c[i];

		for(int i = 0; i < max; i++)
			d[i] = dijk(max, i, g);

		min = d[0];
		for(int i = 1; i < max; i++) {
			if(min > d[i]) {
				min = d[i];
				tmp = i;
			}
		}

		std::cout << tmp << " " << min << std::endl;
		for(int i = 0; i < max; i++)
			delete[] g[i];
		delete[] g;
		delete[] a;
		delete[] b;
		delete[] c;
		delete[] d;

	}while(true);
	return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while(true){
	int N;
	cin >> N; if(N == 0) break;
	VVI edge(20, VI(20, 123456789));
	vector<bool> use(20, false);
	REP(i,N){
	  int a, b, c; cin >> a >> b >> c;
	  edge[a][b] = edge[b][a] = c;
	  use[a] = use[b] = true;
	}
	REP(i,20) edge[i][i] = 0;

	VI t;
	REP(i,20) if(use[i]) t.PB(i);
	int M = SZ(t);

	REP(i,M) REP(j, M) REP(k,M){
	  int a = t[i], b = t[j], c = t[k];
	  edge[b][c] = min(edge[b][c], edge[b][a] + edge[a][c]);
	}
	
	int idx, ans = 1234567890;
	REP(i,M){
	  int st = t[i];
	  int sum = 0;
	  REP(j,M){
		int to = t[j];
		sum += edge[st][to];
	  }
	  if(sum < ans){
		idx = st;
		ans = sum;
	  }
	}
	cout << idx << " " << ans << endl;
  }

  return 0;
}