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 <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define MAXN 15
#define INF 1000000000
int K[MAXN][MAXN];
int n;

int main(void) {
    while (1) {
        cin >> n;
        int num = 0;
        if (n == 0) break;
        for (int i = 0; i < MAXN; i++)
            for (int j = 0; j < MAXN; j++)
                K[i][j] = INF;
        for (int i = 0; i < MAXN; i++) K[i][i] = 0;
        for (int i = 0; i < n; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            num = max(num, max(a, b));
            K[a][b] = K[b][a] = c;
        }
        for (int k = 0; k <= num; k++) {
            for (int i = 0; i <= num; i++) {
                for (int j = 0; j <= num; j++) {
                    if (K[i][j] > K[i][k] + K[k][j]) {
                        K[i][j] = K[i][k] + K[k][j];
                    }
                }
            }
        }
//        for (int i = 0; i <= num; i++) {
//            for (int j = 0; j <= num; j++) {
//                cout << K[i][j] << " ";
//            }
//            cout << endl;
//        }
        int ans = INF, index = 0; 
        for (int i = 0; i <= num; i++) {
            int all = 0;
            for (int j = 0; j <= num; j++) {
                all += K[i][j];
            }
            if (all < ans) {
                index = i;
                ans = all;
            }
        }
        cout << index << " " << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#define INF 10000
using namespace std;

struct edge {
    int from, to, cost;
};

edge es[100];
int d[11];
int n,maxV=0;

int shortest_path(int s){
    int sum=0;
    for(int i=0;i<maxV+1;i++){
        d[i] = INF;
    }
    d[s] = 0;
    while(1){
        bool update = false;
        for(int i=0;i<2*n;i++){
            edge e = es[i];
            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<maxV+1;i++){
        if(d[i] != INF){
        	// cout << i << " " << d[i] << endl;
            sum += d[i];
        }
    }
    return sum;
}

int main(void){
    
    while(cin >> n && n){
    	maxV = 0;
        int a, b, c, tmp, min,sum2=100000;
        for(int i=0;i<n;i++){
            cin >> a >> b >> c;
            es[i].from = a;
            es[i].to = b;
            es[i].cost = c;

            es[i+n].from = b;
            es[i+n].to = a;
            es[i+n].cost = c;
            
            if(maxV < b){
           		maxV = b;
           	}
           	if(maxV < a){
           		maxV = a;
           	}
           	
        }
        //??????????????°?????????
        for(int i=0;i<maxV+1;i++){
            int tmp = shortest_path(i);
            // cout << tmp << endl;
            if(sum2 > tmp){
                sum2 = tmp;
                min = i;
            }
        }
        cout << min << " " << sum2 << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<climits>
#define inf INT_MAX
using namespace std;
unsigned long long d[10][10],sum[10];
int v;

int main()
{
	int n;
	while(cin>>n,n)
	{
		memset(d,0,sizeof(d));
		memset(sum,0,sizeof(sum));
		set<int> ss;
		for(int i=0;i<n;i++)
		{
			int s,t,c;
			cin>>s>>t>>c;
			ss.insert(s);
			ss.insert(t);
			d[s][t]=d[t][s]=c;
		}
		v=ss.size();
		for(int i=0;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				if(d[i][j]==0&&i!=j) d[i][j]=inf;
			}
		}

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

		int ans;
		for(int i=0;i<v;i++)
		{
			for(int j=0;j<v;j++)
			{
				sum[i]+=d[i][j];
			}
		}
		ans=min_element(sum,sum+v)-sum;
		cout<<ans<<" "<<sum[ans]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;
const int MAX_E = 45;
const int MAX_V = 10;
const int INF = 1024 * 1024 * 1024;
struct edge {int to, cost; };
vector<edge> G[MAX_V];
vector<string> result;

int main() {
    int n;
    while(1) {
        cin >> n;
        if (n == 0) break;
        int max_v = -1;
        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            edge e, e1;
            e.to = to;
            e.cost = cost;
            G[from].push_back(e);
            e1.to = from;
            e1.cost = cost;
            G[to].push_back(e1);
            max_v = max(max(max_v, from), to);
        }

        int dps[max_v + 1];
        for(int i = 0; i <= max_v; i++) {
            int d[max_v + 1] = {0};
            for(int k = 0; k <= max_v; k++) {
                d[k] = INF;
            }
            priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
            d[i] = 0;
            que.push(pair<int, int>(0, i));
            while(!que.empty()) {
                pair<int, int> p = que.top();
                que.pop();
                if(p.first > d[p.second]) continue;
                for(int j = 0; j < G[p.second].size(); j++) {
                    edge e1 = G[p.second][j];
                    if(d[e1.to] > d[p.second] + e1.cost) {
                        d[e1.to] = d[p.second] + e1.cost;
                        que.push(pair<int, int>(d[e1.to], e1.to));
                    }
                }
            }


            int sum = 0;
            for(int j = 0; j <= max_v; j++) {
                sum += d[j];
            }

            dps[i] = sum;
        }

        int min_i = 0;
        for(int i = 1; i <= max_v; i++) {
            if(dps[min_i] > dps[i]) {
                min_i = i;
            }
        }

        result.push_back(to_string(min_i) + " " + to_string(dps[min_i]));
    }

    for(int i = 0; i < result.size(); i++) {
        cout << result[i] << endl;
    }
    return 0;
}