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 TOWN_MAX 11
#define ROAD_MAX 46
#define INF 10000000

int solve(int);

int main(int argc, char const* argv[]) {
    int n;

    while (true) {
        std::cin >> n;
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

int solve(int road_num) {
    int distances[TOWN_MAX][TOWN_MAX];

    for (int i = 0; i < TOWN_MAX; i++)
        for (int j = 0; j < TOWN_MAX; j++)
            distances[i][j] = (i == j) ? 0 :INF;

    for (int i = 0; i < road_num; i++) {
        int src, dest, cost;
        std::cin >> src >> dest >> cost;
        distances[src][dest] = cost;
        distances[dest][src] = cost;
    }

    for (int infix_road = 0; infix_road < road_num; infix_road++) {
        for (int begin_town = 0; begin_town < TOWN_MAX; begin_town++) {
            for (int end_town = 0; end_town < TOWN_MAX; end_town++) {
                distances[begin_town][end_town] = std::min(distances[begin_town][end_town],
                        distances[begin_town][infix_road] + distances[infix_road][end_town]);
            }
        }
    }

    int min_cost       = INF*50;
    int min_cost_index = 0;
    for (int i = 0; i < TOWN_MAX; i++) {
        int sum_cost   = 0;
        for (int j = 0; j < TOWN_MAX; j++) {
            sum_cost += distances[i][j];
        }

        if (sum_cost < min_cost) {
            min_cost       = sum_cost;
            min_cost_index = i;
        }
    }

    std::cout << min_cost_index << " " << min_cost % INF << std::endl;

    return 0;
}

C++: #include <iostream>
#include <set>
#include "procpn.hpp"

using namespace std;
using namespace procon;

int main(){
    int e;
    set<int> v;
    int d[MAX_V][MAX_V];
    while(cin >> e,e){
        fill((int*)d,(int*)d + MAX_V * MAX_V,INF);
        FOR(i,0,e){
            int f,t,p;
            cin >> f >> t >> p;
            d[f][t] = p;
            v.insert(f); v.insert(t);
        }
        FORI(i,v) d[*i][*i] = 0;

        warshall_floyed(MAX_V,d);
        int town = 0;
        int m = INF;
       FORI(i,v){
            int t = 0;
            FORI(j,v){
                t += d[*i][*j];
            }
            if(m < t) continue;
            m = t;
            town = *i;
        }
        cout << town << " " << m << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>

using namespace std;
#define INF 100000

int  road, max = 0, time[10][10],sum,root[10];

void dijkstra(int a) {

	int i,j,k=INF,used[10],minroot;
	for (i = 0; i <= max; i++) {
		used[i] = 0;
		root[i] = INF;
	}
	root[a] = 0;
	while (1) {
		minroot = INF;
		for (i = 0; i <= max; i++) {
			if (used[i] == 0&&root[i]<minroot) {
				j = i;
				minroot = root[i];
			}
			
		}
		if (k == j) {
			break;
		}
		else {
			k = j;
		}
		used[j] = 1;
		for (i = 0; i <= max; i++) {
			if (root[i] > root[j] + time[j][i]) {
				root[i] = root[j] + time[j][i];
			}

		}
	}
	sum = 0;
	for (i = 0; i <= max; i++)sum += root[i];

	return ;
}






int main() {
	cin >> road;
	int i, j, a, b, c, save_a[45], save_b[45],save_c[45], min_sum=INF ,ans_town;

	for (i = 1; i <= road; i++) {
		cin >> a >> b >> c;
		if (max < a) max = a;
		if (max < b) max = b;
		save_a[i] = a;
		save_b[i] = b;
		save_c[i] = c;
	}
	for (i = 0; i <= max; i++) {
		for (j = 0; j <= max; j++) {
			time[i][j] = INF;
		}
		time[i][i] = 0;
	}
	for (i = 1; i <= road; i++) {
		time[save_a[i]][save_b[i]] = save_c[i];
		time[save_b[i]][save_a[i]] = save_c[i];
	}
	for (i = 0; i <= max; i++) {
		dijkstra(i);
		if (sum < min_sum) {
			ans_town = i;
			min_sum = sum;
		}
	}
	cout << ans_town << " " << min_sum << endl;
}

C++: #include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<stack> 
#include<bitset>
#include<iterator>
#include<numeric>
using namespace std;
typedef long long ll;

int E,V;
int G[11][11];
int d[11];

void floyd(){
	for(int k = 0 ; k < V ; k ++){
		for(int i = 0 ; i < V ; i ++){
			for(int j = 0 ; j < V ; j ++){
				G[i][j] = min(G[i][j] , G[i][k]+G[k][j]);
			}
		}
	}
}

int main(){
	while(scanf("%d",&E) != EOF && E){
		int u,v,w;
		V = 0;
		memset(G,0x3f3f3f3f,sizeof(G));
		for(int i = 0 ; i < E ; i ++){
			scanf("%d%d%d",&u,&v,&w);
			G[u][v] = w;
			G[v][u] = w;
			// ?点
		 	V = max(V,max(u,v)+1);
		}
		for(int i = 0 ; i < V ; i ++) G[i][i] = 0;
		floyd();
		
		memset(d,0,sizeof(d));		
		int index = 0;
		int ans = 0x3f3f3f3f;
		for(int i = 0 ; i < V ; i ++){
			for(int j = 0 ; j < V ; j ++){
				d[i] += G[i][j];	
			}
			if(ans > d[i]){
				index = i;
				ans = d[i];
			}
		}
		printf("%d %d\n",index,ans);
		
	}	
	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n;// # of edge
  while (true)
    {
      cin >> n;
      if (n == 0)
	break;
      set<int> towns;
      map<PI,int> edges;
      REP(i,0,n)
	{
	  int a, b, c;
	  cin >> a >> b >>c;
	  towns.insert(a);
	  towns.insert(b);
	  PI p;
	  if (a < b)
	    p = PI(a,b);
	  else
	    p = PI(b,a);
	  edges[p] = c;
	}
      VI t(towns.size());
      vector<VI> e(towns.size(), VI(towns.size()));
      int j = 0;
      for (auto i = towns.begin(); i != towns.end(); i++)
	{
	  t[j] = *i;
	  j++;
	}
      for (uint i = 0; i < t.size(); i++)
	for (uint j = i; j < t.size(); j++)
	  if (edges.find(PI(t[i],t[j]))!=edges.end()) 
	    {
	      e[i][j] = edges[PI(t[i],t[j])];
	      e[j][i] = edges[PI(t[i],t[j])];
	    }
	  else if (i == j)
	    e[i][i] = 0;
	  else 
	    {
	      e[i][j] = 1000;
	      e[j][i] = 1000;
	    }

      for (uint r = 0; r < t.size(); r++)
	for (uint p = 0; p < t.size(); p++)
	  for (uint q = 0; q < t.size(); q++)
	    if (e[p][q] > e[p][r] + e[r][q])
	      e[p][q] = e[p][r] + e[r][q];
      int min = 0;
      int i_min = 0;
      bool first = true;
      for (uint p = 0; p < t.size(); p++)
	{
	  if (accumulate(e[p].begin(), e[p].end(), 0) < min|| first)
	    {
	      min = accumulate(e[p].begin(), e[p].end(), 0);
	      i_min = t[p];
	      first = false;
	    }
	}
      cout << i_min <<"\t"<< min << endl;
    }
}