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++: using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
#define INF 1<<12
typedef pair<int,int> p;
int main()
{
	int n,d[10][10];
	while(cin>>n&&n){
		fill(d[0],d[10],INF);
		int a,b,c;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			d[a][b]=d[b][a]=c;
		}
		for(int i=0;i<10;i++)d[i][i]=0;
		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 ans[10]={};
		vector<p> res;
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				if(d[i][j]<INF)ans[i]+=d[i][j];
		for(int i=0;i<10;i++){
			if(ans[i]!=0)res.push_back(p(ans[i],i));
			//printf("ans[%d]:%d\n",i,ans[i]);
		}
		sort(res.begin(),res.end());
		cout<<res.front().second<<" "<<res.front().first<<endl;
	}

    return 0;
}

C++: #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

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


using namespace std;



int main() {
	while(1){
		int n; cin >> n;
		if (!n)break;
		int t[16][16] = {};
		for (int i = 0; i < 16; i++)
			for (int j = 0; j < 16; j++)
				if (i == j)continue;
				else t[i][j] = 9999999;
		bool f[15][15] = {};
		bool F[15] = {};
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			t[a][b] = c;
			t[b][a] = c;
			
			F[a] = 1, F[b] = 1;
		}

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

		int ans = 0, an = 9999999;
		for (int i = 0; i < 10; i++) {
			if (!F[i])continue;
			int dd = 0;
			for (int j = 0; j < 10; j++) {
				if (!F[j])continue;
				dd += t[i][j];
			}
			if (an > dd) {
				ans = i, an = dd;
			}
		}


		
			cout << ans << " " << an << endl;
	
}

	
	return 0;

}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX 50
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];

int dijkstra(int s,int g){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = minnum ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = minnum ; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            if(t < v[i]) v[i] = t;
        }
    }
    
    return v[g];
}


int main(){
    int a,b,c;
    
    for(int i = 0 ; i < MAX ; i++)
        for(int j = 0 ; j < MAX ; j++)
            r[i][j] = INF;

    while(cin >> n,n){
        maxnum = 0;
        minnum = INF;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = c;
            r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
            minnum = min(minnum,min(a,b));
        }

        int mx = INF, e;
        for(int i = minnum ; i <= maxnum ; i++){
            int sum = 0,num = i;
            for(int j = minnum ; j <= maxnum ; j++){
                if(i == j) continue;
                if(dijkstra(i,j)!=INF)sum += dijkstra(i,j);
            }
            if(sum < mx){
                mx = sum;
                e = num;
            }
        }
        cout << e << ' ' << mx << endl;
    }
    
    return 0;
}

C++: #include <iostream>

#define MAX 10
#define INF 2000000
using namespace std;

int d[MAX][MAX];
int n, num_ver = 0;
int min_t = INF;
int min_ver;

void init();
void input();
void wf();

int main(){

  while(cin >> n, n){
    init();
    input();  
    wf();
    
   
    for(int i = 0; i <= num_ver; i++){
      int tmp = 0;
      for(int j = 0; j <= num_ver; j++){
	tmp += d[i][j];
      }
      if(min_t > tmp) {min_t = tmp; min_ver = i;}
    }
    cout << min_ver << " " << min_t << endl;
  }
}

void init(){
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      d[i][j] = (i==j)? 0: INF;
    }
  }
}

void input(){
  for(int i = 0; i < n; i++){
    int a, b, c;
    cin >> a >> b >> c;
    d[a][b] = c;
    d[b][a] = c;
    if(num_ver < b) num_ver = b;
  }
}

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