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<algorithm>
using namespace std;
int n,a,b,c,mini,mini_no,m;
int t[10][10],u[10];
int main(){
  while(cin>>n&&n){

    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
	t[i][j]=(i==j?0:999999);
    m=-1;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      t[a][b]=t[b][a]=c;
      m=max(m,max(a,b));
    }
    m++;
    for(int k=0;k<m;k++){
      for(int i=0;i<m;i++){
	for(int j=0;j<m;j++){
	  t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
	}
      }
    }







    mini=999999;
    for(int i=0;i<m;i++){
      u[i]=0;
      for(int j=0;j<m;j++){
	u[i]+=t[i][j];
      }
    }
    for(int i=0;i<m;i++){
      if(mini>u[i]){
	mini=u[i];
	mini_no=i;
      }
    }
    cout<<mini_no<<' '<<mini<<endl;
  }
  
  return 0;
}

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

using namespace std;

const int MAX_M = 10;
const int MAX_N = 45;
const int INF = 100000000;

//input
int N;
int d[MAX_M][MAX_M];

int maxIndex;
int sum[MAX_M];

void solve(){
	for(int k = 0; k <= maxIndex; k ++){
		for(int i = 0; i <= maxIndex; i ++){
			for(int j = 0; j <= maxIndex; j ++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	int index, ans = INF;
	for(int i = 0; i <= maxIndex; i ++){
		sum[i] = 0;
		for(int j = 0; j <= maxIndex; j ++){
			sum[i] += d[i][j];
		}
		if(ans > sum[i]){
			index = i;
			ans = sum[i];
		}
	}
	printf("%d %d\n", index, ans);
}

int main(int argc, char const *argv[]){

	while(scanf("%d", &N) && N != 0){
		//init
		for(int i = 0; i < MAX_M; i ++){
			fill(d[i], d[i] + MAX_M, INF);
			d[i][i] = 0;
		}
		maxIndex = 0;
		//input
		for(int i = 0; i < N; i ++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			d[a][b] = c;
			d[b][a] = c;
			maxIndex = max(maxIndex, a);
			maxIndex = max(maxIndex, b);
		}
		solve();
	}

	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int dis[15][15];
const int INF = 0x3f3f3f3f;
int main()
{
    int n;
    while(scanf("%d",&n) != EOF&&n)
    {
        int m = 0;
        memset(dis,0x3f,sizeof(dis));
        for(int i = 0;i < 15;i++)
            dis[i][i] = 0;
        for(int i = 0;i < n;i++)
        {
            int a,b,c;
            scanf("%d %d %d",&a,&b,&c);
            dis[a][b] = dis[b][a] = min(dis[a][b],c);
            m = max(max(a,b),m);
        }
        for(int i = 0;i <= m;i++)
            for(int j = 0;j <= m;j++)
                for(int k = 0;k <= m;k++)
                    dis[j][k] = min(dis[j][k],dis[j][i]+dis[i][k]);
        int ans = INF,cas = 0;
        for(int i = 0;i <= m;i++)
        {
            int sum = 0;
            for(int j = 0;j <= m;j++)
                    sum += dis[i][j];
            if(sum < ans)
            {
                ans = sum;
                cas = i;
            }
        }
        printf("%d %d\n",cas,ans);
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int N=105,INF=0x3f3f3f3f;
int n,v,ansNum,G[N][N],ans[N],Map[N];
signed main(void){
	ios::sync_with_stdio(false);
	while(cin>>n&&n!=0){
		v=0;
		ansNum=1;
		memset(G,0x3f,sizeof(G));
		memset(Map,0,sizeof(Map));
		memset(ans,0,sizeof(ans));
		for(int i=1,x,y,w;i<=n;i++){
			cin>>x>>y>>w;
			if(Map[x]==0)
				Map[x]=++v;
			x=Map[x];
			if(Map[y]==0)
				Map[y]=++v;
			y=Map[y];
			G[x][y]=G[y][x]=min(G[x][y],w);
		}
		for(int i=1;i<=v;i++)
			G[i][i]=0;
		for(int k=1;k<=v;k++)
			for(int i=1;i<=v;i++)
				for(int j=1;j<=v;j++)
					if(G[i][j]>G[i][k]+G[k][j])
						G[i][j]=G[i][k]+G[k][j];
		for(int i=1;i<=v;i++)
			for(int j=1;j<=v;j++)
				ans[i]+=G[i][j];
		for(int i=1;i<=v;i++)
			if(ans[i]<ans[ansNum])
				ansNum=i;
		for(int i=0;i<N;i++)
			if(Map[i]==ansNum){
				ansNum=i;
				break;
			}
		cout<<ansNum<<" "<<ans[Map[ansNum]]<<endl;
	}
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

typedef struct{int to; int cost;} edge;

#define INF   (1e9+7)
#define MAX_V (10)
#define MAX_E (45)
#define MAX_C (100)

int V, E;
int D[MAX_V+1][MAX_V];

void warshall_floyd() {
  for (size_t u = 0; u < V; u++)
    for (size_t v = 0; v < V; v++)
      for (size_t w = 0; w < V; w++) D[u][v] = min(D[u][v], D[u][w] + D[w][v]);
}

void solve() {
  int ans_c, ans_d = INF;

  warshall_floyd();

  for (size_t v = 0; v < V; v++) {
    int cost = 0;
    for (size_t u = 0; u < V; u++) cost += D[u][v];
    if (cost < ans_d) {
      ans_c = v;
      ans_d = cost;
    }
  }

  printf("%d %d\n", ans_c, ans_d);
}

int main() {
  fill(D[0], D[MAX_V], INF);
//  fill((int*) D, (int*) D + MAX_V, INF);
  while (true) {
    scanf("%d", &E);
    if (E == 0) break;
    V = 0;
    for (size_t i = 0; i < E; i++) {
      int v, u, cost;
      scanf("%d %d %d", &v, &u, &cost);
      D[u][v] = cost; D[v][u] = cost;
      V = max(V, (max(u, v)));
    }
    V++;
    for (size_t v = 0; v < V; v++) D[v][v] = 0;

    solve();

    fill(D[0], D[V], INF);
  }

  return 0;
}

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

	for(int k=0;k<m;k++){
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				if(T[i][j]>T[i][k]+T[k][j]){
					T[i][j]=T[i][k]+T[k][j];
				}
			}
		}
	}

	int town;
	int ti=INF;
	for(int i=0;i<m;i++){
		int t=0;
		for(int j=0;j<m;j++){
			t+=T[i][j];
		}
			if(ti>=t){
			ti=t;
			town=i;
	}
}
	cout<<town<<" "<<ti<<endl;
	

	}

	return 0;
}