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 <vector>
#include <string.h>
#define INF 999999999
using namespace std;

struct edge
{
	int From;
	int To;
	int Dist;
};

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector< vector<int> > D(10, vector<int>(10));
		vector<edge> Edge(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Edge[i].From >> Edge[i].To >> Edge[i].Dist;
		}
		int city_num = 0;
		for(int i = 0; i < n; ++i)
		{
			city_num = max(city_num, Edge[i].From);
			city_num = max(city_num, Edge[i].To);
		}
		city_num++;
		for(int i = 0; i < city_num; ++i)
		{
			for(int j = 0; j < city_num; ++j)
			{
				D[i][j] = INF;
			}
		}
		for(int i = 0; i < n; ++i)
		{
			D[i][i] = 0;
			D[Edge[i].From][Edge[i].To] = Edge[i].Dist;
			D[Edge[i].To][Edge[i].From] = Edge[i].Dist;
		}
		
		bool update = true;
		while(update)
		{
			update = false;
			for(int i = 0; i < city_num; ++i)
			{
				for(int j = 0; j < city_num; ++j)
				{
					for(int k = 0; k < city_num; ++k)
					{
						if(D[i][k] != INF && D[k][j] != INF && (D[i][k] + D[k][j] < D[i][j]))
						{
							D[i][j] = D[i][k] + D[k][j];
							update = true;
						}
					}
				}
			}
		}
		int min = INF;
		int index = 0;
		for(int i = 0; i < city_num; ++i)
		{
			int sum = 0;
			for(int j = 0; j < city_num; ++j)
			{
				sum += D[i][j];
			}
			if(min > sum)
			{
				min = sum;
				index = i;
			}
		}
		cout << index << " " << min << endl;
	}
}

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

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
#define   baba   0x3f3f3f3f
int main()
{
      int n,m;
      while (scanf("%d",&m),m) {


            int a[20][20];
            memset(a,baba,sizeof(a));
            n=0;
            for(int i=0;i<m;i++)
            {
                 int x,y;
                 scanf("%d%d",&x,&y);
                 n=n>x?n>y?n:y:x>y?x:y;
                 int z;
                 scanf("%d",&z);
                 if(a[x][y]>z)
                 {
                     a[x][y]=z;
                     a[y][x]=a[x][y];
                 }
            }
            int l=0;
            for(int i=0;i<=n;i++)
              {
                for(int j=0;j<=n;j++)
                {
                  for(int k=0;k<=n;k++)
                  {
                    if(a[i][j]>a[k][j]+a[k][i])
                    {
                      a[k][j]=a[i][j]+a[k][i];
                    }
                  }
                }
              }
            int r=0;
            int min=0x3f3f3f3f;

            for(int i=0;i<=n;i++)
            {
              r=0;
              for(int j=0;j<=n;j++)
              {
                if(j==i)
                continue;
                r+=a[i][j];
              }

              if(min>r)
              {
                      min=r;
                      l=i;
              }

            }

              cout<<l<<" "<<min<<endl;


      }
      return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
using namespace std;
main(){
  int m,n;
  while(cin>>n,n){
    int a[10][10],s[10],b,c,d;
    bool q[10];
    r(i,10){q[i]=0;s[i]=0;r(j,10){
      if(i==j)a[i][j]=0;
      else a[i][j]=INF;
    }}
    while(n--){
      scanf("%d%d%d",&b,&c,&d);
      a[c][b]=a[b][c]=d;
      q[c]=1;q[b]=1;
    }
    r(k,10)r(i,10)r(j,10){
      a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
    }
    r(i,10)if(q[i])r(j,10){
      if(q[j]&&a[i][j]!=INF)s[i]+=a[i][j];
    }
    int p=0,ss=1<<29;
    r(i,10){
      if(q[i]&&ss>s[i]){
        ss=s[i];
        p=i;
      }
    }
    cout<<p<<' '<<ss<<endl;
  }
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define scanf scanf_s

int n;
int cost[11][11];
int main()
{
	while (cin >> n,n)
	{
		REP(i, 11)REP(j, 11) cost[i][j] = INF;
		REP(i, 11) cost[i][i] = 0;
		int city = 0;
		REP(i, n)
		{
			int a, b, c;
			cin >> a >> b >> c;
			city = max(city, max(a, b));
			cost[a][b] = c;
			cost[b][a] = c;
		}
		city++;
		REP(i, city)REP(j, city)REP(k, city)
		{
			cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
		}
		int lcost[11] = {};
		REP(i, city)
		{
			REP(j, city) lcost[i] += cost[i][j];
		}
		int ansc = INF;
		int ans;
		REP(i, city)
		{
			if (ansc > lcost[i])
			{
				ansc = lcost[i];
				ans = i;
			}
		}
		cout << ans << " " << ansc << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0;i < (int)n;i++)

const int INF = 1001;

int d[100][100];

int main() {
    while(true) {
        int n, m = 0;
        cin >> n;
        if(!n) break;

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

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

        m++;

        rep(i, m) {
            rep(j, m) {
                rep(k, m) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }

        int ansd = 10000000, ansi;
        rep(i, m) {
            int sum = 0;
            rep(j, m) {
                sum += d[i][j];
            }
            if(sum < ansd) {
                ansd = sum;
                ansi = i;
            }
        }
        cout << ansi << ' ' << ansd << endl;
    }

    return 0;
}

C++: #include<stdio.h>
int main(){
  int n,i,j,k,s,a,b,ans,ma,t,min,mi,max;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    int m[10][10]={{0}};
    for(i=max=0;i<n;i++){
      scanf("%d %d %d",&a,&b,&t);
      m[a][b]=t;
      m[b][a]=t;
      if(max<a)max=a;
      if(max<b)max=b;
    }//printf("%d ",max);
    ans=2100000000;
    for(i=0;i<=max;i++){
      int c[10]={0};
      for(j=0;j<10;j++)c[j]=100000000;
      c[i]=0;
      char f[10]={0};
      mi=i;
      for(k=0;k<=max;k++){
	f[mi]=1;
	for(j=0;j<=max;j++){
	  if(m[mi][j]==0||f[j])continue;
	  if(c[mi]+m[mi][j]<c[j]){
	    c[j]=c[mi]+m[mi][j];//printf("%d %d\n",j,c[j]);
	  }
	}
	min=2100000000;
	//printf("%d:",i);
	for(j=0;j<=max;j++){//printf(" %d",c[j]);
	  if(f[j])continue;
	  if(min>c[j]){
	    mi=j;
	    min=c[j];
	  }
	}//printf("mi:%d\n",mi);
      }
      for(j=s=0;j<=max;j++)s+=c[j];//printf("%d %d\n",s,i);
      if(ans>s){
	ans=s;
	ma=i;
      }
    }
    printf("%d %d\n",ma,ans);
  }
  return 0;
}