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 <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;//道の数
int cost[10][10];//町iからjへのコスト
const int INF =10000000;
int a1,b1,c1;
int ans;
int minV;
int maxV;
int main()
{
  while(cin >>n,n){
  ans = INF;
  maxV =0;
  for(int i = 0;i <10;i++){
    for(int j = 0;j <10;j++){
      if(i!=j)
	cost[i][j] =INF;
      else
	cost[i][j] = 0;
    }
  }
  for(int i = 0;i < n;i++){
    cin >>a1>>b1>>c1;
    cost[a1][b1] = c1;
    cost[b1][a1] = c1;
    maxV =max(maxV,max(a1,b1));
  }
  for(int i = 0;i <=maxV;i++){
    for(int j = 0;j <=maxV;j++){
      for(int k = 0;k <=maxV;k++){
	cost[j][k] =min(cost[j][k],cost[j][i]+cost[i][k]);
      }
    }
  }
  for(int i = 0;i <=maxV;i++){
    int anstemp =0;
    for(int j = 0;j <=maxV;j++){
      anstemp +=cost[i][j];
    }
    if(ans >anstemp){
      ans = anstemp;
      minV = i;
    }
  }
  cout <<minV<<" "<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>

#define INF 10000000

using namespace std;

int data[20][20]={INF};

int main(){
	int n;
	while(cin>>n && n){
		for(int i=0;i<20;i++)data[i][i]=0;
		int v=0;
		for(int i=0;i<n;i++){
			int a,b,x;
			cin>>a>>b>>x;
			v=max(v,max(a,b));
			data[a][b]=data[b][a]=x;
		}
		
		for(int k=0;k<v;k++){
			for(int i=0;i<v;i++){
				for(int j=0;j<v;j++){
				
				if(data[i][k]!=INF && data[k][j]!=INF)data[i][j]=min(data[i][j],data[i][k]+data[k][j]);
				}
			}
		}
		int sum[v];
		for(int i=0;i<v;i++)
			for(int j=0;j<v;j++)sum[i]+=data[i][j];
		int ans=INF;
		int tmp=-1;
		for(int i=0;i<v;i++){
			if(ans>sum[i] && sum[i]>0){
				ans=sum[i];
				tmp=i;
			}
		}
		cout<<tmp<<" "<<sum[tmp]<<endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

const int INF = 1<<30;
const int maxn = 15;
int d[maxn][maxn];
int E,V;

long long sum;

void warshall_floyd(){
	for(int k=0; k<V; k++)
		for(int i=0; i<V; i++)
			for(int j=0; j<V; j++)
				d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
}

int main(){
	while(scanf("%d",&E) && E){
		memset(d, 0x3f, maxn * maxn * sizeof(int));

		for(int i=0; i<maxn; i++) d[i][i] = 0;

		V = 0;
		for(int i=0; i<E; i++){
			int u,v,w;
			scanf("%d%d%d",&u,&v,&w);
			d[u][v] = d[v][u] = w;
			V = max(V,max(v,u)+1);
		}

		warshall_floyd();

		int ans = INF, pos;
		for(int i=0; i<V; i++){
			sum = 0;
			for(int j=0; j<V; j++)
				sum += d[i][j];
			if(ans > sum){
				ans = sum;
				pos = i;
			}
		}

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

C++: #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int V;
const int maxv=17;
const int INF=2e9+7;
int cost[maxv][maxv];
int d[maxv];
bool used[maxv];
void bjs(int s)
{

    fill(d,d+V,INF);
    d[s]=0;
    memset(used,0,sizeof(used));
    while(true)
    {
        int v=-1;
        for(int i=0;i<V;i++)
        {
            if(!used[i]&&(v==-1||d[i]<d[v]))
               v=i;
        }
        if(v==-1) break;
        used[v]=1;
        for(int i=0;i<V;i++)
            d[i]=min(d[i],d[v]+cost[v][i]);
    }
    return ;
}
int main()
{
   int n;
   while(cin>>n&&n!=0)
   {
     V=0;
     for(int i=0;i<maxv;i++)
        fill(cost[i],cost[i]+maxv,INF);
     for(int i=0;i<n;i++)
     {
         int x,y,z;
         cin>>x>>y>>z;
         cost[x][y]=z;
         cost[y][x]=z;
         V=max(V,x);
         V=max(V,y);
     }
     V++;
     int ans[V];
     memset(ans,0,sizeof(ans));
     for(int i=0;i<V;i++)
     {
         bjs(i);
         for(int j=0;j<V;j++)
            ans[i]+=d[j];
     }
     int ans0=0;
     for(int i=0;i<V;i++)
     {
         if(ans[i]<ans[ans0])
            ans0=i;
     }
     cout<<ans0<<" "<<ans[ans0]<<endl;
   }

}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

map<int, bool> mp;
int cost[20][20];
int main(){
	int n, a, b, c;
	int cnt;
	while(cin >> n && n){
		mp.clear();
		cnt = 0;
		fill(&cost[0][0], &cost[19][19] + 1, INF);
		rep(i, n){
			cin >> a >> b >> c;
			if(!mp[a]){
				mp[a] = true;
				cnt++;
				cost[a][a] = 0;
			}
			if(!mp[b]){
				mp[b] = true;
				cnt++;
				cost[b][b] = 0;
			}
			cost[a][b] = cost[b][a] = min(cost[a][b], c);
		}
		rep(k, cnt)rep(i, cnt)rep(j, cnt) cost[i][j] = min(cost[i][k]+cost[k][j], cost[i][j]);
		int id = 0;
		int best = INF;
		rep(i, cnt){
			int c = 0;
			rep(j, cnt)c+=cost[i][j];
			if(c < best){
				best = c;
				id = i;
			}
		}
		cout << id << " " << best << endl;
	}
	return 0;
}