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 <limits.h>
using namespace std;
int dp[10][10];
int main() {
	int n ;
	while(1){
		cin >> n ; if(!n) break;
		for(int i=0;i<10;i++) for(int j=0;j<10;j++) dp[i][j]=INT_MAX;
		for(int i=0;i<10;i++) dp[i][i]=0;
		int V=0;
		for(int i=0;i<n;i++){
			int a,b,c; cin >> a >> b >> c ;
			V=max(V,max(a,b));
			dp[a][b]=dp[b][a]=c;
		}
		for(int i=0;i<=V;i++){
			for(int j=0;j<=V;j++){
				for(int k=0;k<=V;k++){
					if(dp[k][j]==INT_MAX || dp[i][k]==INT_MAX) continue;
					dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
				}
			}
		}
		int NUM=0, MIN=INT_MAX;
		for(int i=0;i<=V;i++){
			int sum=0;
			for(int j=0;j<=V;j++) sum+=dp[i][j];
			if(sum<MIN) MIN=sum,NUM=i;
		}
		cout << NUM << ' ' << MIN << '\n' ;
	}
}

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

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] = {0};
            for(int k = 0; k <= max_v; k++) {
                d[k] = INF;
            }
            priority_queue<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] = min(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;
            }
        }

        cout << min_i << " " << dps[min_i] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, a, b, c, dp[111][111], eki, an[3], ans;
	while (1) {
		eki = 0;
		cin >> n;
		if (n == 0) {
			goto a;
		}
		for (int i = 0; i <= 88; i++) {
			for (int z = 0; z <= 88; z++) {
				dp[i][z] = 9999999;
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> a >> b >> c;
			dp[a][b] = c;
			dp[b][a] = c;
			eki = max(eki, max(a, b));
		}
		for (int i = 0; i <= eki; i++) {
			dp[i][i] = 0;
		}
		for (int i = 0; i <= eki; i++) {
			for (int z = 0; z <= eki; z++) {
				for (int m = 0; m <= eki; m++) {
					dp[i][z] = min(dp[i][z], dp[i][m] + dp[m][z]);
				}
			}
		}
		ans = 0;
		an[2] = 9999999;
		for (int i = 0; i <= eki; i++) {
			ans = 0;
			for (int z = 0; z <= eki; z++) {
				if (i == z) {

				}
				else {
					ans += dp[i][z];
				}
			}
			if (an[2] >= ans) {
				an[2] = ans;
				an[1] = i;
			}
		}
		cout << an[1] << " " << an[2] << endl;
	}
a:;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, a, b, c, dp[111][111], eki, an[3], ans;
	while (1) {
		eki = 0;
		cin >> n;
		if (n == 0) {
			goto a;
		}
		for (int i = 0; i <= 88; i++) {
			for (int z = 0; z <= 88; z++) {
				dp[i][z] = 9999999;
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> a >> b >> c;
			dp[a][b] = c;
			dp[b][a] = c;
			eki = max(eki, max(a, b));
		}
		for (int i = 0; i <= eki; i++) {
			dp[i][i] = 0;
		}
		for (int i = 0; i <= eki; i++) {
			for (int z = 0; z <= eki; z++) {
				for (int m = 0; m <= eki; m++) {
					dp[i][z] = min(dp[i][z], dp[i][m] + dp[m][z]);
				}
			}
		}
		ans = 0;
		an[2] = 9999999;
		for (int i = 0; i <= eki; i++) {
			ans = 0;
			for (int z = 0; z <= eki; z++) {
				if (i == z) {

				}
				else {
					ans += dp[i][z];
				}
			}
			if (an[2] >= ans) {
				an[2] = ans;
				an[1] = i;
			}
		}
		cout << an[1] << " " << an[2] << endl;
	}
a:;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 100000000;
const int MAX_N = 10;
int main() {
	int n;
	while (cin >> n,n) {
		int dis[MAX_N + 1][MAX_N + 1];
		int V = 0, s[11] = { 0 };
		for (int i = 0; i < MAX_N + 1; i++) {
			for (int j = 0; j < MAX_N + 1; j++) {
				if (i == j) dis[i][j] = 0;
				else dis[i][j] = INF;
			}
		}
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			dis[a][b] = c;
			dis[b][a] = c;
			V = max(V, max(a, b));
		}
		for (int k = 0; k <= V; k++) {
			for (int i = 0; i <= V; i++) {
				for (int j = 0; j <= V; j++) {
					dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
				}
			}
		}
		int x = INF;
		for (int i = 0; i <=V; i++) {
			int sum = 0;
			for (int j = 0; j <=V; j++) {
				sum += dis[i][j];
			}
			s[i] = sum;
			x = min(x, sum);
		}
		for (int i = 0; i <= V; i++) {
			if (s[i] == x) {
				cout << i << " " << x << endl;
				break;
			}
		}
	}
}