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>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

#define INF (1 << 28)
#define MAX_E 1000
#define MAX_V 100

int cost[MAX_V][MAX_V];
bool used[MAX_V];
int d[MAX_V];

// O(V^2)??§?????????????????£??¨??????

void shortest_path(int s, int V){
	for(int i = 0; i < V; i++){
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;
	while(true){
		
		int add_v = -1;
		
		for(int u = 0; u < V; u++){
			if(!used[u] && (add_v == -1 || d[u] < d[add_v])){
				add_v = u;
			}
		} // ??´??°????????????????±????
		
		if(add_v == -1){
			break;
		} // ??´??°???????????????????????´????????????
		used[add_v] = true;
		
		for(int u = 0; u < V; u++){
			d[u] = min(d[u], d[add_v] + cost[add_v][u]);
		} // ???????????????????????????????°???????????????´??°
	}
}

int main(){
	
	int V = 10; // V???????????°
	
	int n;
	
	bool town_use[10];
	
	while(true){
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 100; j++){
				cost[i][j] = INF;
			}
		}
		
		for(int i = 0; i < 10; i++){
			town_use[i] = false;
		}
		
		for(int i = 0; i < n; i++){
			int hoge1, hoge2, hoge3;
			cin >> hoge1 >> hoge2 >> hoge3;
			cost[hoge1][hoge2] = hoge3;
			cost[hoge2][hoge1] = hoge3;
			town_use[hoge1] = true;
			town_use[hoge2] = true;
		}
		
		int min = INF;
		int ans = 0;
		
		for(int i = 0; i < 10; i++){
			int sum = 0;
			if(town_use[i]){
				shortest_path(i, V);
				for(int j = 0; j < 10; j++){
					if(d[j] != INF){
						sum += d[j];
					}
				}
				if(sum < min){
					min = sum;
					ans = i;
				}
			}
		}
		
		cout << ans << " " << min << endl;
		
	}
	
	return 0;
}

C++: #include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

const int TOWN = 11;
const int ROAD = 50;
const int INF = 10000;

int d[TOWN][TOWN] ;

int n,a,b,c;
int main()
{
	while(cin >> n && n)
	{
		memset(d,INF,sizeof(d));
		int townnum = 0;
		REP(n)
		{
			cin>> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
			d[i][i] = 0;
			townnum = max(townnum,a);
			townnum = max(townnum,b);
		}
		//cout << "town "<<townnum << endl;
		rep(k,townnum+1)rep(i,townnum+1)rep(j,townnum+1)//if(d[i][j] != INF)
		{
			d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			d[j][i] = d[i][j];
		}
		int time = 1000000,town = 0;
		
		rep(i,townnum+1)//town i
		{
			int sum = 0;
			rep(j,townnum+1) sum += d[i][j];//i to j
			//cout << sum << endl;
			if(sum < time){ time = sum; town = i;}
		}
		cout << town << " " << time << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>

#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

const int INF = 1e+8;

typedef struct edge_def {
	int from;
	int to;
	int cost;
} edge;

int V, E;
edge es[90];
int d[10];

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)

void min_time(int s) {
	int i;
	FOR(i,0,V+1) d[i] = INF;
	d[s] = 0;
	while (1) {
		bool update = false;
		FOR(i,0,2*E) {
			edge e = es[i];
			if (e.from != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update) break;
	}
}

int main() {
	int i, j;
	int total;
	int minT;

	while (1) {
		scanf("%d ", &E);
		if (!E) break;

		V = 0;
		FOR(i,0,E) {
			scanf("%d%d%d ", &(es[i].from), &(es[i].to), &(es[i].cost));
			es[E+i].from = es[i].to;
			es[E+i].to = es[i].from;
			es[E+i].cost = es[i].cost;
			V = max(V, es[i].to);	
		}

		total = INF;
		minT = INF;
		FOR(i,0,V+1) {
			min_time(i);

			int sum = 0;
			FOR(j,0,V+1)
				sum += d[j];

			if (sum < total) {
				total = sum;
				minT = i;
			} else if (sum == total && i < minT)
				minT = i;
		}

		printf("%d %d\n", minT, total);
	}	

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 147483600

int d[10][10];
bool exist[10];

int main(){
  int n;
  while(cin>>n ,n){
    fill(d[0], d[10], INF);
    fill(exist, exist+10, false);
    rep(i,10) d[i][i]=0;
    rep(i,n){
      int a,b,c;
      scanf("%d %d %d", &a, &b, &c);
      d[a][b]=c;
      d[b][a]=c;
      exist[a]=true;
      exist[b]=true;
    }

    rep(k,10) rep(i,10) rep(j,10) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

    int res=0;
    int best=INF;
    rep(i,10) if(exist[i]){
      int tmp=0;
      rep(j,10) if(exist[j]) tmp += d[i][j];
      if(tmp < best){
        best = tmp;
        res = i;
      }
    }

    printf("%d %d\n", res, best);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
typedef pair<int,int> P;

#define INF 1000000
int cost[10][10];
int n,m;

int main(){
  while(1){
    cin >> n;
    if(!n)break;

    m = 0;
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        if(i==j){
          cost[i][j] = 0;
        }else{
          cost[i][j] = INF;
        }
      }
    }
    for(int i=0;i<n;i++){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      if(m<x||m<y){
        m = max(x,y);
      }
      cost[x][y] = z;
      cost[y][x] = z;
    }
    m++;

    for(int k=0;k<m;k++){
      for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
          cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
        }
      }
    }

    int mini = INF;
    int index;
    for(int i=0;i<m;i++){
      int sum = 0;
      for(int j=0;j<m;j++){
        sum += cost[i][j];
      }
      if(mini>sum){
        mini = sum;
        index = i;
      }
    }
    cout << index << " " << mini << endl;
  }
}