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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <utility>
#define ll long long
const int inf=0x3f3f3f3f;
const int mod=1e6;
using namespace std;

ll a[1005];
int n;
void get_table()
{
    memset(a,0,sizeof(a));
    a[0]=a[1]=1;
    for(int i=2;i<=1000;i++)
    {
        int mid=i/2;
        for(int j=0;j<mid;j++)
            a[i]+=a[j]*a[i-1-j]*2;
        if(i&1) a[i]+=a[mid]*a[mid];
        a[i]%=(ll)mod;
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    get_table();
    while(scanf("%d",&n)&&n)
        printf("%lld\n",a[n]);
    return 0;
}
*/
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn=100;
const int INF=999999999;
int M[maxn][maxn];
void floyd(int n)
{
    for (int l=0;l<=n;l++)
    for (int k=0;k<=n;k++)
    for (int r=0;r<=n;r++)
    if (M[k][l]+M[l][r]<M[k][r])
    M[k][r]=M[k][l]+M[l][r];
}
int main()
{
    int m,a,b,num;
    while (scanf("%d",&m),m)
    {
        for (int i=0;i<=12;i++)
        for (int j=0;j<=12;j++)
        if (i!=j)
        M[i][j]=INF;
        else M[i][j]=0;
        int n=0;
        while (m--)
        {
            scanf("%d%d%d",&a,&b,&num);
            M[a][b]=min(num,M[a][b]);
            M[b][a]=M[a][b];
            n=max(n,max(a,b));
        }
        floyd(n);
        int pos,ans=INF;
        for (int i=0;i<=n;i++)
        {
            int sum=0;
            for (int j=0;j<=n;j++)if (i!=j)
                sum+=M[i][j];
            if (ans>sum)
            {
                ans=sum;
                pos=i;
            }
        }
        printf("%d %d\n",pos,ans);
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm> 

using namespace std;

const int MAX_N = 45 * 2 + 4;
const int MAX_V = 10 + 4;
const int INF = 0x3f3f3f3f;

int n;
int v;
struct Edge {
    int from;
    int to;
    int cost;
} edge[MAX_N];

int d[MAX_V];

int Bellman_Ford (int s) {
    int res = 0;
    fill(d, d + MAX_V, INF);
    d[s] = 0;
    while (true) {
        bool update = false;
        for (int i = 0; i < 2 * n; i++) {
            Edge e = edge[i];
            if (d[e.from] != INF && d[e.from] + e.cost < d[e.to]) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if (!update) {
            break;
        }        
    }
    for (int i = 0; i <= v; i++) {
        res += d[i];
    }
    return res;
}

int main() {
    while (scanf("%d", &n) && n > 0) {
        int path[MAX_V];                           
        v = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d %d %d", &edge[i].from, &edge[i].to, &edge[i].cost);
            edge[i + n].from = edge[i].to;
            edge[i + n].to = edge[i].from;
            edge[i + n].cost = edge[i].cost;
            v = max(v, edge[i].from);
            v = max(v, edge[i].to);
        }

        for (int i = 0; i <= v; i++) {
            path[i] = Bellman_Ford(i);
        }
        printf("%d %d\n", min_element(path, path + v + 1) - path, *min_element(path, path + v + 1));
    }
    return 0;    
}

C++: #include<stdio.h>
#define inf 0x3f3f3f3f
int map[11][11];
int main(void)
{
	int n;
	while(scanf("%d",&n),n!=0)
	{
		for(int i=0;i<=11;i++)
		{
			for(int j=0;j<=11;j++)
			map[i][j]=inf;
			map[i][i]=0;
		}
		int max=0;
		for(int i=0;i<n;i++)
		{
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			if(map[a][b]>c)
			{
				map[a][b]=map[b][a]=c;
			}
			if(a>max)
			max=a;
			if(b>max)
			max=b;
		}
		for(int k=0;k<=max;k++)
		for(int i=0;i<=max;i++)
		for(int 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 min=inf,k;
		for(int i=0;i<=max;i++)
		{
			int num=0;
			for(int j=0;j<=max;j++)
			num=num+map[i][j];
			if(num<min)
			{
				min=num;
				k=i;
			}
		}
		printf("%d %d\n",k,min);
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
const int INF=1e9;
struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b){}
    edge(){}
};
struct data{
    int At,cost;
    data(int a,int b):At(a),cost(b){}
    data(){}
    bool operator>(const data &d)const{
        return cost>d.cost;
    }
};
vector<vector<edge> >E;
int all;
int dijkstra(int s){
    vector<int>D(all,INF);
    priority_queue<data,vector<data>,greater<data> >Q;
    Q.push(data(s,0));
    while(!Q.empty()){
        int At=Q.top().At,cost=Q.top().cost;
        Q.pop();
        if(D[At]<cost)continue;
        D[At]=cost;
        for(int i=0;i<E[At].size();i++){
            edge e=E[At][i];
            Q.push(data(e.to,e.cost+cost));
        }
    }
    int sum=0;
    for(int i=0;i<all;i++)sum+=D[i];
    return sum;
}
int main(){
    int n;
    while(cin>>n,n){
        E.clear();
        E.resize(10);
        all=0;
        for(int i=0;i<n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            all=max(max(a,b),all);
            E[a].push_back(edge(b,c));
            E[b].push_back(edge(a,c));
        }
        all++;
        int Min=INF,p;
        for(int i=0;i<all;i++){
            int latte=dijkstra(i);
            if(Min>latte){
                Min=latte;
                p=i;
            }
        }

        cout<<p<<" "<<Min<<endl;

    }
}