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 <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <climits> 
#include <map>
using namespace std;
const int MAX_V = 1000; 
const int MAX_E = 2000; 
const int INF = 100000; 


struct E {
  int to, cost;
  E(int t, int c) : to(t), cost(c) {};
};

int v; 
vector<E> g[MAX_V]; 
int d[MAX_V]; 

bool bellmanford(int s)
{
  fill(d, d + v, INF);
  d[s] = 0;
  for(int k = 0; k < v; ++k){
    for(int j = 0; j < v; ++j){
      int from = j;
      for(int i = 0; i < g[from].size(); ++i){
	int to = g[from][i].to;
	int cost = g[from][i].cost;
	if(d[from] != INF && d[to] > d[from] + cost){
	  d[to] = d[from] + cost;
	  if(k == v - 1)return false;
	}
      }
    }
  }
  return true;
}
int main()
{
  for(;;){
    int gv, ge;
    cin >> ge;
    if(!ge){return 0;}
    set<int> s;

    for(int i = 0; i < ge; ++i){
      int gs, gt, gd;
      cin >> gs >> gt >> gd;
      g[gs].push_back(E(gt,gd));
      g[gt].push_back(E(gs,gd));
      s.insert(gs);
      s.insert(gt);
    }

    gv=s.size();
    v = gv;

    vector<pair<int,int> > p(s.size());

    set<int>::iterator it= s.begin();

    int count=0;
    while(it!=s.end()){
      bellmanford(*it);
      int sum=0;
      for(int i=0;i<v;i++){sum+=d[i];}
      //cout << sum << ":" << *it << endl;
      p[count].first=sum;
      p[count].second=*it;
      it++;
      count++;
    }

    sort(p.begin(),p.end());
  
    //for(int i=0;i<p.size();i++)
    cout << p[0].second << " " << p[0].first << endl;
  }
  return 0;
}

C++: #include <queue>
#include <vector>
#include <stdio.h>
using namespace std;

const int INF = 1e8;
struct edge{int to, cost;};
typedef pair<int, int> pii;
const int MAX_N = 50;
const int MAX_V = 15;
int n, V;
//ある街から出ている道
vector<edge> G[MAX_V];
int d[MAX_V];

int dijkstra(int s){
    int ret = 0;
    priority_queue<pii, vector<pii>, greater<pii> > que;
    fill(d, d+V, INF);
    
    d[s] = 0;
    que.push(pii(0, s));
    
    while(!que.empty()){
        pii p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v]+e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(pii(d[e.to], e.to));
            }
        }
    }
    for(int i=0; i<V; i++)
        ret += d[i];
    return ret;
}

void solve(){
    int ans = INF, num;
    int vmax = 0;
    int from, to, cost;
    for(int i=0; i<n; i++){
        scanf("%d%d%d", &from, &to, &cost);
        G[from].push_back(edge{to, cost});
        G[to].push_back(edge{from, cost});
        vmax = max(vmax, max(from, to));
    }
    V = vmax+1;
    for(int i=0; i<V; i++){
        int tmp;
        if ((tmp = dijkstra(i)) < ans){
            ans = tmp;
            num = i;
        }
    }
    printf("%d %d\n", num, ans);
}

int main(){
    while(scanf("%d", &n), n)
        solve();
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<map>
#include<string>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

typedef pair<double,pair<int,int> > pp;

#define MAX (10000000)

int main(){
  int n;
  while(scanf("%d",&n), n){
    int ct[10][10];
    int m = 0;
    REP(i,10) REP(j,10) ct[i][j] = (i==j?0:MAX);
    REP(i,n){
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      m = max(m, a); m = max(m, b);
      ct[a][b] = ct[b][a] = min(ct[a][b], c);
    }
    m++;

    REP(k,m) REP(i,m) REP(j,m)
      ct[i][j] = min(ct[i][j], ct[i][k]+ct[k][j]);

    int ans = -1;
    int d = INT_MAX;
    REP(i,m){
      int sum = 0;
      REP(j,m) sum+=ct[i][j];
      if(sum < d){
	ans = i;
	d = sum;
      }
    }

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

C++: #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#define MAX_V 10
#define INF 1000000
#define NIL -1
using namespace std;

struct edge {int to,cost;};
typedef pair<int,int> P;	//first:最短距離 second:頂点番号


int d[MAX_V];

void dijkstra(int s,vector<edge> G[]){
	//greater<P>を指定することでfirstが小さい順に取り出せるようになる
	priority_queue<P,vector<P>,greater<P>> que;
	//fill(d,d+V,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()){
		P p = que.top();que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;//最短距離でなければ無視する
		for(int i = 0;i < G[v].size();i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
	
}

int E;
bool cities[MAX_V];//その番号の町が出てくるか否か

int main(){
	cin >>E;
	while(E != 0){
		vector<edge> G[MAX_V];		//隣接リスト
		fill(cities,cities + MAX_V,false);
		int a,b,cost;
		for(int i = 0;i < E;i++){
			cin >>a >>b >>cost;
			cities[a] = true;cities[b] = true;
			edge e;e.to = b;e.cost = cost;
			G[a].push_back(e);
			e.to = a;
			G[b].push_back(e);
		}
		int mini = INF;int num = NIL;
		for(int i = 0;i < MAX_V;i++){
			fill(d,d+MAX_V,INF);
			for(int j = 0;j < MAX_V;j++){
				if(!cities[j])d[j] = 0;}
			dijkstra(i,G);
			int min_tmp= 0;
			for(int k = 0;k < MAX_V;k++)min_tmp += d[k];
			if(min_tmp < mini){mini = min_tmp;num = i;}
		}
		cout <<num <<" " <<mini <<endl;
		cin >>E;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
int main(void){
  int n;
  int maze[10][10];
  while(cin>>n,n){
    int u=0;
    rep(i,10)rep(j,10)maze[i][j]=int(1e9);
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      u=max(a,max(u,b));
      maze[a][b]=c;
      maze[b][a]=c;
    }
    u++;
    //rep(i,u)rep(j,u)cout<<maze[i][j]<<(j==u-1?'\n':' ');
    rep(i,u)rep(j,u)rep(k,u)
      maze[i][j]=min(maze[i][j],maze[i][k]+maze[k][j]);
    int res=int(1e9);
    int sum;
    int rnum=0;
    rep(i,u){
      sum=0;
      rep(j,u)if(i!=j)sum+=maze[i][j];
      if(res>sum){
	res=sum;rnum=i;
      }
    }
    cout<<rnum<<" "<<res<<endl;
  }
}