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 <cstdio>
#include <iomanip>
#include <cstring>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;

int N;
#define MV 10
#define INF 0x7F7F7F7F
int G[MV][MV];
bool input() {
    scanf("%d", &N);
    if (N == 0) return false;
    memset(G, 0x7F, sizeof(G));
    for (int i = 0; i < N; i++) {
        int a, b, c; scanf("%d %d %d", &a, &b, &c);
        G[a][b] = G[b][a] = c;
        G[a][a] = 0;
        G[b][b] = 0;
    }
    return true;
}

void solve() {
    for (int k = 0; k < MV; k++) {
        for (int i = 0; i < MV; i++) {
            for (int j = 0; j < MV; j++) {
                if (G[i][k] == INF || G[k][j] == INF) continue;
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
#ifdef DEBUG
    for (int i = 0; i < MV; i++) {
        for (int j = 0; j < MV; j++) {
            if (G[i][j] == INF) {
                cout << setw(5) << "x";
            } else {
                cout << setw(5) << G[i][j];
            }
        }
        cout << endl;
    }
#endif
    int index = 0, min1 = INF; 
    for (int i = 0; i < MV; i++) {
        bool NOSUCHTOWN = true;
        for (int j = 0; j < MV; j++) {
            if (G[i][j] != INF) {
                NOSUCHTOWN = false;
                break;
            }
        }
        if (NOSUCHTOWN) break;
        int total = 0;
        for (int j = 0; j < MV; j++) {
            if (G[i][j] == INF) break;
            total += G[i][j];
        }
        if (total < min1) {
            index = i;
            min1 = total;
        }
    }
    printf("%d %d\n", index, min1);
}

int main() {
    while (input()) {
        solve();
    }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

typedef struct edge {
	int from;
	int to;
	int time;
} edge;


int main(){
	int n;


	while (cin >> n && n != 0) {
		int min_ = 1000000000;
		int min_num = 1;
		vector<edge> town;
		int cost[100][100];
		int max_ = 0;

		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				cost[i][j] = 100000000;
			}
		}
		for (int i = 0; i < 100; i++) {
			cost[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			edge tmp;
			cin >> tmp.from >> tmp.to >> tmp.time;
			cost[tmp.from][tmp.to] = tmp.time;
			cost[tmp.to][tmp.from] = tmp.time;
			max_ = max(max(tmp.from, tmp.to), max_);
		}
		max_++;
		for (int i = 0; i < max_; i++) {
			for (int j = 0; j < max_; j++) {
				for (int k = 0; k < max_; k++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		for (int i = 0; i < max_; i++) {
			int total = 0;
			for (int j = 0; j < max_; j++) {
				total += cost[i][j];
			}
			if (total < min_) {
				min_ = total;
				min_num = i;
			}
		}
		cout << min_num << " " << min_ << endl;
  }
	return 0;
}

C++: #include <iostream>
using namespace std;

const int INF = 1<<20;
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 <cstdio>
using namespace std;

int main(void)
{
	int n, a, b, c;
	int data[10][10];
	
	while (scanf("%d", &n), n){
		int N = 0;
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				if (i == j) data[i][j] = 0;
				else data[i][j] = 10000000;
			}
		}
		for (int i = 0; i < n; i++){
			scanf("%d %d %d", &a, &b, &c);
			data[a][b] = data[b][a] = c;
			N = max(N, max(a, b));
		}
		
		// WF
		for (int k = 0; k < 10; k++){
			for (int i = 0; i < 10; i++){
				for (int j = 0; j < 10; j++){
					data[i][j] = min(data[i][j], data[i][k] + data[k][j]);
				}
			}
		}
		
		/*
		for (int i = 0; i <= N; i++){
			cout << i << " : ";
			for (int j = 0; j <= N; j++){
				cout << data[i][j] << " ";
			}
			puts("");
		}
		*/
		
		// i が答えだと仮定して全部計算
		int ret = 10000000, ret_num = 10000000, sum;
		for (int i = 0; i <= N; i++){
			sum = 0;
			for (int j = 0; j <= N; j++){
				sum += data[i][j];
			}
			// cout << sum << endl;
			if (sum < ret_num){
				ret_num = sum;
				ret = i;
			}
		}
		
		cout << ret << " " << ret_num << endl;
	}
	
	return 0;
}