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>
using namespace std;
const int MAX = 11;
const int INF = 1<<28;
 
int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];
 
int dijkstra(int s){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
     
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = 0 ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
         
        if(mini == INF) break;
        visit[mn] = true;
         
        for(int i = 0; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            v[i] = min(v[i],t);
        }
    }
     
    int sum = 0;
    for(int i = 0 ; i <= maxnum ; i++){
        sum += v[i];
    }
     
    return sum;
}
 
 
int main(){
    int a,b,c;
 
    while(cin >> n,n){
         
        for(int i = 0 ; i < MAX ; i++)
            for(int j = 0 ; j < MAX ; j++)
                r[i][j] = INF;
         
        maxnum = 0;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = r[b][a] = c;
	     maxnum = max(maxnum,max(a,b));
        }
 
        int mx = INF, e;
        for(int i = 0 ; i <= maxnum ; i++){
            int val = mx;
            mx = min(mx,dijkstra(i));
            if(val > mx) e = i;
        }
        cout << e << " " << mx << endl;
    }
     
    return 0;
}

C++: #include<iostream>
using namespace std;
int FULL=100000;
int main(){
  while(1){
    int n;
    cin>>n;
    if(!n)
      break;
    int times[10][10];
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        times[i][j]=FULL;
      }
      times[i][i]=0;
    }
    int a,b,c;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      times[a][b]=c;
      times[b][a]=c;
    }
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        for(int k=0;k<10;k++){
          if(times[j][k]>(times[j][i]+times[i][k])){
            times[j][k]=times[j][i]+times[i][k];
            times[k][j]=times[j][i]+times[i][k];
          }
        }
      }
    }
    int min=1000000;
    int town=100;
    int num=0;
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        if(times[i][j]==FULL)
          break;
        num+=times[i][j];
      }
      if(num==0)
        break;
      if(num<min){
        min=num;
        town=i;
      }
      num=0;
    }
    cout<<town<<' '<<min<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<algorithm>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <functional>
#include <time.h>
using namespace std;
clock_t fi, endtime;

const int r_c = 0;
const int r_t = 1;
const int MAX_V = 10;
const int MAX_E = 45;
const int MAX_D = 100;
const int MIN_D = 0;

const int INF = MAX_V * MAX_E * MAX_D;

int main()
{
	while (1) {
		int wf[MAX_V][MAX_V];
		int sum[MAX_V] = { 0 };
		int ansi,ans;
		int n, a, b, c, m;
		m = 0;
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < MAX_V; ++i) {
			for (int j = 0; j < MAX_V; ++j) {
				wf[i][j] = INF;
				if (i == j) wf[i][j] = 0;
			}
		}
		for (int i = 0; i < n; ++i) {
			scanf("%d %d %d", &a, &b, &c);
			if (a > m) m = a;
			if (b > m) m = b;
			wf[a][b] = c; wf[b][a] = c;
		}
		for (int k = 0; k <= m; ++k) {
			for (int i = 0; i <= m; ++i) {
				for (int j = 0; j <= m; ++j) {
					if (wf[i][j] > wf[i][k] + wf[k][j])
						wf[i][j] = wf[i][k] + wf[k][j];
				}
			}
		}
		for (int i = 0; i <= m; ++i) {
			sum[i] = 0;
			for (int j = 0; j <= m; ++j) {
				sum[i] += wf[i][j];
			}
			if (i == 0) {
				ans = sum[0]; ansi = 0;
			}
			if (ans > sum[i]) {
				ans = sum[i]; ansi = i;
			}
		}
		printf("%d %d\n", ansi, ans);
	}
}

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

const int MAX_V = 10;
const int MAX_E = 45;
const int INF = 100000000;

int dist[MAX_V][MAX_V];

int main() {
  while (true) {
    int n; scanf("%d", &n);
    if (n == 0) break;

    for (int i = 0; i < MAX_V; i++) {
      for (int j = 0; j < MAX_V; j++) dist[i][j] = (i == j ? 0 : INF);
    }

    int vnum = 0;
    for (int i = 0; i < n; i++) {
      int u, v, d; scanf("%d %d %d", &u, &v, &d);
      dist[u][v] = dist[v][u] = d;
      vnum = max(vnum, max(u, v) + 1);
    }

    // Warshall-Froyd
    for (int k = 0; k < vnum; k++) {
      for (int i = 0; i < vnum; i++) {
        for (int j = 0; j < vnum; j++) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }

    int minV = -1;
    int minSum = INF;
    int ans = INF;
    for (int i = 0; i < vnum; i++) {
      int sum = 0;
      for (int j = 0; j < vnum; j++) {
        if (j != i) sum += dist[i][j];
      }
      if (sum < minSum) {
        minV = i;
        minSum = sum;
      }
    }
    printf("%d %d\n", minV, minSum);
  }
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#define INF 1000000
typedef long long int lli;
using namespace std;

struct edge{int from,to,cost;};
int shortest_path(int s,int V,int E,vector<int> d,vector<edge> es){
	int result=0;
	for(int i=0; i<V; ++i) d[i]=INF;
	d[s]=0;
	while(true){
		bool update = false;
		for(int i=0; i<E; ++i){
			edge e=es[i];
			if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
			if(d[e.to]!=INF&&d[e.from]>d[e.to]+e.cost){
				d[e.from]=d[e.to]+e.cost;
				update=true;
			}
						if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
			if(d[e.to]!=INF&&d[e.from]>d[e.to]+e.cost){
				d[e.from]=d[e.to]+e.cost;
				update=true;
			}
		}
		if(!update) break;
	}
	for(int i=0; i<V; ++i){
		result+=d[i];
	}
	return result;
}

int main(){
	int n;
	while(cin>>n&&n){
		vector<edge> es(n);
		int m=0;
		for(int i=0; i<n; ++i){
			int a,b,c;
			cin >> a >> b >> c;
			m=max(a,max(b,m));
			es[i].from=a;
			es[i].to=b;
			es[i].cost=c;
		}
		vector<int> d(m+1);
		int ans_d=INF;
		int ans_s;
		for(int i=m; i>=0; --i){
			int tmp=shortest_path(i,m+1,n,d,es);
			//cout << tmp << "\n";
			if(ans_d>tmp){
				ans_d=tmp;
				ans_s=i;
			}
		}
		cout << ans_s << " " << ans_d << "\n";
	}
	return 0;
}