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>

#define TOWN_MAX 11
#define ROAD_MAX 46
#define INF 1000000000

int solve(int);

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

    while (true) {
        std::cin >> n;
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

int solve(int road_num) {
    int distances[TOWN_MAX][TOWN_MAX];

    for (int i = 0; i < TOWN_MAX; i++)
        for (int j = 0; j < TOWN_MAX; j++)
            distances[i][j] = INF;

    for (int i = 0; i < road_num; i++) {
        int src, dest, cost;
        std::cin >> src >> dest >> cost;
        distances[src][src]    = 0;
        distances[dest][dest]  = 0;
        distances[src][dest]   = cost;
        distances[dest][src]   = cost;
    }

    for (int infix_road = 0; infix_road < road_num; infix_road++) {
        for (int begin_town = 0; begin_town < TOWN_MAX; begin_town++) {
            for (int end_town = 0; end_town < TOWN_MAX; end_town++) {
                distances[begin_town][end_town] = std::min(distances[begin_town][end_town],
                        distances[begin_town][infix_road] + distances[infix_road][end_town]);
            }
        }
    }

    int min_cost = INF;
    int min_cost_index = 0;
    for (int i = 0; i < TOWN_MAX; i++) {
        if (distances[i][i] == INF) continue;

        int sum_cost = 0;
        for (int j = 0; j < TOWN_MAX; j++) {
             if (distances[i][j] != INF) sum_cost += distances[i][j];
        }

        if (sum_cost < min_cost && sum_cost != 0) {
            min_cost       = sum_cost;
            min_cost_index = i;
        }
    }

    std::cout << min_cost_index << " " << min_cost << std::endl;

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include<utility>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
using namespace std;

template<class T>inline string toString(T x){
        ostringstream sout; sout<<x; return sout.str();
}
const ll MOD=1e9+7;
const int inf=(ll)1e9;
const double PI=acos(-1.0);

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout<<fixed;
	int n;
	while(cin>>n,n){
		int dp[11][11];
		int m=0;
		for(int i=0;i<11;i++){
			for(int j=0;j<11;j++){
				dp[i][j]=inf;
			}
		}
		for(int i=0;i<11;i++){
			dp[i][i]=0;
		}
		for(int i=0;i<n;i++){
			int a,b,c;cin>>a>>b>>c;
			dp[a][b]=c;
			dp[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++){
					dp[i][j]=min(dp[i][k]+dp[k][j],dp[i][j]);
				}
			}
		}
		int ans=inf;
		int ansi=0;
		for(int i=0;i<m;i++){
			int sum=0;
			for(int j=0;j<m;j++){
				if(i==j)continue;
				sum+=dp[i][j];
			}
			if(ans>sum){
				ans=sum;
				ansi=i;
			}
		}
		cout<<ansi<<" "<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int INF=1<<20;
const int maxn=50;
int d[maxn][maxn];
int r;
int main()
{
    while(cin>>r)
	{
		if(r==0) break;
		for(int i=0;i<=11;i++)
			for(int j=0;j<=11;j++){
				if(i!=j)
					d[i][j]=INF;
				else
					d[i][j]=0;
			}
		int n;
		n=0;
		for(int i=0;i<r;i++)
		{
			int a,b,num;
			scanf("%d%d%d",&a,&b,&num);
			int t=max(a,b);
			n=max(t,n);
			d[a][b]=num;
			d[b][a]=num;
		}
		for(int k=0;k<=n;k++)
			for(int i=0;i<=n;i++)
				for(int j=0;j<=n;j++)
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++)
					cout<<d[i][j]<<" ";
					cout<<endl;
		}
		int minx=INF;
		int k;
		for(int i=0;i<=n;i++){
			int res=0;
			for(int j=0;j<=n;j++)
				res+=d[i][j];
			if(res<minx){
				minx=res;
				k=i;
			}
		}
		cout<<k<<" "<<minx<<endl;


	}
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;


	while (cin >> n) {
		int min_ = 1000000000;
		int min_num = 1;
		int cost[100][100];
		int max_ = 0;
		int from, to, time;

		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				cost[i][j] = 100000000;
			}
		}
		for (int i = 0; i < 100; i++) {
			cost[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> from >> to >> time;
			cost[from][to] = time;
			cost[to][from] = time;
			max_ = max(max(from, to), max_);
		}
		max_++;
		for (int i = 0; i < max_; i++) {
			for (int j = 0; j < max_; j++) {
				for (int k = 0; k < max_; k++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		for (int i = 0; i < max_; i++) {
			int total = 0;
			for (int j = 0; j < max_; j++) {
				total += cost[i][j];
			}
			if (total < min_) {
				min_ = total;
				min_num = i;
			}
		}
		cout << min_num << " " << min_ << endl;
  }
	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 ,costtime= INFINITY ,cost ;

  while(1){
      cin >> n;
    if(n == 0) break;
    city = mincity = 0;
    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 (costtime > cost) {costtime = cost;mincity = i;}
    }
    cout<< mincity << " "<<costtime<<endl;
    costtime = INFINITY;
  }


  return 0;
}