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 <vector>
using namespace std;
const int INF = 1001001001;

int main() {
    int E;
    while(cin >> E && E != 0) {
        vector<int> a(10,INF);
        vector< vector<int> > d(10,a);
        for(int i=0; i<10; i++) d[i][i] = 0;
        for(int i=0; i<E; i++) {
            int s,t,w;
            cin >> s >> t >> w;
            d[s][t] = w;
            d[t][s] = w;
        }

        for(int k=0; k<10; k++) {
            for(int i=0; i<10; i++) {
                for(int j=0; j<10; j++) {
                    if(d[i][k] != INF && d[k][j] != INF) {
                        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                    }
                }
            }
        }

        int ans = 0, sum = INF;
        for(int i=0; i<10; i++) {
            if(d[i][0] == INF) break;
            int temp = 0;
            for(int j=0; j<10; j++) {
                if(d[i][j] == INF) break;
                else temp += d[i][j];
            }
            if(sum > temp) {
                ans = i;
                sum = temp;
            }
        }
        cout << ans << " " << sum << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#define inf 1000000
using namespace std;
int d[10][10];
int v;

int main()
{
	int n;
	while(cin>>n,n)
	{
		bool used[10];
		memset(used,0,sizeof(used));
		memset(d,0,sizeof(d));
		for(int i=0;i<n;i++)
		{
			int s,t,c;
			cin>>s>>t>>c;
			used[s]=used[t]=true;
			d[s][t]=d[t][s]=c;
		}
		v=0;
		for(int i=0;i<10;i++)
		{
			if(used[i]) v++;
			for(int j=0;j<10;j++)
			{
				if(d[i][j]==0&&i!=j) d[i][j]=inf;
			}
		}

		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 ans,mn=inf;
		for(int i=0;i<v;i++)
		{
			int sum=0;
			for(int j=0;j<v;j++)
			{
				sum+=d[i][j];
			}
			if(sum<mn)
			{
				ans=i;mn=sum;
			}
		}
		cout<<ans<<" "<<mn<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
static const int INF = 999999;
struct SEdge
{
	int From;
	int To;
	int Cost;
};
int V;
vector<int> d;
vector<SEdge> Edge;

void Bellman_Ford(int s)
{
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	bool update = true;
	while(update)
	{
		update = false;
		int n = Edge.size();
		for(int i = 0; i < n; ++i)
		{
			SEdge e = Edge[i];
			if(d[e.From] != INF && d[e.To] > d[e.From] + e.Cost)
			{
				d[e.To] = d[e.From] + e.Cost;
				update = true;
			}
		}
	}
}

void solve()
{
	int E;
	while(cin >> E, E)
	{
		Edge.clear();
		Edge.resize(2 * E);
		for(int i = 0; i < E; ++i)
		{
			int From, To, Cost;
			cin >> From >> To >> Cost;
			V = max(V, max(From, To));
			Edge[2 * i + 1].To = Edge[2 * i].From = From;
			Edge[2 * i + 1].From = Edge[2 * i].To = To;
			Edge[2 * i + 1].Cost = Edge[2 * i].Cost = Cost;
		}
		++V;
		d.clear();
		d.resize(V);
		int Min = INF;
		int pos = 0;
		for(int i = 0; i < V; ++i)
		{
			Bellman_Ford(i);
			int sum = 0;
			for(int j = 0; j < V; ++j)
			{
				sum += d[j];
			}
			if(Min > sum)
			{
				Min = sum;
				pos = i;
			}
		}
		cout << pos << " " << Min << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: //floyd
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<limits>
#include<utility>

#define c11
#ifdef c11
#include<unordered_set>
#include<unordered_map>
#endif

using namespace std;
typedef long long ll;
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define initz(x) memset(x,0,sizeof(x))
#define initm(x) memset(x,0x7f,sizeof(x))
#define forn(i, n) for(int i = 0; i < (int) n; ++i)
#define for1(i, n) for(int i = 1; i <= (int) n; ++i)
#define fore(i, l, r) for(int i = (int) l; i <= (int) r; ++i)
#define rforn(i, n) for(int i = (int) n - 1; i>= 0; --i)
#define fi first
#define se second

int dx[4] = {1, 0 , -1, 0};
int dy[4] = {0, 1 , 0, -1};

const int INF = 0x3f3f3f3f;
const int MAX_N = 30;
const int MAX_M = 5000;

typedef pair<int, int> P;

int d[MAX_N][MAX_N];
int m;

void floyd() {
  for (int k = 0; k < m; ++k) {
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < m; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  int n, a, b, c;
  while (scanf("%d", &n) != EOF && n) {
    memset(d, 0x3f, sizeof(d));
    m = 0;
    while (n--) {
      scanf("%d%d%d", &a, &b, &c);
      d[a][b] = d[b][a] = c;
      m = max(m, max(a + 1, b + 1));
    }
    floyd();
    int ans, p, tmp;
    p = 0;
    ans = INF;
    for (int i = 0; i < m; ++i) {
      tmp = 0;
      for (int j = 0; j < m; ++j) {
        if (i == j) continue;
        tmp += d[i][j];
        if (tmp >= INF) break;
      }
      if (tmp < ans) {
        ans = tmp;
        p = i;
      }
    }
    printf("%d %d\n", p, ans);
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int INF = 0x3f3f3f3f;

int d[10][10];
int m;

void floyd() {
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < m; ++k) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

bool vis[10];

int main() {
  int i, j, a, b, c, n;
  while (scanf("%d", &n) != EOF && n) {
    memset(d, 0x3f, sizeof(d));
    m = 0;
    memset(vis, 0, sizeof(vis));
    while (n--) {
      scanf("%d%d%d", &a, &b, &c);
      d[a][b] = d[b][a] = c;
      m = max(m, max(a + 1, b + 1));
      vis[a] = vis[b] = 1;
    }
    floyd();
    int ans, p, tmp;
    ans = INF;
    for (i = 0; i < 10; ++i) {
      if (!vis[i]) continue;
      tmp = 0;
      for (j = 0; j < 10; ++j) {
        if (!vis[j] || i == j) continue;
        tmp += d[i][j];
        if (tmp >= INF) break;
      }
      if (tmp < ans) {
        ans = tmp;
        p = i;
      }
    }
    printf("%d %d\n", p, ans);
  }
  return 0;
}