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>
#define INFINITY (1 << 30)
#define MAX_N 10

using namespace std;

int n ;
long long  int d[MAX_N][MAX_N] = {},road[MAX_N][MAX_N] = {};;

int main() {
  int city, mincity;
  long long int  temp1, temp2, temp3, alt,costtime, cost;
  while (1) {
    road[MAX_N][MAX_N] = {};
    d[MAX_N][MAX_N] = {};
    cin >> n;
    if (n == 0) break;
    city = mincity = 0;
    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2 >> temp3;
      if (road[temp1][temp2] != 0) {
        if (road[temp1][temp2] > temp3) {
          road[temp1][temp2] = temp3;
          road[temp2][temp1] = temp3;
        }
      }
      else {
        road[temp1][temp2] = temp3;
        road[temp2][temp1] = temp3;
      }
      if (city < temp1 || city < temp2) { city = (temp1 > temp2) ? temp1 : temp2; }
    }
    //cout << city <<endl;
    city++;

    for (int i = 0; i < city; ++i) {
      for (int j = 0; j < city; ++j) {
        if (i != j) d[i][j] = INFINITY;
        if (road[i][j] != 0) d[i][j] = road[i][j];
      }
    }


    for (int i = 0; i < city; ++i)
      for (int j = 0; j < city; ++j)
        for (int k = 0; k < city; ++k) {
          if (d[j][i] != INFINITY && d[i][k] != INFINITY) {
            alt = d[j][i] + d[i][k];
            if (alt < d[j][k]) d[j][k] = alt;
          }
        }


    for (int i = 0; i < city; ++i) {
      cost = 0;
      for (int j = 0; j < city; ++j) {
        cost += d[i][j];
        //cout << d[i][j] << " ";
      }
      //cout << endl;
      if (i == 0) costtime = cost;
      if (costtime > cost) {
        costtime = cost;
        mincity = i;
      }
    }
    cout << mincity << " " << costtime << endl;

  }


  return 0;
}

C++: #include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<complex>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb(i) push_back(i)
#define fs first
#define sc second

const char dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int d[512][512];
int main(){
	int n,m;
	while(cin >> n){
		m = 0;
		fill_n(d[0],512*512,INF);
		rep(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			d[a][b] = d[b][a] = c;
			m = max(m,max(a,b));
		}
		rep(k,m)rep(i,m)rep(j,m){
			d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		}
		int city = -1, val = INF;
		rep(i,m){
			int tmp = 0;
			rep(j,m){
				tmp += d[i][j];
			}
			if(tmp < val){
				val = tmp;
				city = i;
			}
		}
		cout << city << " " << val << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<stdlib.h>


using namespace std;
typedef long long LL;
const int INF=5e8;
const int MOD=1e9+7;
const int MAXSIZE=1e6+5;
const double eps=0.0000000001;
void fre()
{
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
}
#define memst(a,b) memset(a,b,sizeof(a))
#define fr(i,a,n) for(int i=a;i<n;i++)

int n;
int maps[300][300];
int dis[300];
void Floy(int maxpos)
{
    for(int k=1; k<=maxpos; ++k)//?于?一个中?点
        for(int i=0; i<=maxpos; ++i)//枚?源点
            for(int j=0; j<=maxpos; ++j)//枚??点
                if(maps[i][j]>maps[i][k]+maps[k][j])//不?足三角不等式
                {
                    maps[i][j]=maps[i][k]+maps[k][j];//更新
                }
}
int sum(int s,int maxpos)
{
    int ans=0;
    for(int i=0;i<=maxpos;i++)
    {
        if(s==i) continue;
        if(maps[s][i]!=INF) ans+=maps[s][i];
        else return INF;
    }
    return ans;
}
void pr(int maxpos)
{
    for(int i=0;i<=maxpos;i++)
    {
        for(int j=0;j<=maxpos;j++)
        {
            printf("%d\t",maps[i][j]);
        }
        printf("\n");
    }
}
int main()
{
    while(cin>>n)
    {
        if(n==0) return 0;
        memset(maps,-1,sizeof(maps));
        int maxpos=0;
        for(int i=0; i<300; i++)
            for(int j=0; j<300; j++)
                maps[i][j]=INF;
        for(int i=0; i<n; i++)
        {
            int s,t,val;
            scanf("%d%d%d",&s,&t,&val);
            maps[s][t]=val;
            maps[t][s]=val;
            maxpos=max(maxpos,max(s,t));
        }
        Floy(maxpos);
       // pr(maxpos);
        int minn=INF,pos;
        for(int i=0;i<=maxpos;i++)
        {
            int ss=sum(i,maxpos);
          //  printf("ss %d %d\n",i,ss);
            if(ss<minn)
            {
                minn=ss;
                pos=i;
            }
        }
        printf("%d %d\n",pos,minn);
    }
    return 0;
}


/**************************************************/
/**             Copyright Notice                 **/
/**  writer: wurong                              **/
/**  school: nyist                               **/
/**  blog  : http://blog.csdn.net/wr_technology  **/
/**************************************************/

C++: #include <bits/stdc++.h>
using namespace std;

const int INF = 0x7f7f;
int d[11][11];

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        
        for(int i=0;i<=11;i++)fill(d[i],d[i]+11,INF);        
        
        for (int i = 0; i < 11; i++) d[i][i] = 0;
        int x, y, z, v = 0;
        while (n--) {
            cin >> x >> y >> z;
            v = max(max(v, x), y);
            d[x][y] = z;
            d[y][x] = z;
        }

		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 sum = INF,number;
        for (int i = 0; i <= v; i++) {
            int t = 0;
            for (int j = 0; j <= v; j++) t += d[i][j];
            if(sum>t){
            	sum=t;
            	number=i;
			}
        }
        cout<<number<<" "<<sum<<"\n";
    }
}