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++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

void warshallfloyd(vvi& d)
{
  REP(i, 10) d[i][i] = 0;
  REP(k, 10) REP(i, 10) REP(j, 10) {
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
}

signed main()
{
  for (int n; n = in(), n;) {
    vvi d(10, vi(10, INF));
    REP(i, n) {
      int a = in(), b = in(), c = in();
      d[a][b] = c; d[b][a] = c;
    }
    warshallfloyd(d);
    pii ans = mp(INF, INF);
    REP(i, 10) {
      pii t = mp(0, i);
      int cnt = 0;
      REP(j, 10) {
        //debug(d[i][j]);
        if (d[i][j] == INF) cnt++;
        else t.Fi += d[i][j];
      }
      if (cnt == 9) t.Fi = INF;
      ans = min(ans, t);
    }
    cout << ans.Se << " " << ans.Fi << '\n';
  }

  return 0;
}

C++: #include<iostream>

#define TOWN_MAX 11
#define ROAD_MAX 46
#define INF 1000000000

int solve(int);

int main(int argc, char const* argv[]) {
    int n;

    while (true) {
        std::cin >> n;
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

int solve(int road_num) {
    int distances[TOWN_MAX][TOWN_MAX];

    for (int i = 0; i < TOWN_MAX; i++)
        for (int j = 0; j < TOWN_MAX; j++)
            distances[i][j] = (i == j) ? 0 : INF;

    for (int i = 0; i < road_num; i++) {
        int src, dest, cost;
        std::cin >> src >> dest >> cost;
        distances[src][dest] = cost;
        distances[dest][src] = cost;
    }

    for (int infix_road = 0; infix_road < road_num; infix_road++) {
        for (int begin_town = 0; begin_town < TOWN_MAX; begin_town++) {
            for (int end_town = 0; end_town < TOWN_MAX; end_town++) {
                distances[begin_town][end_town] = std::min(distances[begin_town][end_town],
                        distances[begin_town][infix_road] + distances[infix_road][end_town]);
            }
        }
    }

    int min_cost = INF;
    int min_cost_index = 0;
    for (int i = 0; i < TOWN_MAX; i++) {
        int sum_cost = 0;
        for (int j = 0; j < TOWN_MAX; j++) {
            if (distances[i][j] == INF) break;
            sum_cost += distances[i][j];
        }

        if (sum_cost < min_cost && sum_cost != 0) {
            min_cost       = sum_cost;
            min_cost_index = i;
        }
    }

    std::cout << min_cost_index << " " << min_cost << std::endl;

    return 0;
}

C++: #include <cstring>
#include <iostream>
#include <queue>
using namespace std;

int n, m; // 道の数，街の数
int edges[10][10];

int dijkstra(int from, int to) {
    bool visited[m];
    fill(visited, visited + m, false);
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
    que.push(make_pair(0, from));
    while (!que.empty()) {
        pair<int, int> current = que.top();
        que.pop();
        
        const int dist = current.first;
        const int pos = current.second;
        
        if (pos == to) {
            return dist;
        }
        
        visited[pos] = true;
        
        for (int i = 0; i < m; i++) {
            if (!visited[i] && edges[pos][i] != 0x7f7f7f7f) {
                que.push(make_pair(dist + edges[pos][i], i));
            }
        }
    }
    return -1;
}

int main() {
    while (cin >> n, n) {
        memset(edges, 0x7f,sizeof(edges));
        
        for (int i = 0; i < n; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            edges[a][b] = edges[b][a] = c;
            m = max(a, max(b, m));
        }
        m++;
        
        int res, res_time = 0x7fffffff;
        for (int i = 0; i < m; i++) {
            int total = 0;
            for (int j = 0; j < m; j++) {
                total += dijkstra(i, j);
            }
            if (total < res_time) {
                res_time = total;
                res = i;
            }
        }
        
        cout << res << ' ' << res_time << endl;
    }
    
    return 0;
}