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

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n;
struct Edge {
    int to, cost;
    Edge(int to, int cost) : to(to), cost(cost) {}
};
using P = pair<int, int>;
vector<Edge> G[50];
set<int> vs;
int dijkstra(int s) {
    int dp[50];
    rep(i, 50) dp[i] = INF;
    priority_queue<P> que;
    que.push(P(0, s));
    dp[s] = 0;
    while (que.size()) {
        auto p = que.top();
        que.pop();
        int v = p.second;
        rep(i, G[v].size()) {
            auto e = G[v][i];
            if (dp[e.to] > dp[v] + e.cost) {
                dp[e.to] = dp[v] + e.cost;
                que.push(P(-dp[e.to], e.to));
            }
        }
    }
    int ret = 0;
    for (auto v : vs) {
        ret += dp[v];
    }
    return ret;
}
int main() {
    while (cin >> n, n) {
        vs.clear();
        rep(i, 50) G[i].clear();
        rep(i, n) {
            int a, b, c;
            cin >> a >> b >> c;
            G[a].push_back(Edge(b, c));
            G[b].push_back(Edge(a, c));
            vs.insert(a);
            vs.insert(b);
        }
        int ans = INF;
        int ans_v = -1;
        for (auto v : vs) {
            auto ret = dijkstra(v);
            if (ans > ret) {
                ans = ret;
                ans_v = v;
            }
        }
        cout << ans_v << " " << ans << endl;
    }
    return 0;
}

C++: #include <queue>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m;
const int max_n = 15;
const int INF = 0x3f3f3f3f;

/*********************************************************

int dis[max_n][max_n];
void floyd(int m){
    for(int k = 0; k <= m; ++k)
        for(int i = 0; i <= m; ++i)
            for(int j = 0; j <= m; ++j)
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}

*********************************************************/
/*********************************************************
//bool vis[max_n];
//int d[max_n];
void dijkstra(int s){
    memset(vis, false, sizeof(vis));
    memset(d,INF, sizeof(d));
    d[s] = 0;
    while(1){
        int index = -1;
        for(int j = 0; j <= m; ++j)
            if(!vis[j] && (index == -1 || d[j] < d[index])) index = j;
        if(index == -1) break;
        vis[index] = true;
        for(int j = 0; j <= m; ++j)
            d[j] = min(d[j], d[index] + dis[index][j]);
    }
}

*********************************************************/

int d[max_n];
bool vis[max_n];
int dis[max_n][max_n];
void spfa(int s){
    memset(d, INF, sizeof(d));
    memset(vis, false, sizeof(vis));
    vis[s] = true;
    d[s] = 0;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        int index = que.front();
        que.pop();
        vis[index] = false;
        for(int i = 0; i <= m; ++i)
            if(d[i] > d[index] + dis[index][i]){
                d[i] = d[index] + dis[index][i];
                if(!vis[i]) que.push(i), vis[i] = true;
            }
    }
}

/*********************************************************

//int d[max_n];
struct e{int from, to, cost;}p[max_n];
void bellman(int s){
    memset(d, INF, sizeof(d));
    d[s] = 0;
    while(true){
        bool update = false;
        for(int i = 0; i < n; ++i){
            if(d[p[i].from] != INF && d[p[i].to] < d[p[i].from] + p[i].cost)
                d[p[i].to] = d[p[i].from] + p[i].cost, update = true;
        }
        if(!update) break;
    }
}

*********************************************************/

int main(){
    ios::sync_with_stdio(false);
    while(cin >> n && n){
        for(int i = 0; i < max_n; ++i) fill(dis[i], dis[i] + max_n, INF), dis[i][i] = 0;
        m = 0;
        while(n--){
            int x, y, d;
            cin >> x >> y >> d;
            //cin >> p[i].from >> p[i].to >> p[i].cost;
            m = max(m, max(x, y));
            dis[x][y] = dis[y][x] = d;
        }
        //floyd(m);
        int ans = INF, index = 0;
        for(int i = 0; i <= m; ++i){
            //dijkstra(i);
            spfa(i);
            int temp = 0;
            for(int j = 0; j <= m; ++j) temp += d[j];
            if(temp < ans) ans = temp, index = i;
        }
        cout << index << " " << ans << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 10000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
struct edge{int to,cost;};
int N;
int d[10];
bool f[10];
vector<edge> G[10];
void dijkstra(int s){
      REP(i,N)d[i]=-1;
      d[s]=0;
      priority_queue<P,vector<P>,greater<P> > Q;
      Q.push(P(0,s));
      while(!Q.empty()){
            P p=Q.top();Q.pop();
            int v=p.second;
            if(d[v]>p.first)continue;
            REP(i,G[v].size()){
                  edge e=G[v][i];
                  if(d[e.to]==-1||d[e.to]>d[v]+e.cost){
                        d[e.to]=d[v]+e.cost;
                        Q.push(P(d[e.to],e.to));
                  }
            }
      }
}
int main(){
      while(cin>>N&&N){
            memset(f,false,sizeof(f));
            REP(i,N){
                  int a,b,c;
                  cin>>a>>b>>c;
                  G[a].PB((edge){b,c});
                  G[b].PB((edge){a,c});
                  f[a]=f[b]=true;
            }
            ll ans=-1,pos=-1;
            REP(i,10){
                  if(!f[i])continue;
                  int sum=0;
                  dijkstra(i);
                  REP(j,10)if(f[j])sum+=d[j];
                  if(ans==-1||ans>sum){
                        ans=sum;
                        pos=i;
                  }
            }
            cout<<pos<<" "<<ans<<endl;
      }
}