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<stdio.h>
#include<cmath>
#define INF 9999999
using namespace std;
int n,t[10][10],a,b,c,d,flg[10],sum,mini,miniNo;
int main(){
	while(1){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				t[i][j]=INF*(j!=i);
			}
			flg[i]=0;
		}
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			t[a][b]=t[b][a]=c;
			flg[a]=flg[b]=1;
		}
		for(int k=0;k<10;k++){
			for(int i=0;i<10;i++){
				for(int j=0;j<10;j++){
					t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
				}
			}
		}
		mini=INF;
		for(int i=0;i<10;i++){
			if(flg[i]){
				sum=0;
				for(int j=0;j<10;j++){
					if(t[i][j]!=INF){
						sum+=t[i][j];
					}
				}
				if(mini>sum){
					mini=sum;
					miniNo=i;
				}
			}
		}
		cout<<miniNo<<" "<<mini<<endl;

	}
			return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int dp[15][15];

int main(){
    int n;
    while(cin >> n, n){
        rep(i,15){
            rep(j,15){
                dp[i][j] = 2 << 24;
            }
            dp[i][i] = 0;
        }
        int ma = 0;
        rep(i,n){
            int a, b, c;
            cin >> a >> b >> c;
            dp[a][b] = c;
            dp[b][a] = c;
            if(ma < a)
                ma = a;
            if(ma < b)
                ma = b;
        }
        rep(k,n + 1){
            rep(i,n + 1){
                rep(j,n + 1){
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                }
            }
        }
        int ans, time, mintime = 2 << 24;
        rep(i,ma + 1){
            time = 0;
            rep(j,ma + 1){
                time+= dp[i][j];
            }
            if(mintime > time){
                mintime = time;
                ans = i;
            }
        }
        cout << ans << ' ' << mintime << 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;

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

int V, E;
int D[MAX_V][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() {
  while (cin >> E) {
    if (E == 0) break;

    for (size_t u = 0; u < MAX_V; u++)
      for (size_t v = 0; v < MAX_V; v++) D[u][v] = (u == v)? 0: INF;

    V = 0;
    for (size_t i = 0; i < E; i++) {
      int v, u, cost;
      cin >> v >> u >> cost;
      D[u][v] = cost; D[v][u] = cost;
      V = max(V, (max(u, v)));
    }
    V++;

    solve();
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
const int INF=(1<<21);
int main(){

  int n;
  int town[11][11];
  int a,b,c;
  int total=0;
  int min_total=INF;
  int min_town=0;
  int s[11];

  while(cin>> n,n){
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
	town[i][j]=(i==j)?0:INF;
      }
    }
 
    int v=0;
    for(int i=0;i<n;i++){
    cin>> a>> b>> c;
    town[a][b]=c;
    town[b][a]=c;
    v=max(max(v,a),b);
  }

    for(int i=0;i<=v;i++){
      for(int j=0;j<=v;j++){
	for(int k=0;k<=v;k++){
	  town[j][k]=min(town[j][k],town[j][i]+town[i][k]);
	}
      }
    }

    for(int i=0;i<=v;i++){
      for(int j=0;j<=v;j++){
	total+=town[i][j];
      }
      s[i]=total;
      min_total=min(min_total,total);
      total=0;
    }
    for(int i=0;i<=v;i++){
      if(s[i]==min_total){
	cout<< i<< ' ';
	cout<< min_total<< endl;
	break;
      }
    }
  }
}

C++: #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define MAX 0x3f3f3f3f
using namespace std;

int mpa[12][12];

int n,flag;

void floyd()
{
    for(int k=0; k<=10; k++)
    {
        for(int i=0; i<=10; i++)
        {
            for(int j=0; j<=10; j++)
            {
                if(mpa[i][j]>mpa[i][k]+mpa[k][j])
                    mpa[i][j]=mpa[i][k]+mpa[k][j];
            }
        }
    }
}


int main()
{
    while(cin>>n,n!=0)
    {
        flag=0;
        memset(mpa,MAX,sizeof(mpa));
        for(int i = 1; i <= n; i++)
        {
            int a, b, c;
            cin>>a>>b>>c;

            if(mpa[a][b]>c)
            {
                mpa[a][b]=c;
                mpa[b][a]=c;
            }
        }

        floyd();

        for(int i=0; i<=10; i++)
            mpa[i][11]=0;

        int  mmin=MAX,a1,a2,flag=0;
        for(int i=0; i<=10; i++)
        {
            for(int j=0 ; j<=10; j++)
            {
                if(i == j)
                    mpa[i][j]=0;
                if(mpa[i][j]!=MAX)
                    mpa[i][11]+=mpa[i][j];
            }
            if(mmin>mpa[i][11] && mpa[i][11]!=0)
            {
                mmin=mpa[i][11];
                a1=i;
            }
        }

        cout<<a1<<" "<<mpa[a1][11]<<endl;

    }
    return 0;
}