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 <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll


signed main(){
  int n;
  while(cin>>n&&n){
    vector<P> G[15];
    
    int maxl=0;
    for(int i=0; i<n; i++){
      int a,b,c; cin>>a>>b>>c;
      G[a].push_back(mk(b,c));
      G[b].push_back(mk(a,c));
      maxl=max(maxl,max(a,b));
    }
    
    P min_ans; min_ans.first=INF;
    for(int i=0; i<=maxl; i++){
      int c[15];
      bool come[15];
      for(int j=0; j<=10; j++){c[j]=INF; come[j]=false;}
      
      priority_queue<P, vector<P>, greater<P> > que;
      que.push(mk(0,i));
      c[i]=0;
      int sum=0;
      while(!que.empty()){
        int at=que.top().second; int how_much=que.top().first;
        que.pop();
        if(come[at]) continue;
        sum+=how_much;
        come[at]=true;
        for(int j=0; j<G[at].size(); j++){
          int to=G[at][j].first;
          if(come[to]) continue;
          if(c[to]>how_much+G[at][j].second){
            c[to]=how_much+G[at][j].second;
            que.push(mk(c[to],to));
          }
        }
      }
    
      if(min_ans.first>sum){
        min_ans.first=sum; min_ans.second=i;
      }
    }
    
    cout<<min_ans.second<<" "<<min_ans.first<<en;
  }
}

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

using namespace std;

int main(){
        int N;
        while(cin>>N,N){
                vector<vector<int>>data;
                set<int>d;
                data.resize(N);
                for (int i = 0; i < N; i++) {
                        data[i].resize(N);
                        for (int j = 0; j < N; j++) {
                                data[i][j]=INT_MAX/6;
                        }
                        data[i][i]=0;
                }
                for (int i = 0; i < N; i++) {
                        int a,b,c;
                        cin>>a>>b>>c;
                        data[a][b]=c;
                        data[b][a]=c;
                        d.insert(a);
                        d.insert(b);
                }
                for (int k = 0; k < N; k++) {
                        for (int i = 0; i < N; i++) {
                                for (int j = 0; j < N; j++) {
                                        data[i][j]=min(data[i][j],data[i][k]+data[k][j]);
                                        data[j][i]=data[i][j];
                                }
                        }
                }
                long long int ans=INT_MAX;
                int memo2;
                for(auto x:d){
                        long long int memo=0;
                        for(auto y:d){
                                memo+=data[x][y];
                        }
                        if(ans>memo){
                                memo2=x;
                                ans=memo;
                        }
                }
                cout<<memo2<<" "<<ans<<endl;
        }

}

C++: #include<iostream>
#include<string.h>
using namespace std;
const int maxn = 20;
const int INF = 0x3f3f3f3f;
int d[maxn][maxn];
int n;
int m;
int res;
int floyd()
{
	int start;
	for(int i = 0; i <= m; i++)
		d[i][i] = 0;
	
	
	for(int k =0; k<=m; k++)
		for(int i = 0; i <= m; i++)
			for(int j = 0; j <= m; j++)
			{
				if(d[i][j] > d[i][k] + d[k][j])
					d[i][j] = d[i][k] + d[k][j];
			}
	
	for(int i = 0; i <= m; i++)
	{
		int cnt = 0;
		for(int j = 0; j <= m; j++)
			cnt += d[i][j];
		if(cnt < res)
		{
			res = cnt;
			start = i;
		}	
	}	
	return start;	
			
}

int main()
{
	//freopen("c:\\users\\administrator\\desktop\\in.txt","r",stdin);
	while(cin >> n,n)
	{
		memset(d,INF,sizeof(d));
		res = INF,m = 0;
		for(int i = 0; i <n; i++)
		{
			int u,v,w;
			cin >> u >> v >>w;
			d[u][v] = w;
			d[v][u] = w;
			m = max(m,max(u,v));
		}
		cout<< floyd()<<" "<<res<<endl;	
			
	}
		
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
struct edge { int cost, to; };
vector<edge> G[11];
int solve(int s)
{
    int res = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> dist(11, INF);
    dist[s] = 0;
    que.push(P(0, s));
    while(not que.empty())
    {
        P now = que.top(); que.pop();
        //if(dist[now.second] < now.first) continue;
        for(int u = 0; u < G[now.second].size(); u++)
        {
            edge e = G[now.second][u];
            if(now.first + e.cost < dist[e.to])
            {
                dist[e.to] = now.first + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
    for(int i = 0; i <= 10; i++)
    {
        if(dist[i] == INF) continue;
        res += dist[i];
    }
    if(res == 0) return INF;
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        for(int i = 0; i <= 10; i++) G[i].clear();
        for(int i = 0; i < n; i++)
        {
            int from, to, cost;
            cin >> from >> to >> cost;
            G[from].push_back({cost, to});
            G[to].push_back({cost, from});
        }
        int ans = INF, u = -1;
        for(int s = 0; s <= 10; s++)
        {
            int cost = solve(s);
            if(cost < ans)
            {
                ans = cost;
                u = s;
            }
        }
        cout << u << " " << ans << endl;
    }
    return 0;
}