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 <algorithm>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <math.h>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n ; i++)
#define pb push_back
static const int INF = 1000000;
static const int MAX = 100;

struct edge {int st, fin, cost;};

int d[MAX][MAX];

void floyd(int n){
  rep(k,n){
    rep(i,n){
      rep(j,n){
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  rep(i,n){
    rep(j,n){
    //  cout << d[i][j] <<  " ";
    }
  //  cout << endl;
  }
}

int main(void){
  int n;
  cin >> n;

  rep(i,10){
    rep(j,10){
      d[i][j] = ( ( i == j ) ? 0 : INF);
    }
  }

  int a,b,c;
  rep(i,n){
    cin >> a >> b >> c;
    d[a][b] = c;
    d[b][a] = c;
  }

  floyd(10);
  int sum = 0;
  int minsum = INF;
  int min_i = 0;

  rep(i,10){
    rep(j,10){
      if( d[i][j] != INF){
        sum += d[i][j];
      }
    }
    //cout << "from " << i << " " << sum << endl;
    if(minsum > sum && sum != 0){
      min_i = i;
      minsum = sum;
    }
    sum = 0;
  }
  cout << min_i << " " << minsum << endl;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int map[10][10];
		int m = 0;
		for(int i = 0 ;i < 10; i++){
			for(int j = 0; j < 10; j++){
				if(i == j) map[i][j] = 0;
				else map[i][j] = 10000000;
			}
		}
		for(int i = 0 ; i< n; i++){
			int a,b,c;
			cin >> a >> b >> c;
			m = max(max(a,b),m);
			map[a][b] = map[b][a] = c;
		}
		for(int k = 0; k <= m; k++){
			for(int i = 0; i <= m; i++){
				for(int j = 0; j <= m; j++){
					map[i][j] = min(map[i][j],map[i][k]+map[k][j]);
				}
			}
		}
		int ans[10] = {};
		for(int i = 0 ; i<=m; i++)for(int j = 0 ; j <= m; j++)ans[i] += map[i][j];
		int a = 0;
		for(int i = 0; i <= m; i++){
			if(ans[i] < ans[a]) a = i;
		}
		cout << a << " " << ans[a] << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define inf 0x3f3f3f3f
#define maxn 15
#define maxm 55
using namespace std;
typedef long long ll;
int f[maxn][maxn],n;
bool app[maxn];
int main(){
	while(~scanf("%d",&n) && n){
		memset(app,false,sizeof(app));
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				f[i][j] = inf;
			}
		}
		for(int i=0;i<10;i++) f[i][i] = 0;
		for(int i=1;i<=n;i++){
			int u,v,w;
			scanf("%d%d%d",&u,&v,&w);
			app[u] = app[v] = true;
			f[u][v] = f[v][u] = min(f[u][v],w);
		}
		for(int k=1;k<=10;k++){
			for(int i=0;i<10;i++){
				for(int j=0;j<10;j++){
					f[i][j] = min(f[i][j],f[i][k-1] + f[k-1][j]);
				}
			}
		}
		int cit,ans=inf,tot;
		for(int i=0;i<=9;i++){
			if(!app[i]) continue;
			tot=0;
			for(int j=0;j<=9;j++){
				if(!app[j]) continue;
				tot += f[i][j];
			}
			if(tot < ans){
				ans = tot;
				cit = i;
			}
		}
		printf("%d %d\n",cit,ans);
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  while(n!=0){

  int a,b,c;
  int dc[10][10];
  int count=-1;
  int m=0;
  int s=0;
  int num=0;



	  
  for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
		if(i==j)
			dc[i][j]=0;
		else
			dc[i][j]=1000;
	}
  }

  
  for(int i=0;i<n;i++){
	cin >> a >> b >> c;
	dc[a][b]=c;
	dc[b][a]=c;
	if(count<a)
		count=a;
	if(count<b)
		count=b;
  }

  count=count+1;

  for(int l=0;l<count;l++){
	for(int i=0;i<count;i++){
		for(int j=0;j<count;j++){
			if(dc[i][l]==1000||dc[l][j]==1000)
				continue;
			else if(dc[i][j]==1000)
				dc[i][j]=dc[i][l]+dc[l][j];
			else if(dc[i][j]>dc[i][l]+dc[l][j])
				dc[i][j]=dc[i][l]+dc[l][j];
		}
	}
  }

  m=0;
  s=0;

  for(int i=0;i<count;i++)
	  s+=dc[0][i];

  for(int i=1;i<count;i++){
	  num=0;
	  for(int j=0;j<count;j++){
		  num+=dc[i][j];
	  }
	  if(num<s){
		m=i;
		s=num;
	  }
  }

  cout << m << ' ' << s << endl;

  cin >> n;
  count=-1;
  num=0;

  }

  return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;

const int INF = 100100100;

int main(){
	while(1){
		int n;
		scanf("%d", &n);
		if(n == 0) break;

		int d[10][10];
		for(int i=0; i<10; i++)
			for(int j=0; j<10; j++){
				if(i == j) d[i][j] = 0;
				else d[i][j] = INF;
			}
		for(int i=0; i<n; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			d[a][b] = c;
			d[b][a] = c;
		}

		for(int k=0; k<10; k++){
			for(int i=0; i<10; i++){
				for(int j=0; j<10; j++){
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}

		int s[10] = {};
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(d[i][j] != INF){
					s[i] += d[i][j];
				}
			}
		}
		
		int num, ans = INF;
		for(int i=0; i<10; i++){
			if(s[i] != 0 && s[i] < ans){
				num = i;
				ans = s[i];
			}
		}
		printf("%d %d\n", num, ans);
	}
	return 0;
}

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

int main() {
	int a;
	while (cin >> a, a) {
		vector<vector<int>>b(a);
		int n = 0;
		for (int c = 0; c < a; c++) {
			vector<int>d(3);
			cin >> d[0] >> d[1] >> d[2];
			if (d[1] > n)n = d[1];
			if (d[0] > n)n = d[0];
			b[c] = d;
		}
		n++;
		vector<vector<int>>miti(n, vector<int>(n, 1000000));
		for (int e = 0; e < a; e++) {
			miti[b[e][0]][b[e][1]] = miti[b[e][1]][b[e][0]] = b[e][2];
		}
		for (int f = 0; f < n; f++) {
			for (int g = 0; g < n; g++) {
				for (int h = 0; h < n; h++) {
					if (g == h)miti[g][h] = 0;
					else miti[g][h] = (miti[g][h]<miti[g][f]+miti[f][h]) ? (miti[g][h]) :( miti[g][f] + miti[f][h]);
				}
			}
		}
		map<int, int>l;
		for (int i = 0; i < n; i++) {
			int s = 0;
			for (int j = 0; j <n; j++) {
				s += miti[i][j];
			}
			l[s];
			l[s] = i;
		}
		auto t = l.begin();
		cout << t->second << " " << t->first << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
struct Graph{
  Graph(int n):E(n),d(n){}
  vector<vector<P>>E;
  vector<int>d;
  void add_edge(int a,int b,int c){
    E[a].push_back({b,c});
  }
  void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>>q;
    fill(d.begin(),d.end(),1e9);
    q.push({d[s]=0,s});
    while(q.size()){
      P p=q.top();q.pop();
      if(p.first>d[p.second])continue;
      for(P& a:E[p.second]){
        int x=a.first,y=a.second+p.first;
        if(y<d[x])d[x]=y,q.push({y,x});
      }
    }
  }
};
main(){
  int n,a,b,c,x=0,y,z=1e9,g;
  while(cin>>n,n){
    Graph E(10);
    x=0,z=1e9;
    for(int i=0;i++<n;x=max(x,max(a,b)),E.add_edge(a,b,c),E.add_edge(b,a,c))cin>>a>>b>>c;
    for(int i=0;i<=x;++i){
      E.dijkstra(i);
      y=0;
      for(int j=0;j<=x;++j)y+=E.d[j];
      if(y<z)z=y,g=i;
    }
    cout<<g<<' '<<z<<endl;
  }
}