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;
      }
//       debug(sum);
    }
    cout << town << " " << ans << endl;
  }
  return 0;
}

C++: /*
AOJ 0189 Convenient Location

?¢????????±???????????????¬??? ??°??¶??????????????¬?????? ???????????????  ?????¬?????° ????¶????10

?????\??????????????\??????????¬¬?????????n (1 ??? n ??? 45)?????\?????\n?????? (x, y, d)???x??°y????????????d
??????????????¬?????? ??? ????????????
 */
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }

const int N = 10;
const int INF = 0x3F3F3F3F;
int dist[N][N];
int n, e, name[N];
map<int, int> name_map;

int getid(int x) {
  map<int, int>::iterator it = name_map.find(x);
  if (it == name_map.end()) {
    name_map[x] = n;
    name[n] = x;
    return n++;
  } else {
    return it->second;
  }
}

int main(int argc, char *argv[]) {
  int x, y, d;
  while (scanf("%d", &e) == 1 && e > 0) {
    n = 0;
    name_map.clear();
    CLR(dist, INF);
    while (e--) {
      scanf("%d %d %d", &x, &y, &d);
      x = getid(x); y = getid(y);
      checkmin(dist[x][y], d);
      checkmin(dist[y][x], d);
    }
    REP(i, n) dist[i][i] = 0;
    REP(k, n) REP(i, n) REP(j, n) {
      checkmin(dist[i][j], dist[i][k] + dist[k][j]);
    }
    int ans = INF, best = -1;
    REP(i, n) {
      int current = accumulate(dist[i], dist[i] + n, 0);
      if (current < ans) {
        ans = current;
        best = name[i];
      }
    }
    printf("%d %d\n", best, ans);
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int map[110][110];
int mine[110];
int main()
{
    int a;
    while(scanf("%d",&a)&&a)
    {
        for(int i=0;i<a;i++)
    {
        for(int j=0;j<a;j++)
        {
            if(i==j)
            {
                map[i][i]=0;
            }
            else
            map[i][j]=99999;
        }
    }
    int fuck=0;
    for(int i=1;i<=a;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        map[x][y]=z;
        map[y][x]=z;
        fuck=max(fuck,max(x,y));

    }
    for(int i=0;i<=fuck;i++)
    {
        for(int j=0;j<=fuck;j++)
        {
            for(int k=0;k<=fuck;k++)
            {
                if(map[j][k]>map[j][i]+map[i][k])
                map[j][k]=map[j][i]+map[i][k];
            }
        }
    }
    int sum;
    int hh=100000;
    for(int i=0;i<=fuck;i++)
    {sum=0;
        for(int j=0;j<=fuck;j++)
        {
            sum+=map[i][j];
        }
        mine[i]=sum;
        hh=min(sum,hh);
    }


    for(int i=0;i<=fuck;i++)
    {
        if(mine[i]==hh)
        {
            cout<<i<<" "<<mine[i]<<endl;
            break;
        }
    }
    }


}