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>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid + 1, r
#define lowbit(x) (x&-x)
using namespace std;
int cost[50][50];
int d[50];
bool vis[50];
int V;
int dijks(int s)
{
    fill(d,d+V+1,INF);
    fill(vis,vis+V+1,false);
    d[s] = 0;
    while(true) {
        int v = -1;
        for(int u = 0; u <= V; u++)
            if(!vis[u]&&(v==-1||d[u]<d[v]))
                v=u;
        if(v==-1)
            break;
        vis[v] = true;
        for(int u = 0; u <= V; u++)
            d[u] = min(d[u], d[v] + cost[v][u]);
    }
    int sum = 0;
    for(int j = 0; j <= V; j++)
        sum+=d[j];
    return sum;
}

int main()
{
    int n;
    while(cin>>n&&n) {
        memset(cost, INF, sizeof cost);
        int x, y, len;
        V = 0;
        for(int i = 0; i < n; i++){
            scanf("%d%d%d", &x, &y, &len);
            cost[x][y] = cost[y][x] = len;
            V = max(max(x,y),V);
        }
        int minn=INF, idx;
        for(int i = 0; i <= V ;i++){
            int sum = dijks(i);
            if(sum<minn){
                minn = sum;
                idx = i;
            }
        }
        printf("%d %d\n",idx, minn);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

const int INF = 1e8;

int e[10][10];

int main(void) {
    while (true) {
        int i, j, k, m;
        cin >> m;
        if (m == 0) break;
        REP (i,10) REP (j,10) e[i][j] = i == j ? 0 : INF;
        int n = 0;
        REP (i,m) {
            int a, b, c;
            cin >> a >> b >> c;
            e[a][b] = c;
            e[b][a] = c;
            n = max({n,a+1,b+1});
        }
        REP (k,n) REP (i,n) REP (j,n) e[i][j] = min(e[i][j],e[i][k] + e[k][j]);
        int mn = INF, mi;
        REP (i,n) {
            int sum = 0;
            REP (j,n) sum += e[i][j];
            if (mn > sum) {
                mn = sum;
                mi = i;
            }
        }
        cout << mi << " " << mn << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
using namespace std;
int a1[15][15], b1[15], n;
signed main() {
	while (cin >> n, n) {
		for0(i, 10)for0(j, 10)a1[i][j] = 5000 * (i != j);
		int m = 0;
		for0(i, n) {
			int a, b, c; cin >> a >> b >> c;
			m = max({ m, a, b });
			a1[a][b] = min(c, a1[a][b]);
			a1[b][a] = a1[a][b];
		}m++;
		for0(i, m)for0(j, m)for0(k, m)a1[j][k] = min(a1[j][k], a1[j][i] + a1[i][k]);
		for0(i, m)b1[i] = 0;
		for0(i, m)for0(j, i) {
			b1[i] += a1[i][j];
			b1[j] += a1[i][j];
		}
		int ans1 = -1, ans2 = 500000;
		for0(i, m)if (ans2 > b1[i]) { ans2 = b1[i]; ans1 = i; }
		cout << ans1 << ' ' << ans2 << endl;
	}
}

C++: #include <algorithm>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

typedef struct {
  int u, v, cost;
} Edge;

void solve(vector<Edge> es){
  VI d(10, INF);
  bool update = true;
  VI ans(10, 0);
  int lim = 10;

  REP(i, 0, lim){

    bool reach[10] = {false};
    REP(j, 0, 10){
      d[j] = INF;
    }
    d[i] = 0;
    reach[i] = true;
    update = true;

    while(update){
      update = false;
      REP(j, 0, es.size()){
        Edge e = es[j];
        if(d[e.u] != INF && d[e.v] > d[e.u] + e.cost){
          cout << e.u << ":" << e.v << endl;

          d[e.v] = d[e.u] + e.cost;
          update = true;
          reach[e.v] = true;
        }
      }
    }
    REP(j, 0, lim){
      if(reach[j]){
        ans[i] += d[j];
      } else {
        lim = j;
      }
    }
  }

  int f = INF;
  int v = -1;
  REP(i, 0, lim){
    if(f > ans[i]){
      f = ans[i];
      v = i;
    }
  }
  cout << v << " " << f << endl;

  return;
}

int main(){
  int N;

  while(1){
    cin >> N;
    if(N == 0){
      break;
    }
    vector<Edge> es(2*N);
    REP(i, 0, N){
      int a, b, c;
      cin >> a >> b >> c;
      es[i].u = a; es[i].v = b; es[i].cost = c;
      es[i+N].v = a; es[i+N].u = b; es[i+N].cost = c;
    }
    solve(es);
  }

  return 0;
}