#include <iostream>
#include <string>
#include <stdio.h>
#include <stack>
#include <queue>

using namespace std;

#define INF 10000000

int main(void)
{
    int n;

    while (cin >> n, n)
    {
        int road[45][45];

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                road[i][j] = INF;
            }
        }

        int m = 0;
        for (int i = 0; i < n; i++)
        {
            int a, b, c;
            cin >> a >> b >> c;
            road[a][b] = c;
            road[b][a] = c;
            m = max(m, max(a, b));
        }

        n = m+1;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                for (int k = 0; k < n; k++)
                {
                    road[j][k] = min(road[j][k], road[j][i] + road[i][k]);
                }
            }
        }

        int min = INF;
        int min_p;
        for (int i = 0; i < n; i++)
        {
            int sum = 0;
            for (int j = 0; j < n; j++)
            {
                if (i != j && road[i][j] != INF)
                {
                    //cout << i << " " << j << " " << road[i][j] << endl;
                    sum += road[i][j];
                }
            }
            if (sum > 0 && sum < min)
            {
                min = sum;
                min_p = i;
            }
        }
        cout << min_p << " " << min << endl;
    }

    return 0;
}