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>
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 count1[10];
		for(int k=0;k<m;k++){
			int count=0;
			for(int i=0;i<m;i++){
				count=T[k][i]+count;
			}
			count1[k]=count;
		}
		int count2=count1[0];
		for(int k=0;k<m;k++){
			if(count1[k]<count2)
				count2=count1[k];
		}
		for(int k=0;k<m;k++){
			if(count1[k]==count2){
				cout<<k<<" "<<count2<<endl;
				break;
			}
		}

	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<bits//stdc++.h>
#include<functional>
using namespace std;
struct P{
	int cost,pos;
};
struct B{
	int cost,to;
};
bool operator<(P a,P b){
	return a.cost<b.cost;
}
bool operator>(P a,P b){
	return a.cost>b.cost;
}
vector<B>e[10];
int main() {
	int n;
	while(cin>>n&&n!=0){
		int a,b,c,ma=0;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			e[a].push_back(B{c,b});
			e[b].push_back(B{c,a});
			ma=max(a,max(b,ma));
		}
		P sum;
		sum.cost=1000000;
		for(int i=0;i<=ma;i++){
			priority_queue<P, vector<P>, greater<P>>p;
			int b[10];
			for(int j=0;j<10;j++) b[j]=1000000;
			b[i]=0;
			p.push(P{0,i});
			while(!p.empty()){
				P t=p.top();p.pop();
				for(int j=0;j<(int)e[t.pos].size();j++){
					if(b[t.pos]+e[t.pos][j].cost<b[e[t.pos][j].to]){
						b[e[t.pos][j].to]=b[t.pos]+e[t.pos][j].cost;
						p.push(P{b[e[t.pos][j].to],e[t.pos][j].to});
					}
				}
			}
			int sum2=0;
			for(int j=0;j<=ma;j++){
				sum2+=b[j];
			}
			if(sum.cost>sum2){
				sum.cost=sum2;
				sum.pos=i;
			}
		}
		cout<<sum.pos<<" "<<sum.cost<<endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int N;
    const int INF = 1e9;
    while(cin >> N, N){
        vector<vector<int>> Graph(10,vector<int>(10,INF));

        for(int i=0;i<N;i++){
            int a,b,c;
            cin >> a >> b >> c;
            Graph[a][b] = c;
            Graph[b][a] = c;
        }

        for(int mid = 0; mid < 10; mid++){
            for(int from = 0; from < 10; from++){
                for(int to = 0; to < 10; to++){
                    if(Graph[from][mid] == INF || Graph[mid][to] == INF) continue;
                    Graph[from][to] = min(Graph[from][to], Graph[from][mid] + Graph[mid][to]);
                }
            }
        }

        int V = -1;
        int minCost = INF;

        for(int i=0;i<10;i++){
            int cost = 0;
            for(int j = 0;j<10;j++){
                if(i == j) continue;
                if(Graph[i][j] == INF) continue;
                cost += Graph[i][j];
            }
            cout << cost << endl;
            if(minCost > cost && cost != 0){
                minCost = cost;
                V = i;
            }
        }
        cout << V << " " << minCost << endl;
    }
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define INF 100000000
int d[11][11];
int min(int a,int b){
	if(a<b){
		return a;
	}else{
		return b;
	}
}
void warsall_floyd(){
	for(int i=0;i<11;i++){
		for(int j=0;j<11;j++){
			for(int k=0;k<11;k++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}	
		}
	}
	return;
}
int main(){
	while(1){
		int n,a,b,c,ans;
		ans=INF;
		for(int i=0;i<11;i++){
			for(int j=0;j<11;j++){
				d[i][j]=INF;
			}
			d[i][i]=0;
		}
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			d[a][b]=c;d[b][a]=c;
		}
		warsall_floyd();
		b=INF;
		for(int i=0;i<11;i++){
			a=0;
			for(int j=0;j<11;j++){
				if(d[i][j]<INF)a+=d[i][j];
			}
			if(a<ans&&a!=0){
				ans=a;b=i;
			}
		}
		cout<<b<<" "<<ans<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#define INF 1000000
typedef long long int lli;
using namespace std;

struct edge{int from,to,cost;};
int shortest_path(int s,int V,int E,vector<int> d,vector<edge> es){
	int result=0;
	for(int i=0; i<V; ++i) d[i]=INF;
	d[s]=0;
	while(true){
		bool update = false;
		for(int i=0; i<E; ++i){
			edge e=es[i];
			if(d[e.to]!=INF&&d[e.from]>d[e.to]+e.cost){
				d[e.from]=d[e.to]+e.cost;
				update=true;
			}
			if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
		}
		if(!update) break;
	}
	for(int i=0; i<V; ++i){
		result+=d[i];
	}
	return result;
}

int main(){
	int n;
	while(cin>>n&&n){
		vector<edge> es(n);
		int m=0;
		for(int i=0; i<n; ++i){
			int a,b,c;
			cin >> a >> b >> c;
			m=max(a,max(b,m));
			es[i].from=a;
			es[i].to=b;
			es[i].cost=c;
		}
		vector<int> d(m+1);
		int ans_d=INF;
		int ans_s;
		for(int i=m; i>=0; --i){
			int tmp=shortest_path(i,m+1,n,d,es);
			//cout << tmp << "\n";
			if(ans_d>tmp){
				ans_d=tmp;
				ans_s=i;
			}
		}
		cout << ans_s << " " << ans_d << "\n";
	}
	return 0;
}