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 <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxv = 11;

int d[maxv][maxv];
int V;     //?点数
int x[maxv];     //以x[i]?起点?最短路?之和

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

int main()
{
    int E;
    while(scanf("%d", &E)==1 && E)
    {
        memset(d, 0x3f, sizeof(d));
        for(int i=0; i<maxv; i++)
            d[i][i] = 0;
        V = 0;
        for(int i=0; i<E; i++)
        {
            int u, v, cost;
            scanf("%d%d%d", &u, &v, &cost);
            d[u][v] = cost;
            d[v][u] = cost;
            V = max(V, max(v, u)+1);
        }
        warshall_floyd();
        memset(x, 0, sizeof(x));
        for(int i=0; i<V; i++)
        {
            for(int j=0; j<V; j++)
                x[i] += d[i][j];
        }
        int ans = min_element(x, x + V) - x;
        cout << ans << ' ' << x[ans] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;
ll d[200][200];
int main(){
    int n;
    while(cin>>n && n){
        set<int> app;
        rep(i,200)rep(j,200)d[i][j]=1LL<<60;
        rep(i,200)d[i][i]=0;
        rep(i,n){
            ll a,b,c;
            cin>>a>>b>>c;
            d[a][b]=d[b][a]=c;
            app.insert(a);
            app.insert(b);
        }
        rep(k,200)rep(i,200)rep(j,200)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        int ans=0;
        ll ans_sum=1LL<<60;
        for(int i:app){
            ll sum=0;
            for(int j:app){
                sum+=d[i][j];
            }
            if(ans_sum > sum){
                ans_sum = sum;
                ans = i;
            }
        }

        cout << ans << " " << ans_sum << endl;
    }
}

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_ = INT_MAX;
		int min_num = 1;
		vector<edge> town;
		int cost[50][50];
		int max_ = 0;

		for (int i = 0; i < 50; i++) {
			for (int j = 0; j < 50; j++) {
				cost[i][j] = INT_MAX / 10;
			}
		}
		for (int i = 0; i < 50; 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>
#include <algorithm>
int cost[11][11];
#define INF 10e6

using namespace std;

int main(void){
	int n,a,b,d;
	int cmax;
	int t,rmin,tmin;
	while(cin >> n,n){
		tmin=INF;
		cmax=0;
		for(int i=0;i<11;i++)
				for(int j=0;j<11;j++)
					cost[i][j]=INF;
					
		for(int i=0;i<11;i++)
			cost[i][i]=0;
			
		for(int i=0;i<n;i++){
			cin >> a >> b >> d;
			if(cmax<a)
				cmax=a;
			if(cmax<b)
				cmax=b;
			cost[a][b]=cost[b][a]=d;
		}
		for(int i=0;i<=cmax;i++)
			for(int j=0;j<=cmax;j++)
				for(int k=0;k<=cmax;k++)
					if(cost[i][j]>cost[i][k]+cost[k][j])
						cost[i][j]=cost[i][k]+cost[k][j];
		
		for(int i=0;i<=cmax;i++){
			t=0;
			for(int j=0;j<=cmax;j++)
					t+=cost[i][j];
			if(t<tmin)
				tmin=t,rmin=i;
		}
		cout << rmin << ' ' << tmin << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;

		if(n == 0){
			break;
		}

		int* start = new int[n];
		int* goal = new int[n];
		int* cost = new int[n];

		for(int i = 0; i < n; i++){
			cin >> start[i] >> goal[i] >> cost[i];
		}

		int town;

		for(int i = 0; i < n; i++){
			town = max(start[i], goal[i]);
		}

		town++;

		vector<vector<int> > dist(town, vector<int>(town, INT_MAX / 2));

		for(int i = 0; i < n; i++){
			dist[start[i]][goal[i]] = cost[i];
			dist[goal[i]][start[i]] = cost[i];
		}

		for(int i = 0; i < town; i++){
			dist[i][i] = 0;
		}


		for(int k = 0; k < town; k++){
			for(int i = 0; i < town; i++){
				for(int j = 0; j < town; j++){
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
		int* total = new int[town];
		int TOTAL = INT_MAX / 2;
		int S;

		for(int i = 0; i < town; i++){
			total[i] = 0;
		}

		for(int i = 0; i < town; i++){
			for(int j = 0; j < town; j++){
				total[i] += dist[i][j];
			}
			if(TOTAL > total[i]){
				TOTAL = min(TOTAL, total[i]);
				S = i;
			}
		}

		cout << S << " " << TOTAL << endl;
	}
}

C++: #include <iostream>
#include <set>
#include "procpn.hpp"

using namespace std;
using namespace procon;

int main(){
    int e;
    set<int> v;
    int d[MAX_V][MAX_V];
    while(cin >> e,e){
        fill((int*)d,(int*)d + MAX_V * MAX_V,INF);
        FOR(i,0,e){
            int f,t,p;
            cin >> f >> t >> p;
            d[f][t] = p;
            v.insert(f); v.insert(t);
        }
        FORI(i,v) d[*i][*i] = 0;

        warshall_floyed(MAX_V,d);
        int town = 0;
        int m = INF;
       FORI(i,v){
            int t = 0;
            FORI(j,v){
                t += d[*i][*j];
            }
            if(m < t) continue;
            m = t;
            town = *i;
        }
        cout << town << " " << m << endl;
    }
    return 0;
}