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 <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <cmath>
#include <fstream>
const int MAX = 1e4+10;
const int INF = 1e6;

using namespace std;

int n;
int cs;
int d[MAX][MAX] = {0};//两点间最短距离 
int sum, ans;
int pos;//最合适位置 

//弗洛伊德最短路径 
void  Floyd(){
	for(int i=0; i<=cs; i++)
		for(int j=0; j<=cs; j++)
			for(int k =0; k<=cs; k++){
				d[j][k] = min(d[j][k], d[j][i]+d[i][k]);
			}			
}
 
//测试函数 
int main(){
	/*ifstream cin ("D:\\钢铁程序员\\程序数据\\062最佳宿舍.txt");//从文件读取数据流，省去手动输入的麻烦 
	if(!cin){//读取如果失败 
		cout << "ERROR" << endl;
	}*/
	while(cin >> n, n){
		cs = 0;//最大城市编号 
		for(int i=0; i<=n; i++)
			for(int j=0; j<=n; j++){
				if(i == j)
					d[i][j] = 0;
				else
					d[i][j] = INF;
			}
		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
			cs = max(cs, a);
			cs = max(cs, b);
		}
				
		Floyd();		
		//找最合适位置 
		ans = INF;
		for(int i=0; i<=cs; i++){
			sum = 0;
			for(int j=0; j<=cs; j++){
				sum += d[i][j];
			}
			if(sum < ans){
				pos = i;
				ans = sum;
			}
		} 
		cout << pos << " " << ans << endl;
	}
	//cin.close();//打开文件以后要关闭 
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>

using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;

//int main() {
//	int n,c,v;
//	array<array<pii, 50>, 50> graph = {};
//	scanf("%d %d %d", &n, &c, &v);
//	vector<pii> roads(v, {0,0});
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		roads[i].first = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		roads[i].second = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		graph[roads[i].first][roads[i].second].first = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		graph[roads[i].first][roads[i].second].second = s;
//	}
//
//	array<int> 
//
//	return 0;
//}

int main() {
	int n;
	while (scanf("%d", &n)) {
		if (!n)
			return 0;
		array<array<int, 11>, 11> graph = {};
		for(auto itr = graph.begin(); itr != graph.end(); itr++)
			fill(itr->begin(), itr->end() , -1);
		int m = 0;
		for (int i = 0; n > i; i++) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);

			graph[a][b] = c;
			graph[b][a] = c;
			m = max({a,b,m});
		}
		m++;
		pii Min = { INT_MAX,INT_MAX };
		for (int i = 0; m > i; i++) {
			priority_queue<pii, vector<pii>, greater<pii>> que;
			vector<int> al(m, -1);
			for (int j = 0; m > j; j++) {
				if (graph[i][j] != -1) {
					que.push({ graph[i][j], j });
				}
			}
			al[i] = 0;
			while (!que.empty()) {
				pii num = que.top();
				que.pop();
				if (al[num.second] != -1)
					continue;
				al[num.second] = num.first;
				for (int j = 0; m > j; j++) {
					if (graph[num.second][j] != -1 && al[j] == -1) {
						que.push({ num.first + graph[num.second][j], j });
					}
				}
			}
			Min = min(Min, { accumulate(al.begin(), al.end(),0),i });
		}
		printf("%d %d\n", Min.second, Min.first);
	}
	return 0;
}

C++: // Warshall-floyd
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 114514

int n, a, b, c, v, d[11][11];// v: num of nodes

void init()
{
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            if(i==j)// If not exist cost, cost=INF
                d[i][j] = 0;
            else
                d[i][j] = INF;
        }
    }
}

int main(void)
{
    ios::sync_with_stdio(false);
    while(1) {
        cin >> n;
        if(n == 0) break;
        init();

        v = -1;
        for(int i=0; i<n; i++) {
            cin >> a >> b >> c;
            d[a][b] = c; d[b][a] = c;
            v = max(max(v, a), b);
        }
        v++;

        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 city, dist = INF;
        for(int i=0; i<v; i++) {
            int sum = 0;
            for(int j=0; j<v; j++) {
                sum += d[i][j];
            }
            if(sum < dist) {
                dist = sum;
                city = i;
            }
        }
        cout << city << " " << dist << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int d[11][11];
static const int INF = 99999999;

void solve() {
  int n;
  while (cin >> n && n) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        d[i][j] = INF;
      }
      d[i][i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int from, to, dist;
      cin >> from >> to >> dist;
      d[from][to] = dist;
      d[to][from] = dist;
    }
    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 min_sum_dist = INF;
    int pos = 0;
    for (int i = 0; i < 10; i++) {
      int sum = 0;
      for (int j = 0; j < 10; j++) {
        if (d[i][j] != INF) sum += d[i][j];
      }
      if (sum == 0) continue;
      if (min_sum_dist > sum) {
        min_sum_dist = sum;
        pos = i;
      }
    }
    cout << pos << ' ' << min_sum_dist << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve()
  return 0;
}

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;     //How many towns are there?

		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;
			}
		}

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

		int dis=INF,name=-1,tmp;
		for(int i=0;i<m;i++){
			tmp = 0;
			for(int j=0;j<m;j++){
				tmp += d[i][j];
			}
			if(dis>tmp){
				dis=tmp;
				name=i;
			}
		}
		cout << name << " " << dis << endl;


	}

	return 0;
}