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<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dre_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dre_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	while(1){
		int n;
		int t=0;
		cin>>n; if(n==0)break;
		
		int d[12][12]; rep(i,12)rep(j,12){if(i==j)d[i][j]=0; else d[i][j]=INF;}
		
		rep(i,n){
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			d[a][b]=min(d[a][b],c);
			d[b][a]=min(d[b][a],c);
			t=max_3(t,a,b);
		}
		
		rep(k,12){
			rep(i,12){
				rep(j,12){
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}

		int MIN=INF;
		int k=0;
		rep(i,t+1){
			int sum=0;
			rep(j,t+1){
				sum+=d[i][j];
			}
			if(MIN>sum){
				MIN=sum;
				k=i;
			}
		}
		
		printf("%d %d\n",k,MIN);
	}
}

C++: // 0189
#include <iostream>
#include <vector>
#include <queue>
#define  N    10000000
using namespace std;

int main(){
	while(1){
		int n, a, b, c, num=0, min=N, m=0;
		int town[10][10], dis[10][10], total[10] = {0};

		cin>>n;
		if(n == 0)
			break;

		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				town[i][j] = N;
				if(i == j)
					dis[i][j] = 0;
				else
					dis[i][j] = N;
			}
		}

		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			town[a][b] = c;
			town[b][a] = c;

			if(num < a)
				num = a;
			if(num < b)
				num = b;
		}

		for(int i=0;i<=num;i++){
			queue<int> ver;
			ver.push(i);
			while(!ver.empty()){
				int x = ver.front();
				for(int j=0;j<=num;j++){
					if(dis[i][j] > dis[i][x] + town[x][j]){
						dis[i][j] = dis[i][x] + town[x][j];
						ver.push(j);
					}
				}
				ver.pop();
			}
		}

		for(int i=0;i<=num;i++){
			for(int j=0;j<=num;j++)
				total[i] += dis[i][j];

			if(total[i] < min){
				min = total[i];
				m = i;
			}
		}

		cout<<m<<" "<<total[m]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#define MM(s,q) memset(s,q,sizeof(s))
#define INF 0x3f3f3f3f
#define MAXN 10005
#define Lchild id<<1
#define Rchild (id<<1)+1
#define ll long long
#define FILE  freopen("data.in","r",stdin)
using namespace std;
int dis[50][50];

void Floyd(int N) {
    for (int k = 0; k <= N; k++)
        for (int i = 0; i <= N; i++)
            for (int j = 0; j <= N; j++)
                if (i != j && i != k && j != k) {
                    if (dis[i][j] > dis[i][k] + dis[k][j])
                        dis[i][j] = dis[i][k] + dis[k][j];
                }
}

int main() {
    int n, u, v, w, N;
    while (cin >> n && n) {
        N = 0;
        MM(dis, INF);
        for (int i = 1; i <= n; i++) {
            scanf("%d%d%d", &u, &v, &w);
            dis[u][v] = dis[v][u] = w;
            N = max(N, max(u, v));
        }
        Floyd(N);
        int pos, ans = INF;
        for (int i = 0; i <= N; i++) {
            int sum = 0;
            for (int j = 0; j <= N; j++) {
             //   if (i != j)cout << dis[i][j] << endl;
                if (i != j && dis[i][j] < INF)
                    sum += dis[i][j];
            }
            if (ans > sum) {
                ans = sum, pos = i;
            }
        }
        cout << pos << " " << ans << endl;
    }
}

C++: #include<iostream>
using namespace std;
int n,t[100],a,L,R,M,ans;
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>t[i];
    }
    cin>>a;

    L=0;
    R=n;
    ans=0;
    while(L<R){
      M=(L+R)/2;
      if(t[M]==a){
	break;
      }else if(t[M]>a){
	R=M;
	ans++;
      }else{
	L=M+1;
	ans++;
      }
    }
    cout<<ans+1<<endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>

using namespace std;


int main(){

    long long n;
    vector< vector<long long> > map(100,vector<long long>(100));
    long long a,b,c;
    vector<long long> v(100);
    fill(v.begin(),v.end(),1<<20);
    while(true){
	fill(map.begin(),map.end(),v);
	cin >> n;
	long long ma=0;
	if(n == 0) break;
	for(long long i=0;i<n;i++){
	    cin >> a >> b >> c;
	    map[a][b] = c;
	    map[b][a] = c;
	    ma = max(ma,b);
	}
	for(long long i=0;i<ma;i++){
	    map[i][i] = 0;
	}
	ma++;
	for(int l = 0;l<2;l++){
	for(long long i=0;i<ma;i++){
	    for(long long j=0;j<ma;j++){
		for(long long k=0;k<ma;k++){
			map[i][j] = min(map[i][j] ,map[i][k] + map[k][j] );
		}
	    }
	}
	}

	long long res = 1<<30,t=0;
	for(long long i=0;i<ma;i++){
	    a =0;
	    for(long long j=0;j<ma;j++){
		a += map[i][j];
	    }
	    if(a!=0 && res>a){
		res = a;
		t = i;
	    }
	}
	cout << t<<" " << res << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <numeric>
using namespace std;
int main () {
	int n;
	while (cin >> n, n) {
		int d[10][10];
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				d[i][j] = ((i == j) ? 0 : 0xffffff);
			}
		}
		int v = 0;
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			d[a][b] = d[b][a] = c;
			v = max(a, max(b, v));
		}
		v++;
		// ワーシャルフロイド法
		for (int k = 0; k < v; k++) {
			for (int i = 0; i < v; i++) {
				for (int j = 0; j < v; j++) {
					// pathを1つの辺と考えることで，
					// 直接行く場合とそうでない場合を考える問題とすることができる
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		int minPos;
		int minPosTotal = 0x7fffffff;
		for (int i = 0; i < v; i++) {
			int total = accumulate((int*) d[i], d[i] + v, 0);
			//cout << total << endl;
			if (total < minPosTotal) {
				minPos = i;
				minPosTotal = total;
			}
		}
		cout << minPos << ' ' << minPosTotal << endl;
	}
	return 0;
}