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++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,n) for(int i=1;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl

using namespace std;
int n;
int s[11]={0};
int d[11][11]={0};
void warshall_floyd(){
	for(int k=0;k<10;k++){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
				}
					
			
		}
	}
	
}
int main(){
	
	int a,b,c;
	while(cin>>n,n!=0){
	
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			if(i!=j)
				d[i][j]=999999;
			else
				d[i][j]=0;
		}
	}
	
	for(int i=0;i<n;i++){
		cin>>a>>b>>c;
		d[a][b]=c;
		d[b][a]=c;
	}
	
	warshall_floyd();
	
	int it=0;
	int min=999999;
	rep(i,10){
		int sum=0;
		bool f=false;
	rep(j,10){
		if(i!=j&&d[i][j]!=999999){
			f=true;
		sum+=d[i][j];
		}
		
	}
		
		if(f&&sum<min){
			it=i;
			min=sum;
		}
	}
	
	cout<<it<<" "<<min<<endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
struct edge{int to;int cost;};
typedef pair<int,int> P;
const int Inf=1e7;
int N;
int A,B,C;
vector<edge>X[10];
int d[10];
int cou;
int main()
{
	while(true){

		int ans1=0,ans2=Inf;
		cou=0;
		scanf("%d",&N);
		if(N==0)break;
		for(int i=0;i<N;i++){
			scanf("%d%d%d",&A,&B,&C);
			edge e1={B,C};
			X[A].push_back(e1);
			edge e2={A,C};
			X[B].push_back(e2);
			cou=max(cou,max(A,B));
		}
		for(int s=0;s<=cou;s++){
			for(int i=0;i<=cou;i++)d[i]=Inf;
			d[s]=0;
			priority_queue<P, vector<P>, greater<P> > que;
			que.push(make_pair(0,s));
			while(!que.empty()){
				P p=que.top();que.pop();
				int v=p.second;
				if(d[v]<p.first)continue;
				for(int i=0;i<X[v].size();i++){
					edge e=X[v][i];
					if(d[e.to]>d[v]+e.cost){
						d[e.to]=d[v]+e.cost;
						que.push(make_pair(d[e.to],e.to));
					}
				}
			}
			//for(int i=0;i<=cou;i++)printf("%d %d %d\n",s,i,d[i]);
			int sum=0;
			for(int i=0;i<=cou;i++)sum+=d[i];
			if(ans2>sum){
				ans2=sum;
				ans1=s;
			}
		}
		printf("%d %d\n",ans1,ans2);
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <cmath>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int dir[9][2] = { 0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1, 0, 0 };
const ll  ll_inf = 0x7fffffff;
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
const int inf = 0x3f3f3f;
const int mod = (int) 998244353;
const int Max = (int) 45 + 22;
stringstream ss;

/**********************************************Head-----Template****************************************/
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}

/********************************Head----Temlate**********************************************/

//tools:
//priority_queue <int, vector<int>, greater<int> > Q;
//ios::sync_with_stdio(false);
//freopen("input.txt", "r", stdin);
//ss<<int; ss>>str;

int n, maxx;
int Map[Max][Max];

void Init() {
	maxx = -1;
	for (int i = 0; i <= 45; ++i)
		for (int j = 0; j <= 45; ++j) 
			Map[i][j] = Map[j][i] = (i == j) ? 0 : inf;	
}

void Floyd() {
	for (int i = 0; i <= maxx; ++i) {
		for (int j = 0; j <= maxx; ++j) {
			for (int k = 0; k <= maxx; ++k) {
				Map[i][k] = min(Map[i][k], Map[i][j] + Map[j][k]);
			}
		}
	}
}

int main() {
	
	while (scanf("%d", &n) && n) {
		
		int a, b, c;
		Init();
		for (int i = 0; i < n; ++i) {
			scanf("%d %d %d", &a, &b, &c);
			maxx = max(maxx, a);
			maxx = max(maxx, b);
			Map[a][b] = Map[b][a] = min(c, Map[b][a]);
		}
		
		Floyd();
		int ans = inf;
		int index = -1;
		for (int i = 0; i <= maxx; ++i) {
			int sum = 0;
			for (int j = 0; j <= maxx; ++j) {
				sum += Map[i][j];
			}
			if (sum < ans) {
				ans = sum;
				index = i;
			}
		}
		
		printf("%d %d\n", index, ans);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

const int INF=1<<21;

int main()
{
	int n;
	int f=0;
	while(cin>>n,n)
	{
		if(f)cout<<endl;
		f=1;
		int m[10][10]={};
		for(int i=0;i<10;i++)for(int j=0;j<10;j++)if(i!=j)m[i][j]=INF;
		int a,b,w,maxn=0;
		for(int i=0;i<n;i++)
		{
			cin>>a>>b>>w;
			m[a][b]=m[b][a]=w;
			maxn=max(maxn,max(a,b));
		}
		maxn++;
		for(int k=0;k<maxn;k++)
			for(int i=0;i<maxn;i++)
				for(int j=0;j<maxn;j++)
					m[i][j]=min(m[i][j],m[i][k]+m[k][j]);
		
		int d[10];
		for(int i=0;i<maxn;i++)d[i]=0;
		for(int i=0;i<maxn;i++)
		{
			for(int j=0;j<maxn;j++)
			{
				d[i]+=m[i][j];
			}
		}
		int mini=0,mind=INF;
		for(int i=0;i<maxn;i++)
		{
			if(mind>d[i])
			{
				mini=i;
				mind=d[i];
			}
		}
		cout<<mini<<" "<<d[mini];
	}
	return 0;
}