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 <iostream>
#define INF 1000000
using namespace std;

int main() {
	for (;;)
	{
		int edge[11][11];
		int city = 0;
		for (int i = 0;i < 11;i++) 
		{
			for (int j = 0;j < 11;j++)
			{
				if(i == j)
				{
					edge[i][i] = 0;
					continue;
				}
				edge[i][j] = INF;
			}
		}
		int n;
		cin >> n;
		if (n == 0) break;
		for (int i = 0;i < n;i++)
		{
			int a,b,c;
			cin >> a >> b >> c;
			edge[a][b] = c;
			edge[b][a] = c;
 			city = max (max(a,b)+1,city);
		}
		for (int i = 0;i < city;i++)
		{
			for (int j = 0;j < city;j++)
			{
				for (int k = 0;k < city;k++)
				{
					edge[i][k] = min(edge[i][k],edge[i][j]+edge[j][k]);
				}
			}
		}
		//??????????????§edge?????????????????¢?????\??£?????????(??????????????§?????????)
		int min = INF;
		int minCity;
		for (int i = 0;i < city;i++)
		{
			int sum = 0;
			for (int j = 0;j < city;j++)
			{
				if (i == j) continue;
				sum += edge[i][j];
			}
			if (sum < min)
			{
				min  = sum;
				minCity = i;
			}
		}
		cout << minCity << " " << min << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;


typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

vector<Weight> dijkstra2(const Graph &g, int s) {
  int n = g.size();
  vector<Weight> dist(n, INF);
  dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (dist[e.dst] < e.weight) continue;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
  return dist;
}


int main() {
  int n;
  while(cin >> n,n) {
    Graph g(10);
    int m = 0;
    while(n--) {
      int a,b,c;
      cin >> a >> b >> c;
      g[a].push_back(Edge(a,b,c));
      g[b].push_back(Edge(b,a,c));
      m = max(max(m, a), b);
    }
    m++;
    g.resize(m);
    int res, mi = INF;
    REP(i, m) {
      vector<int> d = dijkstra2(g, i);
      int sum = 0;
      REP(j, m)
        sum += d[j];
      if (mi > sum) {
        mi = sum;
        res = i;
      }
    }
    cout << res << " " << mi << endl;
  }
}

C++: #include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define inf (1<<25)
int main(){
	int n,a,b,c;
	int cost[64][64];
	while(cin >> n, n) {
		rep(i,64) {
			rep(j,64) {
				cost[i][j] = inf;
			}
		}
		int max = 0;
		rep(i,n) {
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			cost[a][a] = 0;
			cost[b][b] = 0;
			if(max < a) max = a;
			if(max < b) max = b;
		}

		rep(i,max+1) {
			rep(j,max+1) {
				rep(k,max+1) {
					int len = cost[i][j] + cost[j][k];
					if(len < cost[i][k]) {
						cost[i][k] = len;
					}
				}
			}
		}
		int min = inf, rmin = -1;
		rep(i,max+1) {
			int ret = 0;
			rep(j,max+1) {
				ret += cost[i][j];
			}
			if(min > ret) {
				min = ret;
				rmin = i;
			}
		}
		cout << rmin << " " << min << endl;
	}
	return 0;
}

C++: //Name: Convenient Location
//Level: 2
//Cateogry: グラフ,Graph,全点間最短距離,All- points shortest path
//Note:

/**
 * Warshall-Floydで全点間最短距離を求め、行ごとに総和を求めて最小になるものを出力する。
 * 存在している街の番号を別に管理しないといけないのが面倒くさいが、隣接行列としては10×10でとってしまい、
 * どこにも行けない街があったら弾くという処理にすると楽。
 *
 * オーダーは O(N^3)。
 */

#include <iostream>
#include <vector>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    vector<vector<int>> dist(10, vector<int>(10, -1));
    for(int i = 0; i < N; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        dist[a][b] = dist[b][a] = c;
        dist[a][a] = 0;
        dist[b][b] = 0;
    }

    for(int k = 0; k < 10; ++k) {
        for(int i = 0; i < 10; ++i) {
            for(int j = 0; j < 10; ++j) {
                if(dist[i][k] == -1 || dist[k][j] == -1) continue;
                const int nd = dist[i][k] + dist[k][j];
                if(dist[i][j] == -1 || dist[i][j] > nd) {
                    dist[i][j] = nd;
                }
            }
        }
    }

    int town = -1;
    int sum = -1;
    for(int i = 0; i < 10; ++i) {
        int tmp = 0;
        bool valid = false;
        for(int j = 0; j < 10; ++j) {
            if(dist[i][j] != -1) {
                tmp += dist[i][j];
                valid = true;
            }
        }
        if(valid && (sum == -1 || tmp < sum)) {
            town = i;
            sum = tmp;
        }
    }
    cout << town << ' ' << sum << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(solve()) ;
    return 0;
}