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<bits/stdc++.h>
#define sd(x) scanf("%d",&x)
#define ss(x) scanf("%s",x)
#define sc(x) scanf("%c",&x)
#define sf(x) scanf("%f",&x)
#define slf(x) scanf("%lf",&x)
#define slld(x) scanf("%lld",&x)
#define me(x,b) memset(x,b,sizeof(x))
#define pd(d) printf("%d\n",d);
#define plld(d) printf("%lld\n",d);
#define eps 1.0E-8
// #define Reast1nPeace

typedef long long ll;

using namespace std;

const int INF = 0x3f3f3f3f;

int mapp[15][15];

int main(){
#ifdef Reast1nPeace
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n && n){
		memset(mapp,INF,sizeof(mapp));
		
		int m = -1;
		for(int i = 0 ; i<n ; i++){
			int a,b,c; cin>>a>>b>>c;
			mapp[a][b] = mapp[b][a] = c;
			m = max(m , max(a,b));
		}
		
		for(int k = 0 ; k<=m ; k++){
			for(int i = 0 ; i<=m ; i++){
				for(int j = 0 ; j<=m ; j++){
					if(i==j) continue;
					if(mapp[i][j] > mapp[i][k]+mapp[k][j]){
						mapp[i][j] = mapp[i][k]+mapp[k][j];
					}
				}
			}
		}
		
		int id; int minn = INF;
		for(int i = 0 ; i<=m ; i++){
			int sum = 0;
			for(int j = 0 ; j<=m ; j++){
				if(i==j) continue;
				sum += mapp[i][j];
			}
			if(minn > sum){
				minn = sum;
				id = i;
			}
		} 
		cout<<id<<" "<<minn<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>

const int N=12,INF=0x3f3f3f3f;
int g[N][N],n;

void minz(int &a,int b) { if(a>b) a=b; }

int main()
{
	int i,j,k,x,sum,cn;
	scanf("%d",&n);
	while(n) {
		memset(g,0x3f,sizeof(g));
		cn=0;
		for(i=0;i<n;i++) {
			scanf("%d%d%d",&j,&k,&x);
			if(j>cn) cn=j;
			if(k>cn) cn=k;
			g[j][k]=g[k][j]=x;
		}
		for(i=0;i<=cn;i++) g[i][i]=0;
		for(k=0;k<=cn;k++)
			for(i=0;i<=cn;i++) for(j=0;j<=cn;j++)
				minz(g[i][j],g[i][k]+g[k][j]);
		x=INF;
		for(i=0;i<=cn;i++) {
			sum=g[i][0];
			for(j=1;j<=cn;j++) if(g[i][j]<INF) sum+=g[i][j];
			if(sum<x) k=i,x=sum;
		}
		printf("%d %d\n",k,x);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define INF 1e9

int main() {
	int N, M;
	while ( cin >> M, M ) {
		int cost[100][100]; fill(cost[0], cost[100], INF);
		set<int> s;
		for (int i = 0; i < M; ++i) {
			int a, b, c; cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
			s.insert(a);
			s.insert(b);
		}
		vector<int> v;
		for (set<int>::iterator it = s.begin(); it != s.end(); ++it) {
			v.push_back(*it);
		}
		N = (int)v.size();
		for (int i = 0; i < N; ++i) cost[i][i] = 0;
		for (int k = 0; k < N; ++k) {
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < N; ++j) {
					cost[v[i]][v[j]] = min(cost[v[i]][v[j]], cost[v[i]][v[k]]+cost[v[k]][v[j]]);
				}
			}
		}
		int aid = -1, asum = 0;
		for (int i = 0; i < N; ++i) {
			int sum = 0;
			for (int j = 0; j < N; ++j) {
				sum += cost[v[i]][v[j]];
			}
			if (aid < 0 || sum < asum) {
				aid = i;
				asum = sum;
			}
		}
		cout << aid << " " << asum << endl;
	}
}

C++: #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
#define N 1010
#define Max 0x3f3f3f3f
int n, m, x;
int maps[N][N], dis[N],  vis[N];
int dij(int x)
{
    int i, j, pos, Min, sum=0;
    for(i=0; i<=n; i++)
    {
        dis[i]=maps[i][x];
        vis[i]=0;
    }
    for(i=0; i<=n; i++)
    {
        Min=Max;
        for(j=0; j<=n; j++)
        {
            if(vis[j]==0 && dis[j]<Min)
            {
                pos=j;
                Min=dis[j];
            }
        }
        vis[pos]=1;
        for(j=0; j<=n; j++)
        {
            if(vis[j]==0 && dis[j]>maps[j][pos]+dis[pos])
                dis[j]=maps[j][pos]+dis[pos];
        }
    }
    for(i=0; i<=n; i++)
    {
        sum+=dis[i];
    }
    return sum;

}
int main()
{
    int i, j, a, b, c, MAX, ans, p;
    while(scanf("%d",&m), m)
    {
        n=0;
        memset(maps, Max, sizeof(maps));
        for(i=0; i<m; i++)
        {
            scanf("%d %d %d",&a,&b,&c);
            if(n<b)
                n=b;;
            maps[a][b]=maps[b][a]=min(maps[a][b], c);
        }
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=n;j++)
            {
                if(i==j)
                    maps[i][j]=0;
            }
        }
        MAX=Max;
        for(i=0;i<=n;i++)
        {

            ans=dij(i);
            if(MAX>ans)
            {
                p=i;
                MAX=ans;
            }
        }
        printf("%d %d\n", p, MAX);

    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
#define INF 1000000
#define N 9
using namespace std;

int d[N][N];
int ans[N];
//初期化
void init(){
  for(int i=0;i<N;i++){
      ans[i]=0;
    for(int j=0;j<N;j++){
      if(i==j) d[i][i]=0;
      else d[i][j]=INF;
    }
  }
}
void solve(int n){
  init();
  int a,b,t;
  //値代入
  for(int i=0;i<n;i++){
    cin>>a>>b>>t;
    d[a][b]=d[b][a]=t; //無向辺
  }
  //ワーシャルフロイド
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      for(int k=0;k<N;k++){
        d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(d[i][j]==INF) continue;
      ans[i]+=d[i][j]; //距離の累積和
    }
  }
  int answer=INF,town;
  for(int i=0;i<N;i++){
    if(ans[i]!=0&&answer>ans[i]){
      answer=ans[i]; town=i;
    }
  }
  cout<<town<<" "<<answer<<"\n";

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

}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF = 1e9;
int data[20][20];
int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		REP(i,20) REP(j,20) data[i][j] = INF;
		REP(i,20) data[i][i] = 0;
		int m = 0;
		REP(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			m = max(m, a+1); m = max(m, b+1);
			data[a][b] = c;
			data[b][a] = c;
		}
		REP(k,m){
			REP(i,m){
				REP(j,m){
					data[i][j] = min(data[i][j], data[i][k] + data[k][j]);
				}
			}
		}
		int sum[20] = {0};
		int nowmin = INF;
		int ans;
		REP(i,m){
			REP(j,m){
				// cout << data[i][j] << " ";
				sum[i] += data[i][j];
			}
			if(nowmin > sum[i]) {
				nowmin = sum[i];
				ans = i;
			}
		}
		cout << ans << " " << sum[ans] << endl;
	}
}