#include <stdio.h>

#define TEST 0
int weakdist(int tc[10][10],int town,int from,int to)
{
    if(from ==to)
        return 0;
    if(tc[from][to] >= 0)
        return tc[from][to];
    return -1;
}

int dist(int tc[10][10],int town,int from,int to)
{
    if(from ==to)
        return 0;
    if(tc[from][to] >= 0)
        return tc[from][to];
    int mindist=-1;
    for(int via=0;via<town;via++)
    {
        if(via == from || via ==to)
            continue;
        if(tc[from][via] == -1 || tc[via][to]==-1)
            continue;
        int sumdist=dist(tc,town,from,via)
        +dist(tc,town,via,to);
        if(mindist < 0 || mindist > sumdist)
            mindist=sumdist;
    }
    tc[from][to]=mindist;
    tc[to][from]=mindist;
    return mindist;
}
void dump(int tc[10][10])
{
    
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++)
            {
                printf("%d ",tc[i][j]);
            }
            puts("");
        }
}

int main(void)
{
    int n;
    int tc[10][10];//connections between towns
    while(scanf("%d",&n) == 1 && n != 0)
    {
        int town=0;
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++)
            {
                tc[i][j]=-1;
            }
            tc[i][i]=0;
        }
        for(int k=0;k<n;k++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            if(a==b)
                continue;
            tc[a][b]=c;
            tc[b][a]=c;
            if(town <a+1)town=a+1;
            if(town <b+1)town=b+1;
        }
#if TEST
        printf("town.num=%d\n",town);
#endif
        int minsum=-1;
        int minnum=-1;
        for(int cnt=0;cnt <10000;cnt++)
        {
            for(int i=0;i<town;i++)
            {   
                for(int j=0;j<town;j++)
                {
                    dist(tc,town,i,j);
                }
            }
        }//try calculating for setting the map.
        for(int i=0;i<town;i++)
        {
            int sum=0;
            for(int j=0;j<town;j++)
            {
                sum+=dist(tc,town,i,j);
            }
            if(minsum<0 || minsum >sum)
            {
                minsum=sum;
                minnum=i;
            }
        }
#if TEST
        dump(tc);
#endif
        printf("%d %d\n",minnum,minsum);
    }
    return 0;

}