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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

template<typename T>T&get(){T a;cin >> a;return a;}
template<typename T>T&rev(T&a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>a){sort(all(a));return a;}

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

const int inf = 1e9;
const ll linf = 3e18;

int d[10][10];
int N;
bool found[10];

void wf()
{
    rep(k, 10) rep(i, 10) rep(j, 10) {
        chmin(d[i][j], d[i][k] + d[j][k]);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (cin >> N, N) {
        memset(found, 0, sizeof(found));
        fill(d[0], d[10], inf);
        rep(i, 10) d[i][i] = 0;

        rep(i, N) {
            int a, b, c; cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
            found[a] = found[b] = true;
        }

        wf();

        int mi = inf, a;

        rep(i, 10) if (found[i]) {
            int sum = 0;
            rep(j, 10) if (found[j]) {
                sum += d[i][j];
            }
            if (mi > sum) {
                mi = sum;
                a = i;
            }
        }

        cout << a << " " << mi << endl;
    }
}

C++: #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int x[11][11];
int main()
{
    int n;
    while(~scanf("%d",&n)&&n)
    {
        int a,b,c;
        memset(x,0x3f,sizeof(x));
        for(int i=0;i<=n;i++)
            for(int j=0;j<=n;j++)
            if(i==j)
            x[i][j]=0;
            int Max=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            if(x[a][b]>c)
            x[a][b]=x[b][a]=c;
            Max=max(Max,max(a,b));
        }
        for(int i=0;i<=Max;i++)
            for(int j=0;j<=Max;j++)
            for(int k=0;k<=Max;k++)
            if(x[i][j]>x[i][k]+x[k][j])
            x[i][j]=x[i][k]+x[k][j];
//            for(int i=0;i<=Max;i++)
//            {
//                for(int j=0;j<=Max;j++)
//                    printf("%d ",x[i][j]);
//                printf("\n");
//            }
            int Min=0x3f3f3f3f,flag=0,sum=0;
        for(int i=0;i<=Max;i++)
        {
            for(int j=0;j<=Max;j++)
            {
                if(x[i][j]!=0x3f3f3f3f)
                sum+=x[i][j];
              //  printf("sum[%d][%d]=%d ",i,j,sum);
            }//printf("\n");
                if(sum&&sum<Min)
                {
                    Min=sum;
                    flag=i;

                }
                sum=0;
        }
        printf("%d %d\n",flag,Min);
    }
}

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 i =0;i<m;i++){
      for(int j =0;j<m;j++){
        for(int k = 0;k<m;k++){
          if(T[j][k]>T[j][i]+T[i][k]){
            T[j][k]=T[j][i]+T[i][k];
          }
        }
      }
    }
    int anstown,anstime=INF;
    for(int i =0;i<m;i++){
      int sumtime=0;
      for(int j = 0;j<m;j++){
        sumtime+=Time[i][j];
      }
      if(anstime>sumtime){
        anstown = i;
        anstime = sumtime;
      }
    }
    cout << anstonw <<" "<<anstime<<endl;
  }
  return 0;
}

C++: /*
ツδ渉ーツシツδδδ仰フツδ債イツドツづ?全ツ点ツ甘板催?短ツ仰猟猟」ツづーツ仰?づ淞づ?つィツつォツづ慊つキツ。
ツつサツつオツつスツづァツ、ツ篠ゥツ閉ェツづ個陳ャツづーツづ?つアツづ可つキツづゥツつゥツづーツ考ツつヲツづ?、ツ堕シツづ個陳ャツづ可行ツつュツつスツづ淞づ個コツスツトツづーツ仰?づ淞づ慊つキツ。
ツ?ィツ禿アツ重ツδ仰ーツプ
ツ暗ェツ氾板渉ャツつウツつ「ツコツスツトツづ可づ按づ?つスツ陳ャツづーツ出ツ療債つオツづ慊つオツづ・ツつ、ツ。
 */
#include <iostream>
using namespace std;

#define INF 999999999

int n, m; //ツ陳ャツづ個青? ツ督ケツづ個青?
int t[12][12];

void init(){
  for(int i = 0; i < 12; i++){
    for(int j = 0; j < 12; j++){
      t[i][j] = INF;
    }
  }
}

void wf(){
  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(i == j) continue;
        t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
      }
    }
  }
}

int main(){
  while(cin >> m, m){
    n = 0;
    init();

    for(int i = 0; i < m; i++){
      int a, b, cost;
      cin >> a >> b >> cost;
      n = max(n, max(a + 1, b + 1));
      t[a][b] = t[b][a] = cost;
    }

    wf();

    int ans = 0;
    int ansCost = INF;

    for(int i = 0; i < n; i++){
      int cost = 0;

      for(int j = 0; j < n; j++){
        if(i == j) continue;
        cost += t[i][j];
      }

      if(ansCost > cost){
        ans = i;
        ansCost = cost;
      }
    }

    cout << ans << " " << ansCost << endl;
  }
}