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<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define LATTE 1000000000

int main(){
	int N;
	while(cin>>N,N){
		int dp[10][10]={},A,B,C;
		bool latte[10]={};
		for(int i=0;i<10;i++)for(int j=0;j<10;j++) if(i!=j) dp[i][j]=LATTE;
		for(int i=0;i<N;i++){
			cin>>A>>B>>C;
			dp[A][B]=dp[B][A]=C;
			latte[A]=latte[B]=true;
		}
		for(int k=0;k<10;k++){
			for(int i=0;i<10;i++){
				for(int j=0;j<10;j++){
					dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
				}
			}
		}
		int _min=LATTE,ans;
		for(int i=0;i<10;i++){
			if(!latte[i]) continue;
			int sum=0;
			for(int j=0;j<10;j++){
				if(!latte[j]) continue;
				if(dp[i][j]==LATTE){
					sum=LATTE;
					break;
				}
				sum += dp[i][j];
			}
			if(_min>sum){
				_min = sum; ans = i;
			}
		}
		printf("%d %d\n",ans,_min);
	}
}

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

const int INF = 1000000;

int main(){

    int n;
    while(1){
      cin >> n;
      if(n==0){
        break;
      }
      int table[10][10];

      bool realtowntable[10];

      for(int i=0;i<10;i++){
        realtowntable[i] = false;
      }

      for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
          if(i==j){
            table[i][j] = 0;
          }
          else{
            table[i][j] = INF;
          }
        }
      }
      int a,b,c;
      for(int i=0;i<n;i++){
        cin >> a >> b >> c;
        if(!realtowntable[a]){
          realtowntable[a] = true;
        }
        if(!realtowntable[b]){
          realtowntable[b] = true;
        }
        table[a][b] = table[b][a] = c;
      }

      for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
          for(int j=0;j<10;j++){
            if(table[i][j] > table[i][k] + table[k][j]){
              table[i][j] = table[i][k] + table[k][j];
            }
          }
        }
      }

      for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
          for(int j=0;j<10;j++){
            if(table[j][i] > table[j][k] + table[k][i]){
              table[j][i] = table[j][k] + table[k][i];
            }
          }
        }
      }

      int anstown = 0;
      long long int ans=0,tmp=0;
      ans = INF * 12;
      for(int i=0;i<10;i++){
        if(realtowntable[i]){
          tmp = 0;
          for(int j=0;j<10;j++){
            if(realtowntable[j]){
              tmp += table[i][j];
            }
          }
          if(ans > tmp){
            ans = tmp;
            anstown = i;
          }
        }
      }
      cout << anstown << ' ' << ans << endl;

    }


    return 0;
}

C++: #include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
const int maxn = 15;
#define INF 0xfffff
int d[maxn][maxn];
int V, ans_num, ans_dis;
void init(){
    ans_dis = INF;
    for(int i = 0; i < maxn; i++){
        fill(d[i], d[i] + maxn, INF);
        d[i][i] = 0;
    }
}
void Floyd(){
    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]);
//                printf("d[%d][%d] = %d\n",i,j,d[i][j]);
            }
}
void solve(){
    Floyd();
    for(int i = 0; i <= V; i++){
        int sum_dis = 0;
        for(int j = 0; j <= V; j++)
            sum_dis += d[i][j];
        if(sum_dis < ans_dis){
            ans_dis = sum_dis;
            ans_num = i;
        }
    }
}
int main(){_
    int n;
    while(~scanf("%d",&n)){
        if(!n) break;
        V = 0;
        init();
        for(int i = 0; i < n; i++){
            int x, y, val;
            scanf("%d%d%d",&x, &y, &val);
            d[x][y] = d[y][x] = val;
//            printf("--d[%d][%d] = %d\n",x, y, d[x][y]);
            V = max(V, max(x, y));
        }
        solve();
        printf("%d %d\n",ans_num, ans_dis);
    }

    return 0;
}

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

const int INF = 1<<20;
const int MAX_V = 10;
const int MAX_E = 45;

int d[MAX_V][MAX_V];
int n;
int V;

void show_d() {
    cout << "===" << endl;
    for(int i = 0; i < V; i++) {
        for(int j = 0; j < V; j++) {
            printf("%3d ", d[i][j]);
        }
        cout << endl;
    }
}

void warshall_floyd() {
    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]);
            }
        }
        // show_d(); // debug
    }
}

int main() {
    while(true) {
        cin >> n;
        if(!n) break;
        int f, t, c;
        V = 0;
        for(int i = 0; i < MAX_V; i++) {
            for(int j = 0; j < MAX_V; j++) {
                d[i][j] = INF;
                if(i == j) d[i][j] = 0;
            }
        }
        for(int i = 0; i < n; i++) {
            cin >> f >> t >> c;
            d[f][t] = c;
            d[t][f] = c;
            V = max(V, f+1);
            V = max(V, t+1);
        }

        warshall_floyd();

        int ix = 0, s = INF;
        for(int i = 0; i < V; i++) {
            int tmp = 0;
            for(int j = 0; j < V; j++) {
                tmp += d[i][j];
            }
            if(tmp < s) {
                ix = i;
                s = tmp;
            }
        }

        cout << ix << " " << s << endl;

    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int d[11][11];//d[u][v]??????e=(u,v)????????????(?????¨???????????´??????INF,??????d[i][i]=0??¨??????)
int V=10;//????????°
const int INF=10000000;

void warshall_floyd(){
	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 main(){
	while(1){
		rep(i,0,10){
			rep(j,0,10){
				if(i==j) d[i][j]=0;
				else d[i][j]=INF;
			}
		}
		int n;
		cin>>n;
		if(n==0) break;
		int from,to,dist;
		rep(i,0,n){
			cin>>from>>to>>dist;
			d[from][to]=dist;
			d[to][from]=dist;
		}
		warshall_floyd();
		int MIN=INF,ans=0;
		rep(i,0,10){
			int sum=0;
			rep(j,0,10){
				if(d[i][j]!=INF) sum+=d[i][j];
			}
			if(sum==0) continue;
			if(sum<MIN){
				MIN=sum;
				ans=i;
			}
		}
		o(ans<<" "<<MIN);
	}
}