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 <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>

using namespace std;

const int inf = 0x7f7f7f;
const int maxn = 111;
int G[maxn][maxn];
int d[maxn];
int n, m;

void init() {
	m = 0;
	memset(d, 0, sizeof(d));
	for(int i = 0; i < maxn; i++) {
		for(int j = 0; j < maxn; j++) {
			G[i][j] = G[j][i] = inf;
		}
		G[i][i] = 0;
	}
}

int main() {
	// freopen("in", "r", stdin);
	int u, v, w;
	while(~scanf("%d", &n) && n) {
		init();
		for(int i = 0; i < n; i++) {
			scanf("%d %d %d", &u, &v, &w);
			if(w < G[u][v]) {
				G[u][v] = G[v][u] = w;
			}
			m = max(m, max(v, u) + 1);
		}
		for(int k = 0; k < n; k++) {
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					if(G[i][j] > G[i][k] + G[k][j]) {
						G[i][j] = G[i][k] + G[k][j];
					}
				}
			}
		}
		for(int i = 0; i < m; i++) {
			for(int j = 0; j < m; j++) {
				d[i] += G[i][j];
			}
		}
		int ii = 0;
		int ans = d[0];
		for(int i = 1; i < m; i++) {
			if(ans > d[i]) {
				ans = d[i];
				ii = i;
			}
		}
		printf("%d %d\n", ii, ans);
	}
}

C++: #include <algorithm>
#include <climits>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int n, a, b, c;
	while (cin >> n, n) {
		vector<vector<pair<int, int>>> d(10);
		for (int i = 0; i < n; ++i) {
			cin >> a >> b >> c;
			d[a].emplace_back(b, c);
			d[b].emplace_back(a, c);
		}
		vector<pair<int, int>> ans(10);
		for (int i = 0; i < 10; ++i) {
			priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> e;
			e.emplace(0, i);
			vector<bool> f(10);
			vector<int> g(10, INT_MAX);
			g[i] = 0;
			while (!e.empty()) {
				pair<int, int> h = e.top();
				e.pop();
				f[h.second] = true;
				for (pair<int, int>& j : d[h.second]) {
					if (!f[j.first]) {
						if (g[h.second] + j.second < g[j.first]) {
							g[j.first] = g[h.second] + j.second;
							e.emplace(g[j.first], j.first);
						}
					}
				}
			}
			for_each(g.begin(), g.end(), [](int& a) { if (INT_MAX == a) a = 0; });
			ans[i] = make_pair(accumulate(g.begin(), g.end(), 0), i);
		}
		for_each(ans.begin(), ans.end(), [](pair<int, int>& a) { if (0 == a.first) a.first = INT_MAX; });
		sort(ans.begin(), ans.end());
		cout << ans.front().second << ' ' << ans.front().first << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define MAX_V 11
#define INF (1e9)
#define cost first
#define node second
using namespace std;
typedef pair <int, int> P;
int n,m;
vector<P> G[101];

//prim
int prim(){
  int res = 0;
  bool visited[101]={};
  int D[101];
  for(int i=0;i<n;i++) D[i] = INF;
  priority_queue <P, vector<P>, greater<P> > Q;
  Q.push(P(0,0));
  while(!Q.empty()){
    P t = Q.top(); Q.pop();
    if(visited[t.node]) continue;
    visited[t.node] = true;
    res += t.cost;
    for(int i=0;i<G[t.node].size();i++){
      int nnode = G[t.node][i].node;
      int ncost = G[t.node][i].cost;
      if(D[nnode] > ncost) Q.push(P(ncost,nnode)),D[nnode]=ncost;
    }
  }
  return res;
}

/*
void init(int n){
  for(int i=0;i<n;i++) G[i].clear();
}
*/

// warshall froyd
	  
int d[MAX_V][MAX_V];
int used[MAX_V];

void init(){
  for(int i=0;i<MAX_V;i++)
    for(int j=0;j<MAX_V;j++) i!=j ? d[i][j]=INF : d[i][j]=0;
}
  
void warshall_froyd(){
  for(int k=0;k<MAX_V;k++)
    for(int i=0;i<MAX_V;i++)
      for(int j=0;j<MAX_V;j++) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
}



int main() {
  while(1){
    cin >> n;
    if(!n)break;
    init();
    for(int i=0;i<n;i++){
      int a,b,c;
      cin >>a>>b>>c;
      d[a][b] = c;
      d[b][a] = c;
    }
    warshall_froyd();
    int ans = INF;
    for(int i=0;i<MAX_V;i++){
      int sum = 0;
      for(int j=0;j<MAX_V && sum < INF;j++) sum+= d[i][j];
      ans = min(sum,ans);
    }
    cout << ans <<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
        int N;
        while(cin>>N,N){
                vector<vector<int>>data;
                set<int>d;
                data.resize(N);
                for (int i = 0; i < N; i++) {
                        data[i].resize(N);
                        for (int j = 0; j < N; j++) {
                                data[i][j]=INT_MAX/6;
                        }
                        data[i][i]=0;
                }
                for (int i = 0; i < N; i++) {
                        int a,b,c;
                        cin>>a>>b>>c;
                        data[a][b]=c;
                        data[b][a]=c;
                        d.insert(a);
                        d.insert(b);
                }
                for (int k = 0; k < N; k++) {
                        for (int i = 0; i < N; i++) {
                                for (int j = 0; j < N; j++) {
                                        data[i][j]=min(data[i][j],data[i][k]+data[k][j]);
                                        data[j][i]=data[i][j];
                                }
                        }
                }
                long long int ans=INT_MAX;
                int memo2;
                for(auto x:d){
                        long long int memo=0;
                        for(auto y:d){
                                memo+=data[x][y];
                        }
                        if(ans>memo){
                                memo2=x;
                                ans=memo;
                        }
                }
                cout<<memo2<<" "<<ans<<endl;
                data.clear();
                d.clear();
        }

}