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 <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while(cin>>n,n){  //,演算子、最後の式を評価
        vector<vector<int>> graph(10,vector<int>(10,99999999));
        int used[10]={0};
        for(int i=0;i<n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            graph[a][b]=c;
            graph[b][a]=c;
            used[a]++;
            used[b]++;
        }
        for(int i=0;i<10;i++){
           //if(used[i])
                graph[i][i]=0;
        }
        for(int k=0;k<10;k++){
            for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                    if(graph[i][j]>graph[i][k]+graph[k][j])
                        graph[i][j]=graph[i][k]+graph[k][j];
                }
            }
        }
        int min=99999999;
        int minpos;
        for(int i=0;i<10;i++){
            if(used[i]==0) continue;
            int sum=0;
            for(int j=0;j<10;j++){
                if(used[j]>0){
                    sum+=graph[i][j];
                }
            }
            if(min>sum){
                min=sum;
                minpos=i;
            }
        }
        cout<<minpos<<" "<<min<<endl;
    }
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<bits//stdc++.h>
#include<functional>
using namespace std;
struct P{
	long long cost,pos;
};
struct B{
	long long cost,to;
};
bool operator<(P a,P b){
	return a.cost<b.cost;
}
bool operator>(P a,P b){
	return a.cost>b.cost;
}
vector<B>e[10];
int main() {
	int n;
	while(cin>>n&&n!=0){
		for(int i=0;i<10;i++) e[i].clear();
		long long a,b,c,ma=0;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			e[a].push_back(B{c,b});
			e[b].push_back(B{c,a});
			ma=max(a,max(b,ma));
		}
		P sum;
		sum.cost=1000000;
		for(int i=0;i<=ma;i++){
			priority_queue<P, vector<P>, greater<P>>p;
			long long b[10];
			for(int j=0;j<10;j++) b[j]=1000000;
			b[i]=0;
			p.push(P{0,i});
			while(!p.empty()){
				P t=p.top();p.pop();
				for(int j=0;j<(int)e[t.pos].size();j++){
					if(b[t.pos]+e[t.pos][j].cost<b[e[t.pos][j].to]){
						b[e[t.pos][j].to]=b[t.pos]+e[t.pos][j].cost;
						p.push(P{b[e[t.pos][j].to],e[t.pos][j].to});
					}
				}
			}
			long long sum2=0;
			for(int j=0;j<=ma;j++){
				sum2+=b[j];
			}
			if(sum.cost>sum2){
				sum.cost=sum2;
				sum.pos=i;
			}
		}
		cout<<sum.pos<<" "<<sum.cost<<endl;
	}
}

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

const int INF = 1e8;
int d[45][45];

int main() {
    int n;
    while (cin >> n, n) {
        for (int i=0; i<45; ++i) {
            for (int j=0; j<45; ++j) {
                d[i][j] = (i == j ? 0 : INF);
            }
        }
        int a, b, c, vn = -1;
        for (int i=0; i<n; ++i) {
            cin >> a >> b >> c;
            d[a][b] = min(d[a][b], c);
            d[b][a] = min(d[b][a], c);
            vn = max(vn, max(a, b)+1);
        }
        for (int k=0; k<vn; ++k) {
            for (int i=0; i<vn; ++i) {
                for (int j=0; j<vn; ++j) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        int idx = -1, min_time = INF;
        for (int i=0; i<vn; ++i) {
            int time = 0;
            for (int j=0; j<vn; ++j) {
                time += d[i][j];
            }
            if (time < min_time) {
                idx = i;
                min_time = time;
            }
        }
        cout << idx << " " << min_time << endl;
    }
    return 0;
}

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

#define INF 1000000

typedef std::pair<int,int> to_cost;

std::vector<std::vector<to_cost> >v(10);
std::vector<int>min(10,INF);

void calc(int i){
	for(int j=0;j<v[i].size();j++){
		if(min[i]+v[i][j].second<min[v[i][j].first]){
			min[v[i][j].first]=min[i]+v[i][j].second;
			calc(v[i][j].first);
		}
	}
}

int main(){
	int n;
	std::cin>>n;
	while(n!=0){
		for(int i=0;i<10;i++)v[i].clear();
		int res=INF,res_num;
		std::vector<int>sum(10,0);
		for(int i=0;i<n;i++){
			int a,b,c;
			std::cin>>a>>b>>c;
			v[a].push_back(to_cost(b,c));
			v[b].push_back(to_cost(a,c));
		}
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++)min[j]=INF;
			min[i]=0;
			calc(i);
			for(int j=0;j<10;j++){
				if(min[j]!=INF)sum[i]+=min[j];
			}
		}
		for(int i=0;i<10;i++){
			if(res>sum[i]&&sum[i]!=0)res=sum[i],res_num=i;
		}
		std::cout<<res_num<<" "<<res<<std::endl;
		std::cin>>n;
	}
	return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int graph[15][15];

int v=0;

int main(void){
	int n;
	while(cin >> n,n){
		rep(i,15)rep(j,15) graph[i][j]=(i==j)?0:inf;
		v=-1;
		rep(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			v=max(v,max(a,b)+1);
			graph[a][b]=graph[b][a]=c;
		}
		rep(k,v)rep(i,v)rep(j,v){
			graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
		}
		int ansv=-1,anst=inf;

		rep(i,v){
			int cur=0;
			rep(j,v) cur+=graph[i][j];
			if(cur<anst)
				anst=cur,ansv=i;
		}

		cout << ansv <<  " " << anst << endl;
	}
	return 0;
}