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<vector>
#include<queue>
#include<functional>
#define INF 2e6

typedef std::pair<int, int> P;

# define MAX_E 45
# define MAX_V 10

int V, E;

struct edge{
	int to, cost;
	edge() = default;
	edge(const edge &)= default;
	edge& operator = (const edge&) = default;
	edge(int _t, int _c) : to(_t), cost(_c) {}
};

std::vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
	std::priority_queue<P, std::vector<P>, std::greater<P>> Q;
	std::fill(d, d + V+1, INF);
	d[s] = 0;
	Q.push(P(0, s));
	while (!Q.empty()){
		P p = Q.top(); Q.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;
				Q.push(P(d[e.to], e.to));
			}
		}
	}
}

P solve(){
	int min = INF, minv;
	for (int i = 0; i <= V; ++i){
		int sum = 0;
		dijkstra(i);
		for (int j = 0; j <= V; ++j){
			sum += d[j];
		}
		if (min > sum)min = sum, minv = i;
	}
	return P(minv, min);
}

int main(){
	while (1){
		std::cin >> E;
		if (E == 0)
			break;
		for (int i = 0; i <= V; i++)G[i].clear();
		V = 0;
		int f, t, c;
		for (int i = 0; i < E; ++i){
			std::cin >> f >> t >> c;
			G[f].push_back(edge(t, c));
			G[t].push_back(edge(f, c));
			if (V < t)
				V = t;
		}
		std::cout << solve().first<<' '<< solve().second << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <utility>
using namespace std;

typedef long long ll;

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

int m;
int d[22][22];
void init(){
  for(int i=0;i<22;i++){
    for(int j=0;j<22;j++){
      if(i==j)d[i][j]=0;
      else d[i][j]=100000000;
    }
  }
}
void solve(){
  for(int k=0;k<m;k++){
    for(int i=0;i<m;i++){
      for(int j=0;j<m;j++){
	d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  int ans=INT_MAX,p=0;
  for(int i=0;i<m;i++){
    int sum=0;
    for(int j=0;j<m;j++)sum+=d[i][j];
    if(ans>sum){
      ans=sum;p=i;
    }
  }
  cout<<p<<" "<<ans<<endl;
}

int main(void){
  int n;
  while(cin>>n,n){
    m=0;
    init();
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b>>c;
      d[a][b]=d[b][a]=c;
      m=max(m,max(a+1,b+1));      
    }
    solve();
  }
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#define inf 1000000000
using namespace std;
unsigned long long d[10][10];
int v;

int main()
{
	int n;
	while(cin>>n,n)
	{
		bool used[10];
		memset(used,0,sizeof(used));
		memset(d,0,sizeof(d));
		for(int i=0;i<n;i++)
		{
			int s,t,c;
			cin>>s>>t>>c;
			used[s]=used[t]=true;
			d[s][t]=d[t][s]=c;
		}
		v=0;
		for(int i=0;i<10;i++)
		{
			if(used[i]) v=i;
			for(int j=0;j<10;j++)
			{
				if(d[i][j]==0&&i!=j) d[i][j]=inf;
			}
		}

		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 ans;
		unsigned long long mn=inf;
		for(int i=0;i<=v;i++)
		{
			int sum=0;
			for(int j=0;j<=v;j++)
			{
				sum+=d[i][j];
			}
			if(sum<mn)
			{
				ans=i;mn=sum;
			}
		}
		cout<<ans<<" "<<mn<<endl;

	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

const int INF=1<<21;

int main()
{
	int n;
	while(cin>>n,n)
	{
		int m[10][10]={};
		for(int i=0;i<10;i++)for(int j=0;j<10;j++)if(i!=j)m[i][j]=INF;
		int a,b,w,maxn=0;
		for(int i=0;i<n;i++)
		{
			cin>>a>>b>>w;
			m[a][b]=m[b][a]=w;
			maxn=max(maxn,max(a,b));
		}
		maxn++;
		for(int k=0;k<maxn;k++)
			for(int i=0;i<maxn;i++)
				for(int j=0;j<maxn;j++)
					m[i][j]=min(m[i][j],m[i][k]+m[k][j]);
		
		int d[10];
		for(int i=0;i<maxn;i++)d[i]=0;
		for(int i=0;i<maxn;i++)
		{
			for(int j=0;j<maxn;j++)
			{
				d[i]+=m[i][j];
			}
		}
		int mini=0;
		for(int i=1;i<maxn;i++)if(d[i-1]>d[i])mini=i;
		
		cout<<mini<<" "<<d[mini]<<endl;
	}
	return 0;
}

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

const int MAX_N=10;
const int INF=0x3f3f3f3f;
int dist[MAX_N][MAX_N];

int main(){
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    int N;
    while((cin>>N)&&N>0){
        memset(dist, 0x3f, sizeof(dist));
        int u,v,w;
        for(int i=0; i<MAX_N; i++) dist[i][i]=0;
        int max_n=0;
        for(int i=0; i<N; i++){
            scanf("%d %d %d", &u, &v, &w);
            dist[u][v]=dist[v][u]=w;
            max_n=max(max_n, max(u,v)+1);
        }
        for(int i=0; i<max_n; i++){
            for(int j=0; j<max_n; j++){
                for(int k=0; k<max_n; k++)
                    dist[j][k]=min(dist[j][k], dist[j][i]+dist[i][k]);
            }
        }
        int res=INF;
        int min_ele=0;
        for(int i=0; i<max_n; i++){
            int tmp=0;
            for(int j=0; j<max_n; j++)
                tmp+=dist[i][j];
            if(tmp<res){
				res=tmp;
				min_ele=i;
			}
        }
        cout<<min_ele<<" "<<res<<endl;
    }
    #ifndef ONLINE_JUDGE
    fclose(stdin);
    #endif
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<string.h>

using namespace std;

#define INF 1000000

int E,V,r[12][3],d[12][12];

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]);
}

void init(){
  for(int i=0;i<12;i++)
    for(int j=0;j<12;j++)
      d[i][j]=INF;

  memset(r,0,sizeof(r));
  V=0;
  E=0;
}

void solve(){
  warshall_floyd();

  int res[12];
  fill(res,res+12,0);


  for(int i=0;i<V;i++){
    for(int j=0;j<V;j++){
      if(d[i][j]!=INF)
        res[i]+=d[i][j];
    }
  }


  int res1=INF;
  int res2=INF;

  for(int i=0;i<V;i++){
    if(res[i]<res2){
      res1=i;
      res2=res[i];
    }
  }

  printf("%d %d\n",res1,res2);
}

int main(){
  while(true){
    init();
    scanf("%d",&E);
    if(E==0) break;
    for(int i=0;i<E;i++){
      scanf("%d%d%d",&r[i][0],&r[i][1],&r[i][2]);
    }

    for(int i=0;i<10;i++){
      V=max(V,r[i][1]);
    }
    V++;


    for(int i=0;i<E;i++){
      d[r[i][0]][r[i][1]]=r[i][2];
      d[r[i][1]][r[i][0]]=r[i][2];
    }

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

    solve();
  }
  return 0;
}