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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

struct Edge{
  int to;
  long long cost;
};

struct NODE{
  int pos;
  long long cost;
};
bool operator < (const NODE &a,const NODE &b){
  return a.cost > b.cost;
}
vector<Edge> g[100000],rg[100000];

int N;
const ll INF = 1e15;
vector<ll> dijkstra(vector<Edge> g[100000], int s){
  priority_queue<NODE> Q;
  Q.push({s,0});
  vector<ll> res(N,INF);
  while(Q.size()){
    NODE q= Q.top();Q.pop();
    if(res[q.pos] == INF){
      res[q.pos] = q.cost;
    }
    else{
      continue;
    }
    for(auto n : g[q.pos]){
      Q.push({n.to,q.cost+n.cost});
    }
  }
  return res;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b,c;
  while(cin>>n&&n){
    N = 0;
    rep(i,n){
      cin >> a >> b >> c;
      g[a].push_back({b,c});
      g[b].push_back({a,c});
      N = max(N,a);
      N = max(N,b);
    }
    ++N;
    int ans = inf;
    int town = inf;
    rep(i,N){
      int sum = 0;
      auto d = dijkstra(g,i);
      rep(j,N){
        sum += d[j];
      }
      if(ans > sum){
        ans = sum;
        town = i;
      }
    }
    cout << town << " " << ans << endl;
  }
  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;
        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 k=0; k<m; k++){
            for(int i=0; i<m; i++){
                for(int j=0; j<m; j++){
                    if(T[i][j]>T[i][k]+T[k][j]){
                        T[i][j] = T[i][k]+T[k][j];
                    }
                }
            }
        }

        int z=INF;
        int v=0;

        for(int i=0; i<m; i++){
            int total(0);
            for(int j=0; j<m; j++){
                total += T[i][j];
            }
            if(total < z){
                v = i;
                z = total;
            }

        }

        cout << v << ' ' << z << endl; 



    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
int fp[15][15];
int m;
void floyd()
{
   for(int i=0;i<m;i++)
      for(int j=0;j<m;j++)
      for(int k=0;k<m;k++)
   {
      fp[j][k]=min(fp[j][k],fp[j][i]+fp[i][k]);
   }
}
int main()
{
   int n;
   while(scanf("%d",&n),n)
   {
      m=0;
      memset(fp,INF,sizeof(fp));
      for(int i=0;i<n;i++)
      {
         int a,b,c;
         scanf("%d%d%d",&a,&b,&c);
         fp[a][b]=fp[b][a]=c;
         m=max(m,max(a,b)+1);
      }
      for(int i=0;i<m;i++)
         fp[i][i]=0;
      floyd();
      int ans,sum=INF;
      for(int i=0;i<m;i++)
      {
         int res=0;
         for(int j=0;j<m;j++)
         {
            res+=fp[i][j];
         }
         if(res<sum)
         {
            sum=res;
            ans=i;
         }
      }
      cout<<ans<<" "<<sum<<endl;
   }
}

C++: #include <cstdio>
#include <algorithm>
#include <climits>
typedef long long ll;

const int max_t = 20;
ll dist[max_t][max_t];

int main() {
	//freopen("aoj0189.txt", "r", stdin);
	while (1) {
		int n, t = 0;
		scanf("%d", &n);
		if (n == 0) break;
		
		for (int i = 0; i < max_t; i++) {
			std::fill(dist[i], dist[i] + max_t, INT_MAX);
		}
		for (int i = 0; i < n; i++) {
			int from, to, d;
			scanf("%d%d%d", &from, &to, &d);
			t = std::max(t, from);
			t = std::max(t, to);
			dist[from][to] = d;
			dist[to][from] = d;
		}
		for (int i = 0; i <= t; i++) {
			dist[i][i] = 0;
		}

		for (int i = 0; i <= t; i++) {
			for (int j = 0; j <= t; j++) {
				for (int k = 0; k <= t; k++) {
					if (dist[i][k] != INT_MAX && dist[k][j] != INT_MAX)
						dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}

		ll min_len = INT_MAX;
		int start = -1;
		for (int i = 0; i <= t; i++) {
			ll len = 0;
			for (int j = 0; j <= t; j++) {
				if (j == i) continue;

				len += dist[i][j];
			}
			if (len < min_len) {
				min_len = len;
				start = i;
			}
		}

		printf("%d %lld\n", start, min_len);
	}
	return 0;
}