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 <bits/stdc++.h>

using namespace std;


int MapData[11][11];
int Result[11];

void calculation(int maxNode) {
	for (int i = 0; i < maxNode; i++) {
		for (int j = 0; j < maxNode; j++) {
			Result[i] += MapData[i][j];
		}
	}
}

void findAllRoad(int maxNode) {
	for (int i = 0; i < maxNode; i++) {
		for (int j = 0; j < maxNode; j++) {
			for (int k = 0; k < maxNode; k++) {
				MapData[j][k] = min(MapData[j][k], MapData[j][i] + MapData[i][k]);
				if (j == k) {
					MapData[j][k] = 0;
				}
			}
		}
	}
}

void init() {
	for (int i = 0; i < 11; i++) {
		for (int j = 0; j < 11; j++) {
			MapData[i][j] = 9999;
		}
	}
	memset(Result, 0, sizeof(Result));
}

int main() {
	int n, a, b, c, minTotal, minNum, cnt;

	while (cin >> n, n) {
		init();
		cnt = -1;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			MapData[a][b] = c;
			MapData[b][a] = c;
			cnt = max(cnt, a);
			cnt = max(cnt, b);
		}
		findAllRoad(cnt+1);
		calculation(cnt+1);

		minNum = -1;
		minTotal = INT_MAX;
		for (int i = 0; i < 11; i++) {
			if (Result[i] != 0 && Result[i] < minTotal) {
				minTotal = Result[i];
				minNum = i;
			}
		}
		cout << minNum << " " << minTotal << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, a, b, c, g[10][10], d[10][10], s[10];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) g[i][j] = 99999999, d[i][j] = 999999999;
		for (int i = 0; i < n; i++) scanf("%d%d%d", &a, &b, &c), g[a][b] = c, g[b][a] = c, m = max({ a + 1, b + 1, m });
		for (int i = 0; i < 10; i++) d[i][i] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					d[j][k] = min(d[j][k], d[j][i] + g[i][k]);
				}
			}
		}
		int p = 0;
		for (int i = 0; i < m; i++) for (int j = 0; j < m; j++) s[i] += d[i][j];
		for (int i = 0; i < m; i++) if (s[i] < s[p]) p = i;
		printf("%d %d\n", p, s[p]);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
typedef long long ll;

using namespace std;

const int mod=1e9+7;
const int INF=1<<25;

void solve(int n){
  int dp[11][11];
  fill(dp[0],dp[10],INF);
  rep(i,9) dp[i][i]=0;
  int a,b,c;
  int first=10,last=0;
  int ans1;
  ll ans2=INF,temp;
  rep(i,n){
    cin >> a >> b >> c;
    first=min(first,min(a,b));
    last=max(last,max(a,b));
    dp[a][b]=dp[b][a]=c;
  }
  rep(k,n) rep(i,n) rep(j,n){
    dp[j][i]=dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
  }
  REP(i,first,last+1){
    temp=0;
    REP(j,first,last+1){
      temp+=dp[i][j];
    }
    if(temp<ans2){
      ans2=temp;
      ans1=i;
    }
  }
  cout << ans1 << " " << ans2 << endl;

  return ;
}
int main(){
  int n;
  while(true){
    cin >> n;
    if(!n)  break;
    solve(n);
  }
  return 0;
}

C++: #include <cstdio>
#include <utility>
#include <vector>
#include <climits>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
//template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int n; (n = in());) {
		vector<vector <int>> v(10, vector<int>(10, INT_MAX/2));
		int s = 0;
		while (n--) {
			int a = in(), b = in();
			v[a][b] = v[b][a] = in();
			s = max(s, max(a, b));
		}
		s++;
		for (int i = 0; i < s; i++)
			v[i][i] = 0;
		for (int k = 0; k < s; k++)
			for  (int i = 0; i < s; i++)
				for (int j = 0; j < s; j++)
					v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
		int ri = 0, rm = INT_MAX;
		for (int i = 0; i < s; i++) {
			int m = 0;
			for (int j = 0; j < s; j++)
				m += v[i][j];
			if (m < rm)
				ri = i, rm = m;
		}
		outl(ri, ' ', rm);
	}
}

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;
}