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<cstdio>
#include<iostream>

using namespace std;
#define INF 100000

int  road, max_t = 0, time_[100][100] = { 0 }, sum, root[100] = { 0 };

void dijkstra(int a) {

	int i,j,k=INF,used[100],minroot;
	for (i = 0; i <= max_t; i++) {
		used[i] = 0;
		root[i] = INF;
	}
	root[a] = 0;
	while (1) {
		minroot = INF;
		for (i = 0; i <= max_t; 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_t; i++) {
			if (root[i] > root[j] + time_[j][i]) {
				root[i] = root[j] + time_[j][i];
			}

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

	return ;
}






int main() {
	while (1) {
		cin >> road;
		if (road == 0) return 0;
		int i, j, a=0, b=0, c=0, save_a[450] = { 0 }, save_b[450] = { 0 }, save_c[450] = { 0 }, min_sum = INF, ans_town=0;
		max_t = 0;
		for (i = 1; i <= road; i++) {
			cin >> a >> b >> c;
			if (max_t < a) max_t = a;
			if (max_t < b) max_t = b;
			save_a[i] = a;
			save_b[i] = b;
			save_c[i] = c;
		}
		for (i = 0; i <= max_t; i++) {
			for (j = 0; j <= max_t; 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_t; i++) {
			dijkstra(i);
			if (sum < min_sum) {
				ans_town = i;
				min_sum = sum;
			}
		}
		cout << ans_town << " " << min_sum << endl;

	}
}

C++: // 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		// ???????????°

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}
		
		for(int k = 0; k < m; k++){
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					if(T[i][j] > T[i][k] + T[k][j]){
						T[i][j] = T[i][k]+ T[k][j];
					}
				}
			}
		}

		int town = m - 1;
		int value = INF;
		for(int i = m - 1; i >= 0; i--){
			int tempValue = 0;
			for(int j = 0; j < m; j++){
				tempValue += T[i][j];
			}
			if(value > tempValue){
				value = tempValue;
				town = i;
			}
		}
		cout << town << ' ' << value << endl;
	}

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

typedef struct edge {
	int from;
	int to;
	int time;
} edge;


int main(){
	int n;


	while (cin >> n && n != 0) {
		int min_ = 1000000000;
		int min_num = 1;
		vector<edge> town;
		int cost[50][50];
		int max_ = 0;

		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				cost[i][j] = 100000000;
			}
		}
		for (int i = 0; i < 100; i++) {
			cost[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			edge tmp;
			cin >> tmp.from >> tmp.to >> tmp.time;
			cost[tmp.from][tmp.to] = tmp.time;
			cost[tmp.to][tmp.from] = tmp.time;
			max_ = max(max(tmp.from, tmp.to), max_);
		}
		max_++;
		for (int i = 0; i < max_; i++) {
			for (int j = 0; j < max_; j++) {
				for (int k = 0; k < max_; k++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		for (int i = 0; i < max_; i++) {
			int total = 0;
			for (int j = 0; j < max_; j++) {
				total += cost[i][j];
			}
			if (total < min_) {
				min_ = total;
				min_num = i;
			}
		}
		cout << min_num << " " << min_ << 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 to;
	int cost;
	edge_def(int _to, int _cost) {to = _to; cost = _cost;}
} edge;

typedef pair<int, int> P;

int V, E;
const int MAX_V = 10;
vector<edge> G[MAX_V];	//[i] : fromを表す
int d[MAX_V];

void dijkstra(int s) {
	int i;
	priority_queue<P, vector<P>, greater<P> > q;

	for (i=0; i<V; i++) d[i] = INF;
	d[s] = 0;
	q.push(P(0, s));

	while (q.size()) {
		P p = q.top();
		q.pop();
		int v = p.second;

		if (d[v] < p.first) continue;

		for (i=0; i<(int)G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}

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

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

		V = 0;
		for (i=0; i<E; i++) {
			int ef, et, ec;
			scanf("%d%d%d ", &(ef), &(et), &(ec));
			G[ef].push_back(edge(et, ec));
			G[et].push_back(edge(ef, ec));
			V = max(V, ef);	
			V = max(V, et);	
		}
		V++;

		total = INF;
		minT = INF;
		for (i=0; i<V; i++) {
			dijkstra(i);

			int sum = 0;
			for (j=0; j<V; j++)
				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<algorithm>
#include<queue>
using namespace std;
int cost[12][12];
int n,a,b,c;
int s,min_cost;


int main(){
	
	while(scanf("%d",&n),n!=0){
		memset(cost,255,sizeof(cost));
		for(int i=0;i<n;i++){
			scanf("%d %d %d",&a,&b,&c);
			cost[a][b]= (cost[a][b]==-1) ? c : min(cost[a][b],c);
			cost[b][a]=cost[a][b];
		}
		for(int i=0;i<=10;i++)
			cost[i][i]=0;
		for(int k=0;k<=10;k++)
			for(int i=0;i<=10;i++)
				for(int j=0;j<=10;j++)
					if(cost[i][k]!=-1&&cost[k][j]!=-1){
						cost[i][j]= (cost[i][j]==-1) ? cost[i][k]+cost[k][j] : min(cost[i][j],cost[i][k]+cost[k][j]);
						cost[j][i]=cost[i][j];
					}
		s=-1;min_cost=-1;
		for(int i=0;i<=10;i++){
			int temp=0;
			for(int j=0;j<=10;j++)
				temp= (cost[i][j]==-1) ? temp : temp+cost[i][j];
			if(s==-1||temp<min_cost&&temp>0){
				min_cost=temp;
				s=i;
			}
		}
		printf("%d %d\n",s,min_cost);
	}
	return 0;
}