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;
#define INF 10000
#define MAXV 45

int dist[MAXV][MAXV];

int main(void){
	int n;

	while(1){
		int town=0;

		cin >> n;
		if(n==0)break;

		memset(dist,INF,sizeof(int)*MAXV*MAXV);
		for(int i=0; i<n; i++){
			int from,to,cost;
			cin >> from >> to >> cost;
			dist[from][to] = cost;
			dist[to][from] = cost;
			town = max(town,max(to,from));
		}
		town++;

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

		/*
		for(int i=0; i<town; i++){
			for(int j=0; j<town; j++){
				printf("%3d",dist[i][j]);
			}
			printf("\n");
		}
		*/
		
		int mincost=INF;
		int mintown;
		for(int i=0; i<town; i++){
			int cost=0;
			for(int j=0; j<town; j++)
				cost += dist[i][j];
			if(mincost>cost){
				mincost = cost;
				mintown = i;
			}
		}

		cout << mintown << " " << mincost << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
	int n;
	int a, b, c;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector< vector<int> > d(10, vector<int>(10, 100000));
		for (int i = 0; i < 10; i++) {
			d[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
		}
		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
				}
			}
		}
		int hyou[10] = {0};
		int p, q;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (i == j) {
					continue;
				} else if (d[i][j] >= 100000) {
					continue;
				}
				hyou[i] += d[i][j];
			}
		}
		p = 0;
		q = hyou[0];
		for (int i = 1; i < 10; i++) {
			if (hyou[i] == 0) {
				break;
			}
			if (q > hyou[i]) {
				p = i;
				q = hyou[i];
			}
		}
		cout << p << ' ' << q << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    vector<int> vv;
    int dp[10][10], ans[10] = {};
    rep(i, 10) rep(j, 10) dp[i][j] = i == j ? 0 : INF;
    rep(i, n) {
      int a, b, c;
      bool key1 = 1, key2 = 1;
      cin >> a >> b >> c;
      if (i == 0) {
        vv.push_back(a);
        vv.push_back(b);
      }
      rep(i, vv.size()) {
        if (vv[i] == a)
          key1 = 0;
        if (vv[i] == b)
          key2 = 0;
      }
      if (key1)
        vv.push_back(a);
      if (key2)
        vv.push_back(b);
      dp[a][b] = c;
      dp[b][a] = c;
    }
    rep(k, n) rep(i, n) rep(j, n) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    rep(i, vv.size()) rep(j, vv.size()) ans[i] += dp[vv[i]][vv[j]];
    rep(i, 10) if (ans[i] == 0) ans[i] = INF;
    cout << distance(ans, min_element(ans, ans + n)) << ' '
         << ans[distance(ans, min_element(ans, ans + n))] << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;
const int INF = 2 << 35;

int main()
		{

int data[11][11];
int n;
int a,s,d;
int ans,anssum;
int sum=0;

while (true)
	{
	
for(int i=0;i<10;i++)
{
for(int k = 0;k<10;k++)
{
data[i][k] = INF;
}
}

cin >> n ;

if(n == 0)return 0;

for(int i = 0; i< n;++i)
{
cin >> a >> s >> d;
data[a][s] = d;
data[s][a] = d;
}

for(int i=0;i<10;i++)
{
for(int k = 0;k<10;k++)
{
for(int m = 0;m<10;m++)
{
	if(data[i][k] > data[i][m] + data[m][k])
	{
	data[i][k] = data[i][m] + data[m][k];
	data[k][i] = data[i][m] + data[m][k];	
	}
}
}
}
anssum = INF;
for(int i=0;i<10;++i)
{
sum = 0;
for (int k=0;k < 10;++k)
{
	sum += data[i][k];
} 	
if(sum < anssum)
{
ans = i;
anssum = sum;
}
}
cout << ans <<" "<< ansnum << "\n";
	}

		}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <functional>
using namespace std;
#define INF 1e+9
int dat[50][50]={};
int a,b,c;
int main(){
	int N;
	int v;
	while(1){
		v=0;
		cin>>N;
		if(N==0){
			break;
		}
	for(int i=0;i<50;i++){
            for(int j=0;j<50;j++){
                if(i==j){
			dat[i][j]=0;
		}
                else{
			dat[i][j]=INF;
		}
            }
        }
	for(int i=0;i<N;i++){
		cin>>a>>b>>c;
		dat[a][b]=c;
		dat[b][a]=c;
		v=max(max(v,a),b);
	}
	for(int k=0;k<=v;k++){
		for(int i=0;i<=v;i++){
			for(int j=0;j<=v;j++){
				dat[i][j]=min(dat[i][j],dat[i][k]+dat[k][j]);
			}
		}
	}
	int ans=INF,ansp;
	for(int i=0;i<=v;i++){
		int cnt=0;
		for(int j=0;j<=v;j++){
			cnt+=dat[i][j];
		}
		if(ans>cnt){
			ans=cnt;
			ansp=i;
		}
	}
	cout<<ansp<<" "<<ans<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

typedef struct {
  int u, v, cost;
} Edge;

void solve(vector<Edge> es){
  VI d(10, INF);
  bool update = true;
  VI ans(10, 0);
  int lim = 10;

  REP(i, 0, lim){

    bool reach[10] = {false};
    REP(j, 0, 10){
      d[j] = INF;
    }
    d[i] = 0;
    reach[i] = true;
    update = true;

    while(update){
      update = false;
      REP(j, 0, es.size()){
        Edge e = es[j];
        if(d[e.u] != INF && d[e.v] > d[e.u] + e.cost){
          d[e.v] = d[e.u] + e.cost;
          update = true;
          reach[e.v] = true;
        }
      }
    }
    REP(j, 0, lim){
      if(reach[j]){
        ans[i] += d[j];
      } else {
        lim = j;
      }
    }
  }

  int f = INF;
  int v = -1;
  REP(i, 0, lim){
    if(f > ans[i]){
      f = ans[i];
      v = i;
    }
  }
  cout << v << " " << f << endl;

  return;
}

int main(){
  int N;

  while(1){
    cin >> N;
    if(N == 0){
      break;
    }
    vector<Edge> es(2*N);
    REP(i, 0, N){
      int a, b, c;
      cin >> a >> b >> c;
      es[i].u = a; es[i].v = b; es[i].cost = c;
      es[i+N].v = a; es[i+N].u = b; es[i+N].cost = c;
    }
    solve(es);
  }

  return 0;
}