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 <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, a, b, c, g[500][500], d[500][500], s[500];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break; m = 0;
		for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) g[i][j] = 99999999, d[i][j] = 999999999;
		for (int i = 0; i < n; i++) scanf("%d%d%d", &a, &b, &c), g[a][b] = c, g[b][a] = c, m = max({ a + 1, b + 1, m });
		for (int i = 0; i < m; i++) d[i][i] = 0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < m; j++) {
				for (int k = 0; k < m; k++) {
					d[j][k] = min(d[j][k], d[j][i] + g[i][k]);
				}
			}
		}
		int p = 0;
		for (int i = 0; i < m; i++) { s[i] = 0; for (int j = 0; j < m; j++) s[i] += d[i][j]; }
		for (int i = 0; i < m; i++) if (s[i] < s[p]) p = i;
		printf("%d %d\n", p, s[p]);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(auto &t:a)cin>>t;return i;}
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T> void prArr(T a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  
  return 0;
}

C++: #include <iostream>

// int inf = 1 << 28;
int inf = 100000000;

int dijk(int n,int s, int **g) {
	int sum = 0;
	bool *used = new bool[n];
	int *d = new int[n];

	for(int i = 0; i < n; i++){
		d[i] = inf;
		used[i]=false;
	}
	d[s] = 0;

	while(true) {
		int u = -1;
		for(int v = 0; v < n; v++)
			if(!used[v] && (u == -1 || d[v] < d[u]))
				u = v;

		if(u == -1) break;
		used[u] = true;

		for(int v = 0; v < n; v++)
			if(d[v] > d[u] + g[u][v])
				d[v] = d[u] + g[u][v];
	}

	for(int i = 0; i < n; i++) {
		sum += d[i];
	}

	return sum;
}

int main() {
	do {
		int **g; // adjacency matrix, ?
		int *d;
		int *a, *b, *c;
		int edge = 0, min = 0, max = 0;
		int tmp = 0;

		std::cin >> edge;
		if(!edge) break;

		a = new int[edge];
		b = new int[edge];
		c = new int[edge];

		for(int i = 0;i < edge;i++) {
			std::cin >> a[i];
			std::cin >> b[i];
			std::cin >> c[i];
		}

		for(int i = 0; i < edge; i++) {
			if(max < a[i])
				max = a[i];
		}
		for(int i = 0; i < edge; i++) {
			if(max < b[i])
				max = b[i];
		}
		max++;

		g = new int*[max];
		d = new int[max];

		for(int i = 0; i < max; i++) {
			g[i] = new int[max];
		}

		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				g[i][j] = inf;

		for(int i = 0; i < edge; i++)
			g[b[i]][a[i]] = g[a[i]][b[i]] = c[i];

		for(int i = 0; i < max; i++)
			d[i] = dijk(max, i, g);

		min = d[0];
		for(int i = 1; i < max; i++) {
			if(min > d[i]) {
				min = d[i];
				tmp = i;
			}
		}

		std::cout << tmp << " " << min << std::endl;
		for(int i = 0; i < max; i++)
			delete[] g[i];
		delete[] g;
		delete[] a;
		delete[] b;
		delete[] c;
		delete[] d;

	}while(true);
	return 0;
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

#define INF 1000000000LL

long long edges[20][20];
long long dist[20][20];

int ids[20];
int nids;

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N;

        cin >> N;

        if(N==0)break;

        memset(edges,0,sizeof(edges));
        memset(dist,0,sizeof(dist));
        nids = 0;

        for(int i=0;i<N;++i){

            int x,y,c;

            cin >> x >> y >> c;

            int ix=-1;
            int iy=-1;

            for(int l=0;l<nids;++l){
                if(ids[l]==x) ix = l;
                if(ids[l]==y) iy = l;
            }

            if(ix<0){ ix = nids; ids[nids++]=x; }
            if(iy<0){ iy = nids; ids[nids++]=y; }

            edges[ix][iy] = edges[iy][ix] = c;

        }

        for(int i=0;i<nids;++i)
            for(int j=0;j<nids;++j){
                if(i==j)
                    dist[i][j]=0;
                else if(edges[i][j])
                    dist[i][j]=edges[i][j];
                else
                    dist[i][j]=INF;
            }

        for(int k=0;k<nids;++k)
            for(int i=0;i<nids;++i)
                for(int j=0;j<nids;++j)
                    dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);

        int ans  = 0;
        long long msum = INF;

        for(int i=0;i<nids;++i){

            long long sum = 0;
            for(int j=0;j<nids;++j) sum += dist[i][j];

            if(sum<=msum){

                if(sum==msum && ids[i]<ids[ans])
                    ans = i;
                else
                    ans = i;

                msum = sum;

            }

        }

        cout << ids[ans] << " " << msum << endl;


    }

    return 0;

}

C++: #include<iostream>
#include<algorithm>
#define INF 5e7
using namespace std;

int graf[15][15];

void warshall() {
	for (int k = 0;k < 13;k++)
		for (int i = 0;i < 13;i++)
			for (int j = 0;j < 13;j++)graf[i][j] = min(graf[i][j], graf[i][k] + graf[k][j]);
}

int main() {
	int n;
	while (cin >> n, n) {
		for (int i = 0;i < 15;i++)
			for (int j = 0;j < 15;j++) {
				graf[i][j] = INF;
				if (i == j)graf[i][j] = 0;
			}
		
		for (int i = 0;i < n;i++) {
			int a, b,c;
			cin >> a >> b>>c;
			graf[a][b] = c;
			graf[b][a] = c;
		}

		warshall();
		int t, time=1e9;

		for (int i = 0;i < 10;i++) {
			int a=0;
			for (int j = 0;j < 10;j++) {
				if(graf[i][j]!=INF)a += graf[i][j];
			}
			if (time > a&&a!=0) {
				time = a;
				t = i;
			}
		}

		cout << t << ' ' << time << endl;
	}
	return 0;
}