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>
#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 MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
const int INF=1e9;
struct edge{int to,cost;};
int N,city;
vector<edge> G[100];
int dijkstra(int s){
      int d[city];
      REP(i,city)d[i]=INF;
      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 sum=0;
      REP(i,city)sum+=d[i];
      return sum;
}
int main(){
      while(cin>>N&&N){
            REP(i,10)G[i].clear();
            city=-1;
            REP(i,N){
                  int a,b,c;
                  cin>>a>>b>>c;
                  G[a].PB((edge){b,c});
                  G[b].PB((edge){a,c});
                  city=max(city,max(a,b));
            }
            city++;
            ll ans=INF,pos=-1;
            REP(i,city){
                  int sum=dijkstra(i);
                  if(ans>sum){
                        ans=sum;
                        pos=i;
                  }
            }
            cout<<pos<<" "<<ans<<endl;
      }
}

C++: #include<iostream>
#include<map>
using namespace std;

int main(){
  int n,a,b,c,N;
  int matrix[110][110];
  int sum[110],Min;
  map<int,bool> index;
  while(cin >> n && n){
    index.clear();
    for(int i=0;i<110;i++)for(int j=0;j<110;j++)matrix[i][j] = i==j?0:1<<20;
    for(int i=0;i<n;i++){
      cin >> a >> b >> c;
      index[a] = true;
      index[b] = true;
      matrix[a][b] = matrix[b][a] = c;
    }
    N = index.size();
    for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)matrix[i][j] = min(matrix[i][j],matrix[i][k]+matrix[k][j]);
    Min=1<<22;
    for(int i=0;i<N;i++){
      sum[i]=0;
      for(int j=0;j<N;j++){
	sum[i]+=matrix[i][j];
      }
      Min = min(Min,sum[i]);
    }
    for(int i=0;i<N;i++){
      // cout << sum[i] << endl;
      if(Min == sum[i]){
	cout << i << " " << sum[i] << endl; 
	  break;
      }
    }

  }
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)

const int INF = 10000000;
const int MAX_V = 1000;
int graph[MAX_V][MAX_V];
int n;

bool visited[MAX_V];
int cost[MAX_V];

void init_graph() {
    REP(i, MAX_V) {
        REP(j, MAX_V) {
            if (i == j) graph[i][j] = 0;
            else        graph[i][j] = INF;
        }
    }
}

void make() {
    REP(i, n) {
        int u, v, c;
        scanf("%d %d %d", &u, &v, &c);
        graph[u][v] = c; graph[v][u] = c;
    }
}

void init_dijkstra() {
    REP(i, MAX_V) visited[i] = false;
    REP(i, MAX_V) cost[i] = INF;
}

void dijkstra(int start) {
    init_dijkstra();

    cost[start] = 0;

    while (true) {
        int mi = INF;
        int nxt = -1;
        visited[start] = true;
        REP(i, MAX_V) {
            if (visited[i]) continue;
            if (i != start) {
                int d = cost[start] + graph[start][i];
                if (d < cost[i]) {
                    cost[i] = d;
                }
            }
            if (mi > cost[i]) {
                mi = cost[i];
                nxt = i;
            }
        }
        start = nxt;
        if (nxt == -1) break;
    }
}

void solve() {
    while (true) {
        scanf("%d", &n);

        if (n == 0) break;

        init_graph();

        make();

        int mi = INF;
        int town = 0;
        REP(i, MAX_V) {
            dijkstra(i);
            int sm = 0;
            REP(j, MAX_V) {
                if (cost[j] < INF)
                    sm += cost[j];
            }
            if (sm > 0 && sm < mi) {
                mi = sm;
                town = i;
            }
        }

        printf("%d %d\n", town, mi);
    }
}

int main() {
    solve();
    return 0;
}

C++: #include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <utility>

#define dprintf(s,...) printf("%s:%d" s,__func__,__LINE__,__VA_ARGS__)
using namespace std;

typedef pair<int,int> P;
typedef long long int ll;

class Edge{
public:
  int to,cost;
  Edge(int t,int c){
    to = t;
    cost = c;
  }
};

int n,k;
int d[10][10];
vector<Edge> G[10];

void dijekstra(int s){

  priority_queue<P, vector<P>, greater<P> > qu;

  qu.push(P(0,s));
  d[s][s]=0;
  
  while(!qu.empty()){

    P v=qu.top();
    qu.pop();

    if(d[s][v.second] < v.first) continue;

    for(int i=0; i<G[v.second].size(); i++){
      Edge e = G[v.second][i];
      if(d[s][v.second]+e.cost < d[s][e.to]){
	d[s][e.to] = d[s][v.second]+e.cost;
	qu.push(P(d[s][e.to], e.to));
      }
    }
    
  }

}

void solve(){

  for(int i=0;i<k;i++)
    for(int j=0;j<k;j++){
      d[i][j]=INT_MAX/3;
    }

  for(int i=0;i<k;i++){
    dijekstra(i);
  }
}


int main(){

  ios_base::sync_with_stdio(false);
  
  while(1){

    k=0;
    
    cin>>n;
    if(n==0) break;
    
    
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b>>c;
      Edge e1(a,c),e2(b,c);
      G[a].push_back(e2);
      G[b].push_back(e1);
      k = max(k,max(a,b));
    }
    k++;
    //cout<<"k="<<k<<endl;
    solve();
    
    int sum[10];
    int ans, min_cost=INT_MAX/3;
    fill(sum,sum+10,0);

    for(int i=k-1;i>=0;i--){
      for(int j=0; j<k; j++){
	sum[i] += d[i][j];
      }
      if(sum[i] < min_cost){
	ans = i;
	min_cost = sum[i];
      }
    }
    cout<<ans<<" "<<min_cost<<endl;
    for(int i=0;i<10;i++){
      G[i].erase(G[i].begin(), G[i].end());
    }    
  }


  
  
  return 0;
}