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 <stdio.h>
#include <string.h>
#define INF 0x3f3f3f
#define M 
int map[15][15], sum;

int min(int a, int b)
{
	return a < b ? a : b;
}
int zdl(int start)
{
	int list[13];
	bool next[13];
	memset(next, false, sizeof(next));
	for(int i=0; i<=sum; i++)
	{
		list[i] = map[start][i];
	}
	next[start] = true;
	int ans = 0, st = INF;
	for(int i=0; i<=sum; i++)
	{
		int k;
		st = INF;
		for(int j=0; j<=sum; j++)
		{
			if(!next[j])
			{
				if(st > list[j])
				{
					st = list[j];
					k = j;
				}
			}
		}
		next[k] = true;
		for(int j=0; j<=sum; j++)
		{
			if(st + map[k][j] < list[j])
			{
				list[j] = st + map[k][j];
			}
		}
	}
	for(int i=0; i<=sum; i++)
	{
		ans += list[i];
	}
	return ans;
}
int main()
{
	int n, m, a, b, s;
	while(scanf("%d", &n) != EOF && n)
	{
		sum = 0;
		for(int i=0; i<13; i++)
		{
			for(int j=0; j<13; j++)
			{
				if(i == j)
					map[i][j] = 0;
				else
					map[i][j] = INF;
			}
		}
		for(int i=0; i<n; i++)
		{
			scanf("%d%d%d", &a, &b, &s);
			if(sum < a)	sum = a;
			if(sum < b)	sum = b;
			if(map[a][b] > s)
			{
				map[a][b] = map[b][a] = s;
			}
		}
		int ans = INF, k;
		for(int i=0; i<=sum; i++)
		{
			int ww = zdl(i);
			if(ans > ww)
			{
				ans = ww;
				k = i;
			}
		}
		printf("%d %d\n", k, ans);
	}
	
	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);
	}
}

C++: #include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <iostream>
#include <sstream>
using namespace std;
#define INF INT_MAX>>1


int main()
{   
    // freopen("in","r",stdin);
    int n;
    while(scanf("%d",&n)&&n){
        int u,v,w,max_v=0;
        int g[15][15];
        memset(g,0x3f3f,sizeof(g));
        for(int i=0;i<n;i++){
            scanf("%d %d %d",&u,&v,&w);
            g[u][v]=g[v][u]=w;
            max_v = max(max_v,u);
            max_v = max(max_v,v);
        }  

        for(int k=0;k<=max_v;k++){
            for(int i=0;i<=max_v;i++){
                for(int j=0;j<=max_v;j++){
                    if(g[i][k]+g[k][j]<g[i][j])
                        g[i][j] = g[i][k]+g[k][j];
                }
            }
        }
        int ans_sum = INF,ans_i;
        for(int i=0;i<=max_v;i++){
            int sum = 0;
            for(int j=0;j<=max_v;j++){
                if(i!=j){
                    sum += g[i][j];
                }
            }
            if(sum < ans_sum){
                ans_sum = sum;
                ans_i = i;
            }
        }
        printf("%d %d\n",ans_i,ans_sum);
    }
    return 0;
}

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

using namespace std;

int a[110][110];
int vis[110];
int n, x, y, z;
int main()
{
    while(1)
    {
        scanf("%d", &n);
        if (n == 0) break;
        memset(a, 0, sizeof(a));
        for(int i=0; i<=9; i++)
            for(int j=0; j<=9; j++)
                a[i][j] = 100000;

        for(int i=0; i<=9; i++)
            a[i][i] = 0;
        memset(vis, 0, sizeof(vis));
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d%d", &x, &y, &z);
            a[x][y] = min(a[x][y], z);
            a[y][x] = min(a[y][x], z);
            vis[x] = 1; vis[y] = 1;
        }

        for(int i=0; i<=9; i++)
            for(int j=0; j<=9; j++)
                for(int k=0; k<=9; k++)
        {
            if (a[j][i] + a[i][k] < a[j][k])
                a[j][k] = a[j][i] + a[i][k];
        }


        int ans1 = -1;
        int ans2 = 0;
        for(int i=0; i<=9; i++)
        {
            if (vis[i] == 0) continue;
            int sum = 0;
            for(int j=0; j<=9; j++)
                sum += a[i][j] * vis[j];
            if (sum < ans2 || ans1 == -1) {ans1 = i; ans2 = sum;}
        }
        cout<<ans1<<' '<<ans2<<endl;
    }
}