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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename M>
void warshallFloyd(M &m, const int &n) {
  rep(k, n) rep(i, n) rep(j, n) cmin(m[i][j], m[i][k] + m[k][j]);
}

void solve() {
  int n;
  while (cin >> n, n) {
    vvi t(10, vi(10));
    rep(i, 10) rep(j, 10) t[i][j] = i == j ? 0 : INF;
    set<int> s;
    rep(i, n) {
      int a, b, c;
      cin >> a >> b >> c;
      s.insert(a), s.insert(b);
      t[a][b] = t[b][a] = c;
    }
    vi v(s.size());
    copy(all(s), v.begin());
    warshallFloyd(t, 10);
    int ms = INF, mp;
    rep(i, 10) {
      int s = 0;
      for (int j : v) s += t[i][j];
      if (cmin(ms, s)) mp = i;
    }
    cout << mp << ' ' << ms << endl;
  }
}

C++: #include <cstdio>
#include <cstring>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include <map>
#include <algorithm>
using namespace std;
map<string, string>mp;
vector<vector<int> >G;

const int INF=0x3f3f3f3f;
const int maxn=1100;
int maps[maxn][maxn];
int n, m;


int main()
{
    while(scanf("%d", &n), n)
    {
        m=0;
        memset(maps, INF, sizeof(maps));
        for(int i=0; i<n; i++)
        {
            int u, v, w;
            scanf("%d %d %d", &u, &v, &w);
            m=max(m, max(u, v));
            maps[u][v]=maps[v][u]=w;
        }

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

        int sum=INF, index;
        for(int i=0; i<=m; i++)
        {
            int ans=0;

            for(int j=0; j<=m; j++)
                if(i!=j)
                    ans+=maps[i][j];
            if(sum>ans)
            {
                sum=ans;
                index=i;
            }
        }
        printf("%d %d\n", index, sum);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<map>
#define int long long
using namespace std;

signed main() {
	int a;
	while (cin >> a, a) {
		vector<vector<int>>b(a);
		int n = 0;
		for (int c = 0; c < a; c++) {
			vector<int>d(3);
			cin >> d[0] >> d[1] >> d[2];
			if (d[1] > n)n = d[1];
			if (d[0] > n)n = d[0];
			b[c] = d;
		}
		n++;
		vector<vector<int>>miti(n, vector<int>(n, 1000000));
		for (int e = 0; e < a; e++) {
			miti[b[e][0]][b[e][1]] = miti[b[e][1]][b[e][0]] = b[e][2];
		}
		for (int f = 0; f < n; f++) {
			for (int g = 0; g < n; g++) {
				for (int h = 0; h < n; h++) {
					if (g == h)miti[g][h] = 0;
					else miti[g][h] = (miti[g][h]<miti[g][f] + miti[f][h]) ? (miti[g][h]) : (miti[g][f] + miti[f][h]);
				}
			}
		}
		map<int, int>l;
		int o = 0;
		for (auto n : miti) {
			int s = 0;
			for (int m : n)s += m;
			l.insert(pair<int, int>(s, o));
			o++;
		}
		auto t = l.begin();
		cout << t->second << " " << t->first << endl;
	}
}

C++: #include<iostream>
#include<climits>
#include<algorithm>
using namespace std;
int main(){
	int n,t[20],d[20][20],temp,num,a,b,c,qq;
	while(cin>>n,n){
		temp=INT_MAX;
		qq=0;
		for(int i=0;i<10;i++)
		for(int j=0;j<10;j++){
			d[i][j]=INT_MAX/2;
			t[j]=0;
		}
		for(int i=0;i<n;i++){
			d[i][i]=0;
			cin>>a>>b>>c;
			if(qq<a)
			qq=a;
			if(qq<b)
			qq=b;
			d[a][b]=c;
			d[b][a]=c;
		}
		qq++;
		
		for(int k=0;k<qq;k++)
		for(int i=0;i<qq;i++)
		for(int j=0;j<qq;j++)
		d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		for(int i=0;i<qq;i++){
			for(int j=0;j<qq;j++){
				t[i]+=d[i][j];
			}
			if(temp>t[i]){
				temp=t[i];
				num=i;
			}
		}
		cout<<num<<' '<<temp<<endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<cstdio>

#define INF 100000000

struct edge{
	int from, to, cost;
	void init(){ from = 0, to = 0, cost = 0; };
};

edge es[100];

int d[1000000];
int V=0, E;

void shortest_path(int s){
	for (int i = 0; i < V+1; ++i)d[i] = INF;
	d[s] = 0;
	while (1){
		bool update = false;
		for (int i = 0; i < E*2; ++i){
			edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update)break;
	}
}

int main(){
	while (1){
		//for (int i = 0; i < E * 2; ++i)es[i].init();
		V = 0;
		scanf("%d", &E);
		if (E == 0)break;
		for (int i = 0; i < E; ++i){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			V < a ? V = a : V = V;
			V < b ? V = b : V = V;
			es[i * 2].from = a;
			es[i * 2].to = b;
			es[i * 2].cost = c;
			es[i * 2 + 1].from = b;
			es[i * 2 + 1].to = a;
			es[i * 2 + 1].cost = c;
		}
		int ans = 0;
		int anspath = INF;
		for (int i = 0; i < V + 1; ++i){
			int anspath_ = 0;
			shortest_path(i);
			for (int j = 0; j < V + 1; ++j){
				anspath_ += d[j];
			}
			if (anspath_ < anspath){
				anspath = anspath_;
				ans = i;
			}
		}
		printf("%d %d\n", ans, anspath);
	}
	return 0;
}//*/