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<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef pair<string,int>psi;
const int inf=0x3f3f3f3f;
const int N = 1005;
const int M = 1000005;
const ll mod = 1e9+7;
int road[50][50];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt", "w", stdout);
    int n, x, y, c, maxn;
    while(~scanf("%d", &n) && n)
    {
        maxn=0;
//        for(int i=0;i<=10;i++)
//            for(int j=0;j<=10;j++)
//                road[i][j] = 200;
        memset(road,inf,sizeof(road));
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&x,&y,&c);
            road[x][y]=c;
            road[y][x]=c;
            maxn=max(max(x,y), maxn);
        }
        for(int t=1; t<=maxn; t++)
        {
            for(int i=0;i<=maxn;i++)
            {
                for(int j=0;j<=maxn;j++)
                {
                    road[i][j]=min(road[i][t]+road[t][j], road[i][j]);
                }
            }
        }
        int sum=inf, tmp=0, id;
        for(int i=0;i<=maxn;i++)
        {
            tmp = 0;
            for(int j=0; j<=maxn; j++)
            {
                //cout << "road["<<i<<"][" << j << "]=" << road[i][j] << endl;
                if(i!=j)
                    tmp += road[i][j];
            }
            if(tmp < sum)
            {
                sum = tmp;
                //cout << "sum = " << sum << endl;
                id = i;
            }
        }
        printf("%d %d\n", id, sum);
    }
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <stack>
#include <queue>

using namespace std;

#define INF 10000000

int main(void)
{
    int n;

    while (cin >> n, n)
    {
        int road[45][45];

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                road[i][j] = INF;
            }
        }

        int m = 0;
        for (int i = 0; i < n; i++)
        {
            int a, b, c;
            cin >> a >> b >> c;
            road[a][b] = c;
            road[b][a] = c;
            m = max(m, max(a, b));
        }

        n = m+1;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                for (int k = 0; k < n; k++)
                {
                    road[j][k] = min(road[j][k], road[j][i] + road[i][k]);
                }
            }
        }

        int min = INF;
        int min_p;
        for (int i = 0; i < n; i++)
        {
            int sum = 0;
            for (int j = 0; j < n; j++)
            {
                if (i != j && road[i][j] != INF)
                {
                    //cout << i << " " << j << " " << road[i][j] << endl;
                    sum += road[i][j];
                }
            }
            if (sum > 0 && sum < min)
            {
                min = sum;
                min_p = i;
            }
        }
        cout << min_p << " " << min << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <bitset>
#include <string.h>
#include <cmath>
#include <algorithm>
#define N 1000015
#define P pair<int,int>
#define ll long long
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
bool vis[102];
int dis[300];
int g[300][300];
int inf = 0x3f3f3f3f;
int n, sum;
void Dijkstra(int x) {
	mem(vis, false);
	mem(dis, inf);
	dis[x] = 0;
	// dis[1] = inf;
	for (int i = 0; i <= sum; ++i) {
		int MIN = inf, u = -1;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] < MIN) {
				MIN = dis[j];
				u = j;
			}
		}
		if (u == -1)	return;
		vis[u] = true;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] > g[u][j] + MIN) {
				dis[j] = g[u][j] + MIN;
			}
		}
	}
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	while (cin >> n, n) {
		int s, e, c;
		mem(g, inf);
		sum = -1;
		for (int i = 0; i < n; ++i) {
			cin >> s >> e >> c;
			sum = max(s, sum);
			sum = max(e, sum);
			g[s][e] = g[e][s] = min(g[s][e], c);
		}
		int ans_n, ans_v = inf;
		for (int i = 0; i <= sum; ++i) {
			Dijkstra(i);
			int sum_temp = 0;
			for (int j = 0; j <= sum; ++j) {
				if (dis[j] == inf) {
					sum_temp = inf;
					break;
				}
				sum_temp += dis[j];
			}
			if (sum_temp < ans_v) {
				ans_v = sum_temp;
				ans_n = i;
			}
		}
		cout << ans_n << " " << ans_v << endl;
	}

	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:>
 ?????????============================================================
 
 =================================================================
 
 ?§£??¬=============================================================
 
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    ll G[10][10];
    bool used[10];
    while(cin >> n){
        if(n==0) break;
        for(int i = 0; i < 10;i++)for(int j = 0;j < 10;j++) G[i][j] = INF;
        for(int i = 0; i < 10;i++){
            used[i] = false;
            G[i][i] = 0;
        }
        for(int i = 0; i < n;i++){
            ll a,b,c; cin >> a >> b >> c;
            G[a][b] = min(G[a][b],c);
            G[b][a] = min(G[b][a],c);
            used[a] = used[b] = true;
        }
        for(int i = 0; i < 10;i++){
            for(int j = 0;j <10;j++){
                for(int k = 0;k < 10;k++){
                    G[j][k] = min(G[j][k],G[j][i]+G[i][k]);
                }
            }
        }
        ll id = -1,sum = INF;
        for(int i = 0; i < 10;i++){
            if(used[i] == false)continue;
            ll tmp = 0;
            for(int j = 0; j < 10;j++){
                if(i == j)continue;
                if(used[j] == false)continue;
                tmp += G[i][j];
            }
            if(tmp < sum){
                sum = tmp;
                id = i;
            }
        }
        cout << id << " " << sum << endl;
    }
    return 0;
}