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 <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>


using namespace std;

#define Max INT_MAX
#define Inf (INT_MAX/2)


#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i,l,n) for(int (i)=(int)(l);(i)<(int)(n);(i)++)
// s <= x < g ?
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
// 0 <= x < w && 0 <= y < h ?
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

typedef pair<int, int> P;


#define MaxN 1000

#define MaxE 1000
//struct edge es[MaxE];




//その時点で考えてる頂点集合の中での
//i->jの最短路
int dp[10][10];

int main()
{
    int E;
    while ( cin >> E ){
        if( E == 0 ) { break; }
        int a,b,c;
        rep(i,10){
            rep(j,10){
                if( i==j ){
                    dp[i][j] = 0;
                } else {
                    dp[i][j] = Inf;
                }
            }
        }

        rep(i,E){
            cin >> a >> b >> c;
            dp[a][b] = c;
            dp[b][a] = c;
        }
        rep(k,10){
            rep(i,10){
                rep(j,10){
                    dp[i][j] = min( dp[i][j], dp[i][k] + dp[k][j] );
                }
            }
        }

        int min = Inf;
        int minI;
        rep(i,10){
            int sum = 0;

            rep(j,10){
                if( dp[i][j] >= Inf ) { continue; }
                else if( i == j){ continue; } 
                else{
                    sum += dp[i][j];
                }
            }

            //cout << "sum " << sum << endl;
            //
            if ( sum < min && sum){
                //cout << "i: " << i << endl;
                //cout << "min: " << min << endl;
                min = sum;
                minI = i;
            }
        }

        cout << minI << " " << min << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 10000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
struct edge{int to,cost;};
int N;
int d[10];
bool f[10];
vector<edge> G[10];
void dijkstra(int s){
      REP(i,N)d[i]=INF;
      d[s]=0;
      priority_queue<P,vector<P>,greater<P> > Q;
      Q.push(P(0,s));
      while(!Q.empty()){
            P p=Q.top();Q.pop();
            int v=p.second;
            if(d[v]>p.first)continue;
            REP(i,G[v].size()){
                  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(){
      while(cin>>N&&N){
            memset(f,false,sizeof(f));
            REP(i,N){
                  int a,b,c;
                  cin>>a>>b>>c;
                  G[a].PB((edge){b,c});
                  G[b].PB((edge){a,c});
                  f[a]=f[b]=true;
            }
            int ans=INF,pos=-1;
            REP(i,N){
                  int sum=0;
                  dijkstra(i);
                  REP(j,10)if(f[j])sum+=d[j];
                  if(ans>sum){
                        ans=sum;
                        pos=i;
                  }
            }
            cout<<pos<<" "<<ans<<endl;
      }
}

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;
			}
		}

    int d[m][m];
    for(int i=0;i<m;i++){
      for(int j=0;j<m;j++){
        d[i][j]=T[i][j];
      }
    }
    for(int k=0;k<m;k++){
      int count=0;
      for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
          if(d[i][j]>d[i][k]+d[k][j]){
            d[i][j]=d[i][k]+d[k][j];
						d[j][i]=d[j][k]+d[k][i];
          }
        }
      }
		}
		int l=0;
		int count=10000000;
		for(int i=0;i<m;i++){
			int a=0;
			for(int j=0;j<m;j++){
				int l=0;
				a+=d[i][j];
			}
			if(a<count){
				count=a;
				l=i;
			}
		}
		cout<<l<<" "<<count<<endl;
	}

	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n;
	while(cin >> n, n) {
		vvi dist(10, vi(10, INF));
		int a, b, c, maxN = 0;
		REP(i, n) {
			cin >> a >> b >> c;
			dist[a][b] = dist[b][a] = c;
			maxN = max(maxN, max(a, b));
		}
		maxN++;
		REP(i, maxN) {
			REP(j, maxN) {
				REP(k, maxN) {
					dist[j][k] = min(dist[j][k], dist[j][i]+dist[i][k]);
				}
			}
		}
		
		int ans = -1, cost = INF;
		REP(i, maxN) {
			int tmp = 0;
			REP(j, maxN) {
				if(i != j) {
					tmp += dist[i][j];
				}
			}
			if(tmp < cost) {
				cost = tmp;
				ans = i;
			}
		}

		cout << ans << " " << cost << endl;
	}
	return 0;
}