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] ={};
      cin >> n;
    if(n == 0) break;
    city = mincity = 0; costtime ;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2>>temp3;
      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[i][k] !=INFINITY && d[k][j] != INFINITY){
            alt = d[i][k]+ d[k][j];
            if (alt < d[i][j]) d[i][j] = 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<stdio.h>
#define INF 999
int route[100][100];
int node[10];
int route_num;

int main()
{
	while(1)
	{
		scanf("%d",&route_num);
		if(route_num==0)
			break;

		int min_cost=INF;
		int node_num=0;
		for(int i=0;i<100;i++)
			for(int j=0;j<100;j++)
				route[i][j]=INF;

		for(int i=0;i<route_num;i++)
		{
			int from,to,cost;
			scanf("%d%d%d",&from,&to,&cost);
			route[from][to] = route[to][from] = cost;
			if(node_num < to)
				node_num=to;
			if(node_num < from)
				node_num=from;
		}

		for(int x=0;x<=node_num;x++)
		{
			for(int i=0;i<=node_num;i++)
				node[i]=INF;
			node[x]=0;

			while(1)
			{
				bool flag=false;
				for(int i=0;i<=node_num;i++)
				{
					for(int j=0;j<=node_num;j++)
					{
						if(node[i]!=INF && route[i][j]!=INF && node[j] > node[i]+route[i][j])
						{
							node[j]=node[i]+route[i][j];
							flag=true;
						}
					}
				}
				if(!flag)
					break;
			}
			int temp=0;
			for(int i=0;i<=node_num;i++)
				temp+=node[i];
			if(min_cost > temp)
				min_cost=temp;
		}
		printf("%d\n",min_cost);
	}
}

C++: #include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int n;
typedef pair<int, int> P; //<to, cost>
vector<P> node[10];
queue<P> que;

int dijkstra(int s, int city);

int main(){
  while(cin >> n, n){
    int city = -1;
    for(int i = 0; i < 10; i++) node[i].clear();
    for(int i = 0; i < n; i++){
      int a, b, c;
      cin >> a >> b >> c;
      node[a].push_back(P(b, c));
      node[b].push_back(P(a, c));
      city = max(city, a);
      city = max(city, b);
    }
    P mini = P(-1, INT_MAX);
    for(int i = 0; i <= city; i++){
      int x = dijkstra(i, city);
      if(mini.s > x){
	mini.f = i;
	mini.s = x;
      }
    }

    cout << mini.f << " " << mini.s << endl;
  }
}

int dijkstra(int s, int city){
  int allcost = 0;
  for(int i = 0; i <= city; i++){
    que.push(P(s, 0));
    int mincost = INT_MAX;
    bool moved[10][10] = {{false}};
    while(!que.empty()){
      P now = que.front(); que.pop();
      if(i == now.f) mincost = min(mincost, now.s);
      else{
	for(int j = 0; j < node[now.f].size(); j++){
	  P next = node[now.f][j];
	  if(!moved[now.f][next.f]){
	    moved[now.f][next.f] = true;
	    next.s += now.s;
	    que.push(next);
	  }
	}
      }
    }
    allcost += mincost;
  }
  return allcost;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n,a,b,c,dp[111][111],eki,an[3],ans[3];
	while (1) {
		eki = 0;
		cin >> n;
		if (n == 0) {
			goto a;
		}
		for (int i = 0; i <= 11; i++) {
			for (int z = 0; z <= 11; z++) {
				dp[i][z] = 9999999;
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> a >> b >> c;
			dp[a][b] = c;
			dp[b][a] = c;
			eki = max(eki, max(a, b));
		}
		for (int i = 0; i <= eki; i++) {
			dp[i][i] = 0;
		}
		for (int i = 0; i <= eki; i++) {
			for (int z = 0; z <= eki; z++) {
				for (int m = 0; m <= eki; m++) {
					dp[i][z] = min(dp[i][z], dp[i][m] + dp[m][z]);
				}
			}
		}
		ans[2] = 0;
		an[2] = 9999999;
		for (int i = 0; i <= eki; i++) {
			ans[2] = 0;
			for (int z = 0; z <= eki; z++) {
				ans[2] += dp[i][z];
			}
			if (an[2] >= ans[2]) {
				an[2] = ans[2];
				an[1] = i;
			}
		}
		cout << an[1] << " " << an[2] << endl;
	}
a:;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>

using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;

//int main() {
//	int n,c,v;
//	array<array<pii, 50>, 50> graph = {};
//	scanf("%d %d %d", &n, &c, &v);
//	vector<pii> roads(v, {0,0});
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		roads[i].first = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		roads[i].second = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		graph[roads[i].first][roads[i].second].first = s;
//	}
//	for (int i = 0; v > i; i++) {
//		int s;
//		scanf("%d", &s);
//		graph[roads[i].first][roads[i].second].second = s;
//	}
//
//	array<int> 
//
//	return 0;
//}

int main() {
	int n;
	while (scanf("%d", &n)) {
		if (!n)
			return 0;
		array<array<int, 1>, 1> graph = {};
		int m = 0;
		for (int i = 0; n > i; i++) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);

			graph[a][b] = c;
			graph[b][a] = c;
			m = max({a,b,m});
		}
		m++;
		pii Min = { INT_MAX,INT_MAX };
		for (int i = 0; m > i; i++) {
			priority_queue<pii, vector<pii>, greater<pii>> que;
			vector<int> al(m, -1);
			for (int j = 0; m > j; j++) {
				if (graph[i][j]) {
					que.push({ graph[i][j], j });
				}
			}
			al[i] = 0;
			while (!que.empty()) {
				pii num = que.top();
				que.pop();
				if (al[num.second] != -1)
					continue;
				al[num.second] = num.first;
				for (int j = 0; m > j; j++) {
					if (graph[num.second][j] && al[j] == -1) {
						que.push({ num.first + graph[num.second][j], j });
					}
				}
			}
			Min = min(Min, { accumulate(al.begin(), al.end(),0),i });
		}
		printf("%d %d\n", Min.second, Min.first);
	}
	return 0;
}