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 N, M;
int d[15][15];

bool read() {
  cin >> M;
  if (M == 0) return false;
  for (int i = 0; i <= 10; i++) {
    for (int j = 0; j <= 10; j++) {
      d[i][j] = 1<<20;
    }
    d[i][i] = 0;
  }
  N = 0;
  int s, e, m;
  for (int i = 0; i < M; i++) {
    cin >> s >> e >> m;
    d[s][e] = m;
    d[e][s] = m;
    N = max(N, s);
    N = max(N, e);
  }
  return true;
}

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

void solve() {
  floyd(N+1);
  int dmin = 1<<20, idx = 0;
  for (int i = 0; i <= N; i++) {
    int dis = 0;
    for (int j = 0; j <= N; j++) {
      dis += d[i][j];
    }
    if (dis < dmin) dmin = dis, idx = i;
  }
  cout << idx << ' ' << dmin << endl;
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (read()) {
    solve();
  }
  return 0;
}

C++: 6     
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0xfffffff
using namespace std;
int map[1100][1100];
int main()
{
	int n,m,k,i,j,a,b,c,sum1;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<1100;i++)
		for(j=0;j<1100;j++)
		{
			map[i][j]=INF;
			map[i][i]=0;
		}
		int Max=0;
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			Max=max(Max,a);
			Max=max(Max,b);
			map[a][b]=c;
			map[b][a]=c;
		}
		for(k=0;k<=Max;k++)
		for(i=0;i<=Max;i++)
		for(j=0;j<=Max;j++)
		{
			if(map[i][j]>map[i][k]+map[k][j])
			map[i][j]=map[i][k]+map[k][j];
		}
		int sum=INF;
		int ans=0;
		for(i=0;i<=Max;i++)
		{
			sum1=0;
			for(j=0;j<=Max;j++)
		    {
			   sum1+=map[i][j];
		    }
		    if(sum1<sum)
			{
				sum=sum1;
				ans=i;
			}
		}
		printf("%d %d\n",ans,sum);
	}
	return 0;
}

C++: #include<algorithm>
#include<stdio.h>
#include<vector>
#include<queue>

using namespace std;

int C = 0;
int N = 0;
int R[10][10] = { 0 };
int M[10] = { 0 };

bool solve() {
	int sum = INT_MAX,ans = 0;
	for (int i = 0; i <= C; i++) {
		queue<int> q;
		q.push(i);
		M[i] = 0;
		while (!q.empty()) {
			for (int j = 0; j <= C; j++) {
				if (R[q.front()][j] != -1 && (M[j] == -1 || M[q.front()] + R[q.front()][j] < M[j])) {
					
					M[j] = R[q.front()][j] + M[q.front()];
					q.push(j);
				}
			}
			q.pop();
		}
		int s = 0;
		for (int j = 0; j <= C; j++)
			s += M[j];
		if (sum > s) {
			sum = s;
			ans = i;
		}
		memset(M, -1, sizeof(int) * 10);
	}
	printf("%d %d\n", ans,sum);
}

int main(void) {
	int n = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		C = 0;
		memset(R, -1, sizeof(int) * 100);
		memset(M, -1, sizeof(int) * 10);
		scanf("%d", &N);
		for (int j = 0; j < N; j++) {
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			R[a][b] = c;
			R[b][a] = c;
			C = max(C, max(a, b));
		}
		solve();
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <climits> // int ???????????§????????????????????????
#include <map>
using namespace std;
const int MAX_V = 1000; // ???????????°????????§???
const int MAX_E = 2000; // ????????°????????§???
const int INF = INT_MAX; // ???????????§?????????(int ???????????§???)


struct E {
  int to, cost;
  E(int t, int c) : to(t), cost(c) {};
};

int v; // ????????°
vector<E> g[MAX_V]; // ??£??\?????????
int d[MAX_V]; // ??????s ????????????????????¢

// ?????????????????????????????????????????????????????????
// ??????????????????????????°true???????????°false ?????????
bool bellmanford(int s)
{
  // ??????
  fill(d, d + v, INF);
  d[s] = 0;
  // ??????s ??????????????¨???k+1 ???????????????????????????????????¢???
  for(int k = 0; k < v; ++k){
    // ??????1 ?????????????????¨???
    for(int j = 0; j < v; ++j){
      int from = j;
      // ??????????§??????¨????????¨???????????????????????????????????????
      for(int i = 0; i < g[from].size(); ++i){
	int to = g[from][i].to;
	int cost = g[from][i].cost;
	// ???????????¢??¨??????????????´???
	if(d[from] != INF && d[to] > d[from] + cost){
	  d[to] = d[from] + cost;
	  // ????????????????????¨??????????????°?????????????????????????????????????????????
	  // ???????????£??????v ???????????????????????¢????????????????????????????????°????????????????????¨
	  if(k == v - 1)return false;
	}
      }
    }
  }
  // ?????????????????????????????°????????????????????¨??????????????¨?????????
  return true;
}
int main()
{
  for(;;){
    // ??\??????????????????gv ??????????????°???ge ???????????°???gr ????§????
    int gv, ge, gr;
    cin >> ge;
    if(!ge){return 0;}
    set<int> s;

    for(int i = 0; i < ge; ++i){
      // ??\??????????????????gs ??????????§???????gt ??????????????????gd ???????????????
      int gs, gt, gd;
      cin >> gs >> gt >> gd;
      g[gs].push_back(E(gt, gd)); // 2 ???????????????????????±????¨????
      g[gt].push_back(E(gs,gd));
      s.insert(gs);
      s.insert(gt);
    }

    gv=s.size();
    v = gv;

    vector<pair<int,int> > p(s.size());

    set<int>::iterator it= s.begin();

    int count=0;
    while(it!=s.end()){
      bellmanford(*it);
      int sum=0;
      for(int i=0;i<v;i++){sum+=d[i];}
      //cout << sum << ":" << *it << endl;
      p[count].first=sum;
      p[count].second=*it;
      it++;
      count++;
    }

    sort(p.begin(),p.end());
  
    //for(int i=0;i<p.size();i++)
    cout << p[0].second << " " << p[0].first << endl;
  }
  
}