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 <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

int INF=1e8;
int dist[15][15];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  while(cin>>n,n){

    //??\????????£??\???????????¢?????????
    fill(dist[0],dist[0]+15*15,INF);
    int m=0,a,b,d;
    rep(i,n){
      cin>>a>>b>>d;
      dist[a][b]=dist[b][a]=min(dist[a][b],d);
      m=max({m,a,b});
    }
    ++m;

    rep(i,m) dist[i][i]=0; //i??????i????????¢???0
    //???????????£???????????????
    rep(k,m) rep(i,m) rep(j,m)
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

    //(?????¢?????????,????????????)
    pii re=pii(INF,-1);
    rep(i,m){

      int sum=0; //??????????¨????
      rep(j,m) sum+=dist[i][j];

      //????°??????´??°
      re=min(re,pii(sum,i));
    }
    cout<<re.Y<<" "<<re.X<<endl;
  }
  return 0;
}

C++: #include<algorithm>
#include<limits.h>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>

using namespace std;

int C = 0;
int N = 0;
int R[10][10] = { 0 };
int M[10] = { 0 };

bool solve() {
	int sum = INT_MAX,ans = 0;
	for (int i = 0; i <= C; i++) {
		queue<int> q;
		q.push(i);
		M[i] = 0;
		while (!q.empty()) {
			for (int j = 0; j <= C; j++) {
				if (R[q.front()][j] != -1 && (M[j] == -1 || M[q.front()] + R[q.front()][j] < M[j])) {
					
					M[j] = R[q.front()][j] + M[q.front()];
					q.push(j);
				}
			}
			q.pop();
		}
		int s = 0;
		for (int j = 0; j <= C; j++)
			s += M[j];
		if (sum > s) {
			sum = s;
			ans = i;
		}
		memset(M, -1, sizeof(int) * 10);
	}
	printf("%d %d\n", ans,sum);
}

int main(void) {
	int n = 0;
	//scanf("%d", &n);
	//for (int i = 0; i < n; i++) {
		C = 0;
		memset(R, -1, sizeof(int) * 100);
		memset(M, -1, sizeof(int) * 10);
		scanf("%d", &N);
		for (int j = 0; j < N; j++) {
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			R[a][b] = c;
			R[b][a] = c;
			C = max(C, max(a, b));
		}
		solve();
	//}
}

C++: #include <iostream>
#define inf 10000000
#define llint long long int

using namespace std;

int n;
int town_num;
int graph[12][12];

int dist[12];
bool checked[12];

int getmin(int a, int b)
{
  if(a > b) return b;
  else return a;
}

void dijkstra(int start)
{
  for(int i = 0; i < town_num; i++) checked[i] = false;
  for(int i = 0; i < town_num; i++) dist[i] = inf;
  dist[start] = 0;

  while(1){
    int min = inf, min_i = -1;
    for(int i = 0;i < town_num; i++){
      if(checked[i] || dist[i] == inf) continue;
      if(min > dist[i]){
		min = dist[i];
		min_i = i;
      }
    }
    if(min_i == -1) break;
  	
    checked[min_i] = true;
    for(int j = 0; j < town_num; j++){
    	if(checked[j]) continue;
    	if(graph[min_i][j] == inf) continue;
      dist[j] = getmin(dist[j], dist[min_i] + graph[min_i][j]);
    }
  }
}


int getsum(int pivot)
{
  dijkstra(pivot);

  int sum = 0;
  for(int i = 0; i < town_num; i++){
    sum += dist[i];
  }
  return sum;
}


int main(void)
{
  while(1){
	 cin >> n;
	if(n == 0) break;

	for(int i = 0; i < 12; i++){
		for(int j = 0; j < 12; j++){
			if(i == j) graph[i][j] = 0;
			else graph[i][j] = inf;
      	}
	}

  	town_num = -1;
    int a, b, c;
    for(int i = 0; i < n; i++){
      	cin >> a >> b >> c;
      	if(graph[a][b] > c){
			graph[a][b] = c;
			graph[b][a] = c;
    	}
    	if(a > town_num) town_num = a;
    	if(b > town_num) town_num = b;
    }
  	town_num++;

    int min_i, min = inf, val;
    for(int i = 0; i < town_num; i++){
      val = getsum(i);
      if(val < min){
		min = val;
		min_i = i;
      }
    }

    cout << min_i << " " << min << endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define INF 100000000
int d[11][11];
int min(int a,int b){
	if(a<b){
		return a;
	}else{
		return b;
	}
}
void warsall_floyd(){
	for(int i=0;i<11;i++){
		for(int j=0;j<11;j++){
			for(int k=0;k<11;k++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}	
		}
	}
	return;
}
int main(){
	while(1){
		int n,a,b,c,ans;
		ans=INF;
		for(int i=0;i<11;i++){
			for(int j=0;j<11;j++){
				d[i][j]=INF;
			}
			d[i][i]=0;
		}
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			d[a][b]=c;d[b][a]=c;
		}
		warsall_floyd();
		for(int i=0;i<11;i++){
			a=0;
			for(int j=0;j<11;j++){
				if(d[i][j]<INF){
					a+=d[i][j];
				}
			}
			if(a<ans&&a!=0){
				ans=a;b=i;
			}
		}
		if(ans==INF){
			cout<<"0 0"<<endl;
		}else{
			printf("%d %d\n",b,ans);
		}
	}
	return 0;
}