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 <string>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
typedef pair<int,int> P;

#define INF 1000000
struct road{int to,cost;};
int d[10];
int n,m;

int main(){
  while(1){
    cin >> n;
    if(!n)break;
    m = 0;
    vector<road> roads[10];
    for(int i=0;i<n;i++){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      if(m<x||m<y){
        m = max(x,y);
      }
      roads[x].push_back((road){y,z});
      roads[y].push_back((road){x,z});
    }
    m++;

    int minIndex;
    int mini = INF;
    for(int i=0;i<m;i++){
      priority_queue<P, vector<P>, greater<P> > que;
      que.push(P(0,i));
      fill(d,d+m,INF);
      d[i] = 0;
      while(que.size()){
        P p = que.top(); que.pop();
        int dist = p.first;
        int pos = p.second;
        if(d[pos]<dist) continue;
        for(int j=0;j<roads[pos].size();j++){
          int to = roads[pos][j].to;
          int cost = roads[pos][j].cost;
          if(d[to]>d[pos]+cost){
            d[to] = d[pos] + cost;
            que.push(P(d[to],to));
          }
        }
      }
      int sum = 0;
      for(int j=0;j<m;j++){
        //printf("%3d%c",d[j],j==m-1?'\n':' ');
        sum += d[j];
      }
      if(mini>sum){
        mini = sum;
        minIndex = i;
      }
    }
    cout << minIndex << " " << mini << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
int map[15][15];
void floyd(int n)
{
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			for(int k=0;k<n;++k)
			{
				map[j][k]=min(map[j][k],map[j][i]+map[i][k]);
			}
		}
	}
}
void init(int n)
{
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<i;++j)
		{
			map[i][j]=map[j][i]=inf;
		}
		map[i][i]=0;
	}
}
int main()
{
	int n;
	while(scanf("%d",&n),n)
	{
		init(15);int m=0;
		for(int i=0;i<n;++i)
		{
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			map[a][b]=map[b][a]=min(map[a][b],c);
			m=max(max(m,a),b);
		}
		floyd(m+1);
		int ans=inf,res=0;
		for(int i=0;i<=m;++i)
		{
			int p=0;
			for(int j=0;j<=m;++j)
			{
				if(map[i][j]!=inf)
				{
					p+=map[i][j];
				}
			}
			if(p<ans)
			{
				ans=p;res=i;
			}
		}
		printf("%d %d\n",res,ans);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int n;
const int INF = 1e9;

struct edge {
	int to, tm;
};

int main()
{
	cin >> n;

	while (n > 0) {
		int a, b, c, m, mc, md, t = 0;
		int d[10];
		typedef pair<int, int> P;
		vector<edge> G[10];

		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			
			edge e;
			e.to = b;
			e.tm = c;
			G[a].push_back(e);
			e.to = a;
			G[b].push_back(e);

			t = max(t, max(a, b));
		}

		md = INF;

		for (int i = 0; i <= t; i++) {
			mc = 0;
			fill(d, d + 10, INF);
			d[i] = 0;

			priority_queue<P, vector<P>, greater<P>> Q;
			Q.push(P(0, i));

			while (!Q.empty()) {
				P p = Q.top();
				Q.pop();

				int u = p.second;
				if (d[u] < p.first)
					continue;

				for (edge e : G[u]) {
					if (d[e.to] > d[u] + e.tm) {
						d[e.to] = d[u] + e.tm;
						Q.push(make_pair(d[e.to], e.to));
					}
				}
			}

			for (int i = 0; i <= t; i++)
				if(d[i] < INF)
					mc += d[i];

			if (mc < md) {
				m = i;
				md = mc;
			}
		}

		cout << m << " " << md << endl;
		cin >> n;
	}
}

C++: #include <iostream>
#include <algorithm>
#define INF 1 << 16
#define MAX_V 10
using namespace std;
int d[MAX_V+1][MAX_V+1];
int maxv;

void warshall_floyd() {
	for (int k = 0; k <= maxv; ++k) {
		for (int i = 0; i <= maxv; ++i) {
			for (int j = 0; j <= maxv; ++j) {
				d[i][j] = (d[i][k] + d[k][j] < d[i][j]) ? d[i][k] + d[k][j] : d[i][j];
			}
		}
	}
	return;
}

int main() {
	int m, a, b, c, minv, minsum;

	while (cin >> m, m) {
		for (int i = 0; i < MAX_V; ++i) {
			for (int j = 0; j < MAX_V; ++j) {
				d[i][j] = (i == j) ? 0 : INF;
			}
		}

		maxv = 0;
		while (m--) {
			cin >> a >> b >> c;
			maxv = (b > maxv) ? a : maxv;
			maxv = (b > maxv) ? b : maxv;
			d[a][b] = c;
			d[b][a] = c;
		}
		warshall_floyd();

		int sum[MAX_V] = { 0 };
		for (int i = 0; i <= maxv; ++i) {
			for (int j = 0; j <= maxv; ++j) {
				sum[i] += d[i][j];
			}
		}

		minsum = INF;
		for (int i = 0; i <= maxv; ++i) {
			if (sum[i] < minsum) {
				minv = i;
				minsum = sum[i];
			}
		}
		cout << minv << " " << minsum << endl;
	}
	return 0;
}

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;
        sum+=how_much;
        come[at]=true;
        que.pop();
        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;
  }
}