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 <cstdio>
using namespace std;

const int INF = 1<<30;
const int MAX_V = 10;
const int MAX_E = 45;

int d[MAX_V][MAX_V];
int n;
int V;

void show_d() {
    cout << "===" << endl;
    for(int i = 0; i < V; i++) {
        for(int j = 0; j < V; j++) {
            printf("%3d ", d[i][j]);
        }
        cout << endl;
    }
}

void warshall_floyd() {
    for(int k = 0; k < V; k++) {
        for(int i = 0; i < V; i++) {
            for(int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
        // show_d(); // debug
    }
}

int main() {
    while(true) {
        cin >> n;
        if(!n) break;
        int f, t, c;
        V = 0;
        for(int i = 0; i < MAX_V; i++) {
            for(int j = 0; j < MAX_V; j++) {
                d[i][j] = INF;
                if(i == j) d[i][j] = 0;
            }
        }
        for(int i = 0; i < n; i++) {
            cin >> f >> t >> c;
            d[f][t] = c;
            d[t][f] = c;
            V = max(V, f+1);
            V = max(V, t+1);
        }

        warshall_floyd();

        int ix = 0, s = INF;
        for(int i = 0; i < V; i++) {
            int tmp = 0;
            for(int j = 0; j < V; j++) {
                tmp += d[i][j];
            }
            if(tmp < s) {
                ix = i;
                s = tmp;
            }
        }

        cout << ix << " " << s << endl;

    }
    return 0;
}

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

#define inf 1000000000

using namespace std;

int main(){
	while(1){
		int n;
		int in1[100];
		int in2[100];
		int in3[100];
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>in1[i]>>in2[i]>>in3[i];
		}
		int maxi=0;
		for(int i=0;i<n;i++){
			maxi=max(maxi,in1[i]);
			maxi=max(maxi,in2[i]);
		}
		
		printf("%d\n",maxi);
		
		int m=maxi+1;
		
		int C[100][100];
		for(int i=0;i<100;i++){
			for(int j=0;j<100;j++){
				C[i][j]=inf;
			}
		}
		for(int i=0;i<n;i++){
			C[in2[i]][in1[i]]=C[in1[i]][in2[i]]=in3[i];
		}
		
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					C[i][j]=min(C[i][j],C[i][k]+C[k][j]);
				}
			}
		}
		
		
		int maxo;
		int maxn=inf;
		int ans[100];
		for(int i=0;i<m;i++){
			ans[i]=0;
			for(int j=0;j<m;j++){
				ans[i]+=C[i][j];
			}
			ans[i]-=C[i][i];
			if(maxn>ans[i]){
				maxn=ans[i];
				maxo=i;
			}
		}
		
		printf("%d %d\n",maxo,maxn);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
#define REP(i, n) for (int i = 0; i < n; i++)


int main() {
    ll n, d[15][15];
    while(cin >> n, n){
        REP(i,15)fill(d[i],d[i]+15,IINF);
        REP(i,n){
            ll a, b, c;
            cin >> a >> b >> c;
            d[a][b] = c;
            d[b][a] = c;
        }
        REP(i,10) d[i][i] = 0;
        REP(k,10)REP(i,10)REP(j,10){
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
        ll dmin=IINF, id;
        REP(i,10){
            ll sum = 0;
            REP(j,10){
                if(d[i][j]!=IINF)
                    sum += d[i][j];
            }
            if(sum != 0 && sum < dmin){
                id = i;
                dmin = sum;
            }
        }
        cout << id << " " << dmin << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }

    replace(dist.begin(), dist.end(), INT_MAX, -1);
}

void shortestPath(const vector<vector<Edge> >& edges, vector<vector<int> >& dist)
{
    dist.resize(edges.size());
    for(unsigned i=0; i<edges.size(); ++i)
        shortestPath(edges, i, dist[i]);
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int m = 0;
        map<int, int> index;
        vector<int> num;

        vector<vector<Edge> > edges;
        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            if(index.find(a) != index.end())
                a = index[a];
            else{
                index.insert(make_pair(a, m));
                num.push_back(a);
                a = m;
                ++ m;
                edges.resize(m);
            }
            if(index.find(b) != index.end())
                b = index[b];
            else{
                index.insert(make_pair(b, m));
                num.push_back(b);
                b = m;
                ++ m;
                edges.resize(m);
            }

            edges[a].push_back(Edge(b, c));
            edges[b].push_back(Edge(a, c));
        }

        vector<vector<int> > dist;
        shortestPath(edges, dist);

        int k;
        int sum = INT_MAX;
        for(int i=0; i<m; ++i){
            int tmp = accumulate(dist[i].begin(), dist[i].end(), 0);
            if(tmp < sum){
                sum = tmp;
                k = i;
            }
        }
        cout << num[k] << ' ' << sum << endl;
    }
}