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++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
vector<vector<int>>d = vector<vector<int>>(10, vector<int>(10, INF));;
int n;
signed main() {
	while (cin >> n, n) {
		d = vector<vector<int>>(10, vector<int>(10, INF));;
		rep(i, 0, 10)d[i][i] = 0;
		int x(0), y(0);
		rep(i, 0, n) {
			int a, b, c; cin >> a >> b >> c;
			x = max(x, a); y = max(y, b);
			d[a][b] = c; d[b][a] = c;
		}
		rep(k, 0, 10) {
			rep(i, 0, 10) {
				rep(j, 0, 10) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		int z = max(x, y);
		int sum(INF), ind(0);
		rep(i, 0, z + 1) {
			int v = accumulate(d[i].begin(), d[i].begin() + z + 1, 0);
			if (sum > v) {
				sum = v;
				ind = i;
			}
		}
		cout << ind << " " << sum << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    int n;
    while(cin >> n, n){
        int dis[10][10];
        fill(dis[0], dis[10], IINF);
        rep(i, 10){
            dis[i][i] = 0;
        }
        int maxi = 0;
        rep(i, n){
            int a, b, c;
            cin >> a >> b >> c;
            dis[a][b] = c;
            dis[b][a] = c;
            maxi = max({maxi, a, b});
        }
        ++maxi;
        for(int k = 0 ; k < maxi ; ++k){
            for(int i = 0 ; i < maxi ; ++i){
                for(int j = 0 ; j < maxi ; ++j){
                    dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
                }
            }
        }
        int tmp = IINF, ans1, ans2;
        rep(i, maxi){
            int cnt = 0;
            rep(j, maxi){
                cnt += dis[i][j];
            }
            if(cnt < tmp){
                tmp = cnt;
                ans1 = i;
                ans2 = cnt;
            }
        }
        printf("%d %d\n", ans1, ans2);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;

const int INF = 1000000;

int main(){

    int n;
    while(1){
      cin >> n;
      if(n==0){
        break;
      }
      int table[10][10];

      bool realtowntable[10];

      for(int i=0;i<10;i++){
        realtowntable[i] = false;
      }

      for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
          if(i==j){
            table[i][j] = 0;
          }
          else{
            table[i][j] = INF;
          }
        }
      }
      int a,b,c;
      for(int i=0;i<n;i++){
        cin >> a >> b >> c;
        if(!realtowntable[a]){
          realtowntable[a] = true;
        }
        if(!realtowntable[b]){
          realtowntable[b] = true;
        }
        table[a][b] = table[b][a] = c;
      }

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

      /*for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
          for(int j=0;j<10;j++){
            if(table[j][i] > table[j][k] + table[k][i]){
              table[j][i] = table[j][k] + table[k][i];
            }
          }
        }
      }*/

      int anstown = 0;
      long long int ans=0,tmp=0;
      ans = INF * 12;
      for(int i=0;i<10;i++){
        if(realtowntable[i]){
          tmp = 0;
          for(int j=0;j<10;j++){
            if(realtowntable[j]){
              tmp += table[i][j];
            }
          }
          if(ans > tmp){
            ans = tmp;
            anstown = i;
          }
        }
      }
      cout << anstown << ' ' << ans << endl;

    }


    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define INF 1000000
int mat[10][10];
int tn;

int main(){
	int n, a, b, c;
	while (cin >> n && n != 0) {
		tn = 0;
		for (int i = 0; i < 10; i++) {
			fill(mat[i], mat[i] + n, INF);
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			mat[a][b] = mat[b][a] = c;
			tn = max(tn, max(a, b));
		}
		for (int i = 0; i <= tn; i++) {
			mat[i][i] = 0;
		}
		for (int k = 0; k <= tn; k++) {
			for (int i = 0; i <= tn; i++) {
				for (int j = 0; j <= tn; j++) {
					if (mat[i][j] > mat[i][k] + mat[k][j]) {
						mat[i][j] = mat[i][k] + mat[k][j];
					}
				}
			}
		}
		int l = 0, sum, ans = INF;
		for (int i = 0; i <= tn; i++) {
			sum = 0;
			for (int j = 0; j <= tn; j++) {
				sum += mat[i][j];
			}
			if (ans > sum) {
				ans = sum;
				l = i;
			}
		}
		cout << l << " " << ans << endl;
	}

	return 0;
}