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 INFINITY (1 << 30)

#define MAX_N 10

using namespace std;

int n,road[MAX_N][MAX_N] = {},d[MAX_N][MAX_N] = {};
int main() {
  int temp1,temp2,temp3,city ,alt,mincity ;
  long long int costtime ,cost;
  while(1){
    road[MAX_N][MAX_N] ={};
    d[MAX_N][MAX_N] ={};
      cin >> n;
    if(n == 0) break;
    city = mincity = 0; costtime ;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2>>temp3;
      if(road[temp1][temp2] != 0 ){
        if(road[temp1][temp2] > temp3) {
          road[temp1][temp2] = temp3;
          road[temp2][temp1] = temp3;
        }
      }
      else
      {
        road[temp1][temp2] = temp3;
        road[temp2][temp1] = temp3;
      }
      if(city < temp1|| city < temp2)  {city = (temp1 > temp2)?  temp1: temp2; }
    }
    //cout << city <<endl;
    city++;

    for (int i = 0; i <city ; ++i) {
      for (int j = 0; j < city; ++j) {
        if(i != j ) d[i][j] = INFINITY;
        if (road [i][j] !=0) d[i][j] =road[i][j];
      }
    }



      for (int i = 0; i <city ; ++i)
        for (int j = 0; j <city ; ++j)
          for (int k = 0; k < city; ++k) {
            if(d[j][i] !=INFINITY && d[i][k] != INFINITY){
              alt = d[j][i]+ d[i][k];
              if (alt < d[j][k]) d[j][k] = alt;
            }
          }




    for (int i = 0; i < city; ++i) {
        cost =0;
      for (int j = 0; j < city ; ++j) {
        cost += d[i][j];
       // cout << d[i][j]<<" ";
      }
      //cout<<endl;
      if(i == 0) costtime = cost;
      if (costtime > cost) {costtime = cost;mincity = i;}
    }
    cout<< mincity << " "<<costtime<<endl;

  }


  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <bitset>
#include <string.h>
#include <cmath>
#include <algorithm>
#define N 1000015
#define P pair<int,int>
#define ll long long
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
bool vis[102];
int dis[30];
int g[30][30];
int inf = 0x3f3f3f3f;
int n, sum;
void Dijkstra(int x) {
	mem(vis, false);
	mem(dis, inf);
	dis[x] = 0;
	// dis[1] = inf;
	for (int i = 0; i <= sum; ++i) {
		int MIN = inf, u = -1;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] < MIN) {
				MIN = dis[j];
				u = j;
			}
		}
		if (u == -1)	return;
		vis[u] = true;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] > g[u][j] + MIN) {
				dis[j] = g[u][j] + MIN;
			}
		}
	}
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	while (cin >> n, n) {
		int s, e, c;
		mem(g, inf);
		sum = -1;
		for (int i = 0; i < n; ++i) {
			cin >> s >> e >> c;
			sum = max(s, sum);
			sum = max(e, sum);
			g[s][e] = g[e][s] = min(g[s][e], c);
		}
		int ans_n, ans_v = inf;
		for (int i = 0; i <= sum; ++i) {
			Dijkstra(i);
			int sum_temp = 0;
			for (int j = 0; j <= sum; ++j) {
				if (dis[j] == inf) {
					sum_temp = inf;
					break;
				}
				sum_temp += dis[j];
			}
			if (sum_temp < ans_v) {
				ans_v = sum_temp;
				ans_n = i;
			}
		}
		cout << ans_n << " " << ans_v << endl;


	}

	return 0;
}

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

using namespace std;

int dp[10][10];

int main() {
  for (;;) {
    int n, m = 0;
    cin >> n;
    if (!n) return 0;
    for (int i = 0; i < 10; i++)
      fill(dp[i], dp[i]+10, 1<<20);
    for (int i = 0; i < n; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      m = max(m, max(a, b));
      dp[a][b] = c;
      dp[b][a] = c;
    }
    m++;
    for (int i = 0; i < m; i++)
      dp[i][i] = 0;
    for (int k = 0; k < m; k++)
      for (int i = 0; i < m; i++)
        for (int j = 0; j < m; j++)
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    int rt = 0, rc = 1<<20;
    for (int i = 0; i < m; i++) {
      int c = 0;
      for (int j = 0; j < m; j++)
        c += dp[i][j];
      if (rc > c) {
        rt = i;
        rc = c;
      }
    }
    cout << rt << ' ' << rc << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> P;
int INF = 1 << 10;

struct edge{
  int to;
  int cost;
};

vector<vector<edge> > G(10);
vector<int> d(10, INF);
vector<P> ans;

void init(){
  for(int i = 0; i < 10; i++){
	d[i] = INF;
  }
}

void display_d(){
  for(int i = 0; i < 10; i++){
	if(d[i] == INF) cout << "INF ";
	else cout << d[i] << " ";
  }
  cout << endl;
}

void initG(){
  for(int i = 0; i < 10; i++){
	G[i].clear();
  }
}

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  init();
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
	P p = que.top(); que.pop();
	int v = p.second;
	if(d[v] < p.first) continue;
	for(int i = 0; i < G[v].size(); i++){
	  edge e = G[v][i];
	  if(d[e.to] > d[v] + e.cost){
		d[e.to] = d[v] + e.cost;
		que.push(P(d[e.to], e.to));
	  }
	}
  }
  //cout << "d = ";
  //display_d();
  
}

int main(){
  int n = 0;
  while(1){
	cin >> n;
	if(n == 0) break;
	int a = 0, b = 0, c = 0;
	for(int i = 0; i < n; i++){
	  cin >> a >> b >> c;
	  edge e1, e2;
	  e1.to = b; e1.cost = c;
	  e2.to = a; e2.cost = c;
	  G[a].push_back(e1);
	  G[b].push_back(e2);
	}

	for(int i = 0; i < 10; i++){
	  dijkstra(i);
	  int sum = 0;
	  for(int j = 0; j < 10; j++){
		if(d[j] == INF) continue;
		sum += d[j];
	  }
	  if(sum != 0) ans.push_back(P(sum, i));
	}

	sort(ans.begin(), ans.end());
	cout << ans[0].second << " " << ans[0].first << endl;
	ans.clear();
	initG();
  }
  return 0;
}