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>
#include <algorithm>

using namespace std;
const int INF = 100000;

int main()
{

	int data[11][11];
	int n;
	int a, s, d;
	int ans=9595, anssum;
	int sum = 0;
	int number;

	while (true)
	{

		for (int i = 0; i<11; i++)
		{
			for (int k = 0; k<11; k++)
			{
				data[i][k] = (i==k) ? 0 : INF;
				
			}
		}

		cin >> n;

		if (n == 0)return 0;

		for (int i = 0; i< n; ++i)
		{
			cin >> a >> s >> d;
			data[a][s] = d;
			data[s][a] = d;
			number = max(max (a, s), number);
		}

		for (int i = 0; i<number; i++)
		{
			for (int k = 0; k<number; k++)
			{
				for (int m = 0; m<number; m++)
				{
					data[k][m] = min(data[k][m], data[k][i] + data[i][m]);
					
				}
				
			}
			
		}
	
		anssum = INF;
		for (int i = 0; i<number; ++i)
		{
			sum = 0;
			for (int k = 0; k < number; ++k)
			{
				sum += data[i][k];
			}
			cout << sum << endl;
			if (sum < anssum)
			{
				ans = i;
				anssum = sum;
			}
		}
		cout << ans << " " << anssum << "\n";
	}

}

C++: //51
#include<iostream>
#include<numeric>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int d[10][10];
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	d[i][j]=(i==j)?0:1<<29;
      }
    }
    int tn=0;
    while(n--){
      int a,b,c;
      cin>>a>>b>>c;
      tn=max(tn,max(a,b));
      d[a][b]=d[b][a]=c;
    }
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	for(int k=0;k<10;k++){
	  d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
	}
      }
    }
    int m=1<<30;
    int t;
    for(int i=0;i<tn+1;i++){
      int s=accumulate(d[i],d[i]+tn+1,0);
      if(s<m){
	m=s;
	t=i;
      }
    }
    cout<<t<<' '<<m<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<utility>
#include<numeric>
#include<iterator>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cassert>
using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
#define FOR(i,init,len) for(int i=(init);i<(len);++i)
#define For(i,init,len) for(int i=(init);i<=(len);++i)
#define fi first
#define se second
#define pb push_back
#define is insert
namespace IO {
	inline char getchar() {
		static const int BUFSIZE=5201314;
		static char buf[BUFSIZE],*begin,*end;
		if(begin==end) {
			begin=buf;
			end=buf+fread(buf,1,BUFSIZE,stdin);
			if(begin==end) return -1;
		}
		return *begin++;
	}
}
inline void read(int &in) {
	int c,symbol=1;
	while(isspace(c=IO::getchar()));
	if(c=='-') { in=0;symbol=-1; }
	else in=c-'0';
	while(isdigit(c=IO::getchar())) { in*=10;in+=c-'0'; }
	in*=symbol;
}
inline int read() { static int x;read(x);return x; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
#define PA(name,init,len) cout<<#name"["<<(len-init)<<"]=";FOR(_,init,len) cout<<name[_]<<" \n"[_==(len-1)];
#define Pa(name,init,len) cout<<#name"["<<(len-init+1)<<"]=";For(_,init,len) cout<<name[_]<<" \n"[_==(len)];
#define PV(name) cout<<#name"="<<name<<'\n';

int n;
const int maxn=15;
const int INF=1e9;
int d[maxn][maxn];

int main() {

    while(scanf("%d",&n)==1&&n){
        For(i,0,9) For(j,0,9) d[i][j]=INF;
        For(i,0,9) d[i][i]=0;
        int ma=0;
        FOR(i,0,n){int a,b,c;scanf("%d%d%d",&a,&b,&c);d[a][b]=d[b][a]=c;ma=std::max(ma,std::max(a,b));}
        For(k,0,ma) For(i,0,ma) For(j,0,ma) d[i][j]=std::min(d[i][j],d[i][k]+d[k][j]);
        int idx=0,ans=INF;
        For(i,0,ma){
            int t=0;
            For(j,0,ma) t+=d[i][j];
            if(t<ans) {idx=i;ans=t;}
        } 
        printf("%d %d\n",idx,ans);
    }

	return 0;
}

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

using namespace std;

// BEGIN_LIBRARY ///////////////////
#define MAX_V (100)
#define INF (999999)

namespace NLibrary{
	class Dijkstra {
	private:
		int cost[MAX_V][MAX_V];
		int d[MAX_V];
		bool used[MAX_V];
		int V;
	public:
		Dijkstra() {
			for (int i = 0; i < MAX_V; i++) {
				fill(cost[i], cost[i] + MAX_V, INF);
			}
		}

		void setV(int V) {
			this->V = V;
		}

		void setCost(int a, int b, int c, bool bidirect = false) {
			this->cost[a][b] = c;
			if (bidirect) {
				this->cost[b][a] = c;
			}
		}

		void calc(int s) {
			// s??????????????????????????¢????±???????
			fill(d, d + MAX_V, INF);
			fill(used, used + MAX_V, false);
			d[s] = 0;
			while (true) {
				int v = -1;
				for (int u = 0; u < V; u++) {
					if (!used[u] && (v == -1 || d[u] < d[v])) {
						v = u;
					}
				}

				if (v == -1) break;
				used[v] = true;
				for (int u = 0; u < V; u++) {
					d[u] = min(d[u], d[v] + cost[v][u]);
				}
			}
		}

		int getL(int a) {
			return d[a];
		}
	};

}

// END_LIBRARY ////////////////////

int main() {
	NLibrary::Dijkstra dijkstra;
	int n;
	int as[100];
	int bs[100];
	int cs[100];
	while (cin >> n, n != 0) {
		int V = -1;
		for (int i = 0; i < n; i++) {
			cin >> as[i] >> bs[i] >> cs[i];
			V = max(V, max(as[i], bs[i]));
		}
		V++;
		dijkstra.setV(V);
		for (int i = 0; i < n; i++) {
			dijkstra.setCost(as[i], bs[i], cs[i], true);
		}
		int m = INF, town = -1;
		for (int i = 0; i < V; i++) {
			int sum = 0;
			dijkstra.calc(i);
			for (int j = 0; j < V; j++) {
				sum += dijkstra.getL(j);
			}

			if (sum < m) {
				town = i;
				m = sum;
			}
		}
		cout << town << " " << m << endl;
	}
	return 0;
}