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 <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#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 ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

#define INF 999999
#define MAX_V 999

using namespace std;

struct Node{
	int cost;
	int depart;
	int arrival;
};

vector<Node> dat;
vector<int> cost;

void dijkstra(int s){
	int pos;
	queue<int> q;
	int t;
	cost.at(s)=0;
	
	for(vector<Node>::iterator i=dat.begin();i!=dat.end();i++){
		if((*i).depart==s){
			q.push((*i).arrival);
			cost.at((*i).arrival)=(*i).cost;
		}
	}
	
	while(!q.empty()){
		
		pos=q.front();
		q.pop();
		
		for(vector<Node>::iterator i=dat.begin();i!=dat.end();i++){			if((*i).depart==pos){
				if(cost.at((*i).arrival)==INF){
					q.push((*i).arrival);
				}
				if(cost.at((*i).arrival)>(*i).cost+cost.at(pos)){
					cost.at((*i).arrival)=(*i).cost+cost.at(pos);
				}
			}
		}
		bool f=true;
		rep(i,cost.size()){
			if(cost.at(i)==INF){
				f=false;
			}
		}
		if(f){
			break;
		}
	}
}

int main(){
	int a, b, c, num;
	Node t;
	int n;
	while(cin>>n,n){
		num=0;
		dat.clear();
		cost.clear();
		rep(i,n){
			cin>>a>>b>>c;
			t.depart =a;
			t.cost   =c;
			t.arrival=b;
			dat.push_back(t);
			t.depart =b;
			t.cost   =c;
			t.arrival=a;
			dat.push_back(t);
			num=max(num,max(a,b));
		}
		rep(k,n+1){
			cost.push_back(INF);
		}
		int mini=-1, mCost=INF;
		rep(i,num+1){
			int sum=0;
			cost.clear();
			rep(k,num+1){
				cost.push_back(INF);
			}
			dijkstra(i);
			rep(j,num+1){
				sum+=cost.at(j);
			}
			if(sum<mCost){
				mCost=sum;
				mini=i;
			}
		}
		cout<<mini<<" "<<mCost<<endl;
	}
	return 0;
}

C++: /* Warshall-Floyd Algorithm */

#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int wf[10][10];
	for(int n_road;cin>>n_road,n_road;){
		for(int i=0;i<10;i++)for(int j=0;j<10;j++)wf[i][j]=10000;

		int n_city=0;
		for(int i=0;i<n_road;i++){
			int a,b,c;	cin>>a>>b>>c;
			n_city=max(n_city,max(a+1,b+1));
			wf[a][b]=wf[b][a]=c;
		}

		for(int k=0;k<n_city;k++){
			for(int i=0;i<n_city;i++){
				for(int j=0;j<n_city;j++){
					if(i==j)	wf[i][j]=0;
					wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j]);
				}
			}
		}

		int opt=10000,iopt;
		for(int i=0;i<n_city;i++){
			int sum=0;
			for(int j=0;j<n_city;j++)	sum+=wf[i][j];
			if(opt>sum)	opt=sum,iopt=i;
		}
		cout<<iopt<<' '<<opt<<endl;
	}
	return 0;
}

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

#define INF (1<<29)

using namespace std;



int main(void){

  int a,b,c,g[10][10],n,sum[10];

  while(cin >> n,n){
    fill(sum,sum+10,0);
    fill(g[0],g[10],INF);

    for(int i=0;i<10;i++)g[i][i]=0;

    for(int i=0;i<n;i++){
      cin >> a >> b >> c;
      g[a][b]=g[b][a]=c;
    }

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

    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
        if(g[i][j]<INF)sum[i]+=g[i][j];

    int ans1=INF,ans2=0;
    for(int i=0;i<10;i++)
      if(ans1>sum[i] && sum[i]>0)ans1=sum[i],ans2=i;

    cout << ans2 << " " << ans1 << endl;
  }


  return 0;
}

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;



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;
		}*/
		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]);
				}
			}
		}
		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;
	}
}