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>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int MAX_V = 12;
LL d[MAX_V][MAX_V];//d[i][j]???e={u,v}????????????(?????¨???????????¨??????INF,i==j?????¨??????0)
int v;

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 (cin >> v&&v) {
		REP(i, MAX_V)REP(j, MAX_V) {
			if (i == j)d[i][j] = 0;
			else d[i][j] = INF;
		}
		int a, b, c;
		for (int i = 0; i < v; i++) {
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
	}
		warshall_floyd();
		int cost = INF, town = -1;
		for (int i = 0; i<10; ++i) {
			LL c = 0;
			for (int j = 0; j<10; ++j) {
				if (d[i][j] == INF) {
					continue;
				}
				c += d[i][j];
			}
			if (c != 0 && cost > c) {
				cost = c;
				town = i;
			}
		}
		cout << town << ' ' << cost << endl;;
	}
}

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

using namespace std;

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

		if(n == 0){
			break;
		}

		int* start = new int[n];
		int* goal = new int[n];
		int* cost = new int[n];

		for(int i = 0; i < n; i++){
			cin >> start[i] >> goal[i] >> cost[i];
		}

		int town;

		for(int i = 0; i < n; i++){
			town = max(start[i], goal[i]);
		}

		town++;

		vector<vector<int> > dist(town, vector<int>(town, INT_MAX / 2));

		for(int i = 0; i < n; i++){
			dist[start[i]][goal[i]] = cost[i];
			dist[goal[i]][start[i]] = cost[i];
		}

		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]);
				}
			}
		}
		int* total = new int[town];
		int TOTAL = INT_MAX / 2;
		int S;

		for(int i = 0; i < town; i++){
			total[i] = 0;
		}

		for(int i = 0; i < town; i++){
			for(int j = 0; j < town; j++){
				total[i] += dist[i][j];
			}
			if(TOTAL > total[i]){
				TOTAL = min(TOTAL, total[i]);
				S = i;
			}
		}

		cout << S << " " << TOTAL << endl;
		delete [] start;
		delete [] goal;
		delete [] cost;
		delete [] total;
	}
	return 0;
}

C++: #include <iostream>
#define INFINITY (1 << 30)

#define MAX_N 10

using namespace std;

int n,road[MAX_N][MAX_N] = {},d[MAX_N][MAX_N] = {};
int main() {
  int temp1,temp2,temp3,city ,alt,mincity ;
  long long int costtime ,cost;
  while(1){
      cin >> n;
    if(n == 0) break;
    city = mincity = 0; costtime ;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2>>temp3;
      road[temp1][temp2] = temp3;
      road[temp2][temp1] = temp3;
      if(city < temp1|| city < temp2)  {city = (temp1 > temp2)?  temp1: temp2; }
    }
    //cout << city <<endl;
    city++;

    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j < city; ++j) {
        if(i != j ) d[i][j] = INFINITY;
        if (road [i][j] !=0) d[i][j] =road[i][j];
      }
    }




    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j <city ; ++j) {
        for (int k = 0; k < city; ++k) {
          if(d[k][j] != INFINITY){
            alt = d[i][k]+ d[k][j];
            if (alt < d[i][j]) d[i][j] = alt;
          }

        }

      }
    }

    for (int i = 0; i < city; ++i) {
        cost =0;
      for (int j = 0; j < city ; ++j) {
        cost += d[i][j];
        //cout << d[i][j]<<" ";
      }
      //cout<<endl;
      if(i == 0) costtime = cost;
      if (costtime > cost) {costtime = cost;mincity = i;}
    }
    cout<< mincity << " "<<costtime<<endl;

  }


  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

const int INF = 100000000;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		
		int T[10][10];

		rep(i,10){
			rep(j,10){
				if(i == j){
					T[i][j] = 0;
				}else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;

		rep(i,n){
			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;
			}
		}
		
		rep(k,m){
			rep(i,m){
				rep(j,m){
					if(T[i][j] > T[i][k] + T[k][j]){
						T[i][j] = T[i][k] + T[k][j];
					}
				}
			}
		}

		int city = 0;
		int mn = INF;

		rep(i,m){
			int sum = 0;
			rep(j,m){
				sum += T[i][j];
			}
			if(mn > sum){
				mn = sum;
				city = i;
			}
		}

		cout << city << " " << mn << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
	int n;
	while (cin >> n, n)
	{
		int cost[15][15];
		REP(i, 15)REP(j, 15) cost[i][j] = (i == j ? 0 : INF);
		int a, b, c;
		int city = 0;
		REP(i, n)
		{
			cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
			city = max({ city, a, b });
		}
		city++;
		REP(k, city)REP(i, city)REP(j, city) cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
		int sum[15] = {};
		REP(i, city)
		{
			REP(j, city) sum[i] += cost[i][j];
		}
		int ans; int anssum = INF;
		REP(i, city)
		{
			if (anssum > sum[i])
			{
				ans = i;
				anssum = sum[i];
			}
		}
		cout << ans << " " << anssum << endl;
	}
	return 0;
}