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<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int N=11;

int mp[N][N];


int bfs(int n,int p){
  vector<int> time(n);
  queue<int> que;
  rep(i,n)time[i]=INF;
  time[p]=0;
  que.push(p);
  int u;
  while(!que.empty()){
    u=que.front(),que.pop();
    rep(i,n){
      if(time[i]>time[u]+mp[u][i]){
        time[i]=time[u]+mp[u][i];
        que.push(i);
      }
    }
  }
  int sum=0;
  rep(i,time.size())sum+=time[i];
  return sum;
}

signed main(){
  int n;
  while(cin>>n,n!=0){
    rep(i,N)rep(j,N)mp[i][j]=i==j?0:INF;
    int city[N]={};
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      mp[a][b]=mp[b][a]=c;
      city[a]++;
      city[b]++;
    }
    vector<int> d;
    rep(i,N)if(city[i]>0)d.pb(i);
    int e=d.size();
    int ans1,ans2=INF;
    rep(i,e){
      int temp=bfs(e,d[i]);
      if(ans2>temp){
        ans2=temp;
        ans1=i;
      }
    }
    cout<<ans1<<' '<<ans2<<endl;
  }
  return 0;
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0189
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int INF = 1<<28;
const int MAX = 10;
int main(){

  for(int n;cin>>n,n;){
    vector<vector<int>> d(MAX, vector<int> (MAX, INF));

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

    int node,time=INF;

    // i=起点 j=終点 k=iとjの間の点　起点からk点を経由して終点に行く
    for(int k=0;k<=max_node;++k)
      for(int i=0;i<=max_node;++i)
        for(int j=0;j<=max_node;++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    for(int i=0;i<=max_node;++i){
      int sum=0;
      for(int j=0;j<=max_node;++j){
        if(d[i][j]!=INF) sum += d[i][j];
      }
      if(time>sum){
        time = sum;
        node = i;
      }
    }

    cout << node << " " << time << endl;
  }

  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=50;
int time[maxn],minn,pos,n;
bool vis[maxn];
vector <pair<int,int> > ve[maxn];
void init() {
    pos=-1;
    minn=0x7f7f7f7f;
    for(int i=0;i<=n;i++)
        ve[i].clear();
    int m=0;
    for(int i=1;i<=n;i++) {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        ve[a].push_back(make_pair(b,c));
        ve[b].push_back(make_pair(a,c));
        m=max(m,a);
        m=max(m,b);
    }
    n=m;
}

void spfa(int s) {
    queue <int> qu;
    memset(vis,0,sizeof(vis));
    memset(time,0x7f,sizeof(time));
    qu.push(s);
    time[s] = 0;
    while(!qu.empty()) {
        int now=qu.front(); 
		qu.pop();
        vis[now]=false;
        for(int i=0;i<ve[now].size();i++) {
            int v=ve[now][i].first;
            int d=ve[now][i].second;
            if(d+time[now]<time[v]) {
                time[v]=time[now] + d;
                if(!vis[v]) {
                    qu.push(v);
                    vis[v] = true;
                }
            }
        }
    }
}

bool updatamin() {
    int sum=0;
    for(int i=0;i<=n;i++)
        sum+=time[i];
    if(sum<minn) {
        minn=sum;
        return true;
    }
    return false;
}

int main() {
    while(scanf("%d",&n)) {
    	if(n==0) break;
        init();
        for(int i=0;i<=n;i++) {
            spfa(i);
            if(updatamin()) {
                pos = i;
            }
        }
        printf("%d %d\n",pos,minn);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

struct edge{
	int to, cost;
};

int main(){
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0) return 0;

		vector<vector<llong> > v(15, vector<llong>(15, INF));
		int m=0;
		REP(i, n){
			int f, t, c;
			scanf("%d %d %d", &f, &t, &c);
			m=max(m, f);
			m=max(m, t);
			v[f][t]=c;
			v[t][f]=c;
		}
		m++;
		REP(i, m) v[i][i]=0;

		REP(i, m){
			REP(j, m){
				REP(k, m){
					v[j][k]=min(v[j][k], v[j][i]+v[i][k]);
					
				}
			}
		}

		int ans=0;
		vector<llong> sum(15, 0);
		REP(i, m){
			REP(j, m){
				if(v[i][j]>=INF) continue;
				sum[i]+=v[i][j];
			}
			if(sum[ans]>sum[i]) ans=i;
		}

		printf("%d %ld\n", ans, sum[ans]);
	}
}

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

const int INF = 1<<27;
int G[10][10];

int main() {
  int n;
  while(cin >> n && n) {
    fill(G[0],G[10],INF);
    for(int i = 0; i < 10; ++i) G[i][i] = 0;

    for(int i = 0; i < n; ++i) {
      int a, b;
      cin >> a >> b;
      cin >> G[a][b];
      G[b][a] = G[a][b];
    }
    for(int k = 0; k < 10; ++k) {
      for(int i = 0; i < 10; ++i) {
	for(int j = 0; j < 10; ++j) {
	  if(G[i][k] == INF || G[k][j] == INF) continue;
	  G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	}
      }
    }

    int mini, minCost;
    minCost = INF;
    for(int i = 0; i < 10; ++i) {
      int sum = 0;
      for(int j = 0; j < 10; ++j) {
	if(G[i][j] == INF) continue;
	sum += G[i][j];
      }
      if(sum == 0) continue;
      if(sum < minCost) {
	mini = i;
	minCost = sum;
      }
    }
    cout << mini << " " << minCost << endl;
  }
  return 0;
}