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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

const int MAX_M = 10;
const int INT_MAX = 1 << 30;

struct Edge{ int u, v, cost; };

int dijkstra(vector<Edge>& edges, int m, int s)
{
	vint d(m, INT_MAX);
	d[s] = 0;
	
	bool update = true;
	while(update)
	{
		update = false;
		
		rep(i, edges.size())
		{
			Edge e = edges[i];
			
			if(d[e.u] != INT_MAX && d[e.u] + e.cost < d[e.v])
			{
				d[e.v] = d[e.u] + e.cost;
				update = true;
			}
			
			if(d[e.v] != INT_MAX && d[e.v] + e.cost < d[e.u])
			{
				d[e.u] = d[e.v] + e.cost;
				update = true;
			}
		}
	}
	
	return accumulate(ALL(d), 0);
}

int main()
{
    int n;
	while(cin >> n && n)
	{
		int cost = INT_MAX, index = 0, m = 0;
		vector<Edge> edges(n);
		
		rep(i, n)
		{
			cin >> edges[i].u >> edges[i].v >> edges[i].cost;
			chmax(m, max(edges[i].u, edges[i].v) + 1);
		}
		
		rep(i, m)
		{
			int tmp = dijkstra(edges, m, i);
			
			if(tmp < cost)
			{
				index = i;
				cost = tmp;
			}
		}
		
		cout << index << " " << cost << endl;
	}
}

C++: #include <iostream>
#include <limits.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;i++)
 
int main(){
	int n,a,b,c;
	int mi,mx,t_num,now;
 
	int t[10][10];
	while(cin >> n && n){
		/*ú»*/
		REP(i,10)
		 REP(j,10)
		  if(i!=j)t[j][i] = INT_MAX/2; //WFÌZpI[o[t[h~
		  else t[i][j]=0;
		mx=0;mi=INT_MAX;
 
		/*üÍ*/
		REP(i,n){
			cin >> a >> b >> c;
			t[a][b]=t[b][a]=c;
			mx = max(mx,max(a,b)); //XÌÅåðmxÉãü
		}
 
		/*S_ÎÅZoHðßé([VtCh@)*/
		REP(k,mx+1) // k<mx+1 Í k<=mxÆ¿ (®¾©ç)
		 REP(i,mx+1)
		  REP(j,mx+1)
		   t[i][j]=t[j][i]=min(t[i][k]+t[k][j],t[i][j]);
 
		/*S_ÔË»Ìn_ÖÌ£aªÅà¬³¢àÌðL^*/
		REP(i,mx+1){
			now=0;
			REP(j,mx+1)now+=t[j][i];
			if(mi>now){
				t_num=i;
				mi=now;
			}
		}
 
		/*oÍ*/
		cout << t_num << " " << mi << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#define rep(i,a) for(int i=0;i<(a);++i)
const int INF = 1<<30;
#define _m_ 1
struct edge{
	int from, to, cost; 
	edge () {}
	edge(int f, int t, int c){
		from=f;
		to=t;
		cost=c;
	}
};
typedef std::pair<int, int> P;

int V;
std::vector<edge> es;
int d[11];
int maxm=0;
int SP(int s){
	rep(i, maxm+1)d[i] = INF;
	d[s] = 0;
	while(_m_){
		bool update = false;
		rep(i, es.size()){
			edge e = es[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if(!update)break;
	}
	int res = 0;
	rep(i, maxm+1){
		//if(i == s)continue;
		if(d[i] != INF)res += d[i];
	}
	
	return res;
}

int main(){
	int n;
	while(scanf("%d",&n) && n){
		es.clear();
		maxm=0;
		for(int i = 0 ; i < n; ++i){
			int a, b, c;
			scanf("%d %d %d",&a, &b, &c);
			edge ac(a,b,c);
			edge bc(b,a,c);
			es.push_back(ac);
			es.push_back(bc);
			maxm=std::max(maxm,std::max(a,b));
		}
		V = n;
		P ans=P(0, SP(0));
		
		for(int i = 0; i < maxm + 1; ++i){
			if(ans.second > SP(i)){
				ans.second = SP(i);
				ans.first = i;
			}
			//printf("OK\n");
			//printf("%d %d\n", i, SP(i));
		}
		printf("%d %d\n", ans.first, ans.second);
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;

int main(){
	int n;
	while(scanf("%d",&n),n){
		int D[16][16] = {{0}};
		rep(i,16){
			rep(j,16){
				if(i != j)D[i][j] = INF;
			}
		}
		int v = 0;
		rep(i,n){
			int from,to,cost;
			scanf("%d%d%d",&from,&to,&cost);
			D[from][to] = cost;
			D[to][from] = cost;
			v = max(v,max(from,to));
		}
		v++;
		int sum = INF,town = 0;
		rep(k,v){
			rep(i,v){
				int x = 0;
				rep(j,v){
					D[i][j] = min(D[i][j],D[i][k]+D[k][j]);
					x += D[i][j];
				}
				if(x != 0 && x < sum){
					sum = x;
					town = i;
				}
			}
		}

		printf("%d %d\n",town,sum);
	}
	return 0;
}

C++: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 10000000
#define rep(i,n) for (int i=0;i<(n);i++)
#define rev(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vp;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

int d[10][10];

void washall_floyd(int v) {
  rep(k,v)
    rep(i,v)
      rep(j,v)
        d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
}

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

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

    rep(i,n+1) rep(j,n+1) d[i][j] = INF;
    rep(i,n+1) d[i][i] = 0;

    rep(i,n) {
      int a,b,cost;
      cin >> a >> b >> cost;
      d[a][b] = cost;
      d[b][a] = cost;
     }

     washall_floyd(n+1);

    //  rep(i,n+1){ rep(j,n+1) { cout << d[i][j] << " ";} cout << endl;}

    int num = 0;
    int min = 0;
    rep(j,n+1)
      if(d[0][j] != INF) min += d[0][j];

      rep(i,n+1) {
        int tmp = 0;
        rep(j,n+1)
          if(d[i][j] != INF) tmp += d[i][j];
        if(tmp < min && tmp != 0) { min = tmp; num = i;}
      }
      cout << num << " " << min << endl;
  }

	return 0;
}