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;

enum { maxn = 20, INF = 10000000000000LL };

typedef long long LL;
LL G[maxn][maxn];
int vis[maxn];
LL d[maxn][maxn];
int inq[maxn];
int m;

void spfa(int src)
{
    memset(inq, 0, sizeof inq);
    for(int i = 0; i < maxn; i++) d[src][i] = INF;
    d[src][src] = 0LL;
    queue< int > q;
    while(!q.empty()) q.pop();
    q.push(src);
    inq[src] = 1;
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(int i = 0; i < maxn; i++)
        {
            if(G[u][i])
            {
                if(d[src][u] + G[u][i] < d[src][i])
                {
                    d[src][i] = d[src][u] + G[u][i];
                    if(!inq[i])
                    {
                        inq[i] = 1;
                        q.push(i);
                    }
                }
            }
        }
        inq[u] = 0;
    }
}

int main()
{
    while(~scanf("%d", &m), m)
    {
        memset(vis, 0, sizeof(vis));
        memset(G, 0, sizeof(G));
        memset(d, 0, sizeof(d));
        for(int i = 0; i < m; i++)
        {
            int a, b;
            LL c;
            scanf("%d%d%lld", &a, &b, &c);
            G[a][b] = G[b][a] = c;
            vis[a] = vis[b] = 1;
        }
        for(int i = 0; i < maxn; i++)
            if(vis[i])
                spfa(i);
        LL ans = INF;
        int pt = -1;
        for(int i = 0; i < maxn; i++)
        {
            LL sum = 0;
            if(vis[i])
            {
                for(int j = 0; j < maxn; j++)
                {
                    if(vis[j])
                    {
                        sum += d[i][j];
                    }
                }
                if(sum <= ans)
                {
                    ans = sum;
                    pt = i;
                }
            }
        }
        printf("%d %lld\n", pt, ans);
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
#define INF 1000000
#define N 9
using namespace std;

int d[N][N];
int ans[N];
//初期化
void init(){
  for(int i=0;i<N;i++){
      ans[i]=0;
    for(int j=0;j<N;j++){
      if(i==j) d[i][i]=0;
      else d[i][j]=INF;
    }
  }
}
void solve(int n){
  init();
  int a,b,t;
  //値代入
  for(int i=0;i<n;i++){
    cin>>a>>b>>t;
    d[a][b]=d[b][a]=t; //無向辺
  }
  //ワーシャルフロイド
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      for(int k=0;k<N;k++){
        d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(d[i][j]==INF) continue;
      ans[i]+=d[i][j]; //距離の累積和
    }
  }
  int answer=INF,town;
  for(int i=0;i<N;i++){
    if(ans[i]!=0&&answer>ans[i]){
      answer=ans[i]; town=i;
    }
  }
  cout<<town<<" "<<answer<<"\n";

}
int main(){
  int n;
  cin>>n;
  while(n!=0){solve(n);cin>>n;}

}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef pair<int, int> P;
typedef long long int ll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;

int main(){
	while(cin >> n){
		if(n == 0) break;
		int ans[10];
		int t = 0, m = 0;
		int d[10][10];
		fill((int*)d,(int*)(d+10), INF);
		clr(ans,0);
		rep(i,10) d[i][i] = 0;
		rep(i,n){
			int temp1, temp2, temp3; scanf("%d%d%d", &temp1, &temp2, &temp3);
			d[temp1][temp2] = temp3; d[temp2][temp1] = temp3;
			if(m < temp1) m = temp1;
			if(m < temp2) m = temp2;
		}
		m++;
		rep(k,m) rep(i,m) rep(j,m) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
		rep(i,m) rep(j,m) ans[i] += d[i][j];
		for(int i = 1; i < m; i++){
			if(ans[t] > ans[i]) t = i;
		}
		cout << t << " " << ans[t] << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX 50
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum;
bool visit[MAX];

int dijkstra(int s,int g){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = 0 ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = 0 ; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            if(t < v[i] && r[mn][i] != INF) v[i] = t;
        }
    }
    
    return v[g];
}


int main(){
    int a,b,c;
    
    for(int i = 0 ; i < MAX ; i++)
        for(int j = 0 ; j < MAX ; j++)
            r[i][j] = INF;

    while(cin >> n,n){
        maxnum = 0;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = c;
            r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
        }

        int mx = INF, num = 0;
        for(int i = 0 ; i <= maxnum ; i++){
            int sum = 0;
            for(int j = 0 ; j <= maxnum ; j++){
                if(i == j) continue;
                if(dijkstra(i,j)!=INF) sum += dijkstra(i,j);
            }
            if(sum < mx){
                mx = sum;
                num = i;
            }
        }
        cout << num << ' ' << mx << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <algorithm>
int cost[10][10];
#define INF 10e6

using namespace std;

int main(void){
	int n,a,b,d;
	int cmax;
	int t,rmin,tmin;
	while(cin >> n,n){
		tmin=INF;
		cmax=0;
		for(int i=0;i<10;i++)
				for(int j=0;j<10;j++)
					cost[i][j]=INF;
					
		for(int i=0;i<10;i++)
			cost[i][i]=0;
			
		for(int i=0;i<n;i++){
			cin >> a >> b >> d;
			if(cmax<a)
				cmax=a;
			if(cmax<b)
				cmax=b;
			cost[a][b]=cost[b][a]=d;
		}
		for(int i=0;i<=cmax;i++)
			for(int j=0;j<=cmax;j++)
				for(int k=0;k<=cmax;k++)
					if(cost[i][j]>cost[i][k]+cost[k][j])
						cost[i][j]=cost[i][k]+cost[k][j];
				
		for(int i=0;i<=cmax;i++){
			for(int j=0;j<=cmax;j++)
				cout << ' '<<cost[i][j];
			cout << endl;
		}
		
		for(int i=0;i<=cmax;i++){
			t=0;
			for(int j=0;j<=cmax;j++)
					t+=cost[i][j];
			if(t<tmin)
				tmin=t,rmin=i;
		}
		cout << cmax << endl;
		cout << rmin << ' ' << tmin << endl;
	}
	return 0;
}