Problem:
Score : 1100 points

Problem Statement

Coloring of the vertices of a tree G is called a good coloring when, for every pair of two vertices u and v painted in the same color, picking u as the root and picking v as the root would result in isomorphic rooted trees.

Also, the colorfulness of G is defined as the minimum possible number of different colors used in a good coloring of G.

You are given a tree with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. We will construct a new tree T by repeating the following operation on this tree some number of times:

Add a new vertex to the tree by connecting it to one of the vertices in the current tree with an edge.

Find the minimum possible colorfulness of T.
Additionally, print the minimum number of leaves (vertices with degree 1) in a tree T that achieves the minimum colorfulness.

Notes

The phrase "picking u as the root and picking v as the root would result in isomorphic rooted trees" for a tree G means that there exists a bijective function f_{uv} from the vertex set of G to itself such that both of the following conditions are met:

f_{uv}(u)=v

For every pair of two vertices (a,b), edge (a,b) exists if and only if edge (f_{uv}(a),f_{uv}(b)) exists.

Constraints

2 \leq N \leq 100

1 \leq a_i,b_i \leq N(1\leq i\leq N-1)

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

Print two integers with a space in between.
First, print the minimum possible colorfulness of a tree T that can be constructed.
Second, print the minimum number of leaves in a tree that achieves it.

It can be shown that, under the constraints of this problem, the values that should be printed fit into 64-bit signed integers.

Sample Input 1

5
1 2
2 3
3 4
3 5

Sample Output 1

2 4

If we connect a new vertex 6 to vertex 2, painting the vertices (1,4,5,6) red and painting the vertices (2,3) blue is a good coloring.
Since painting all the vertices in a single color is not a good coloring, we can see that the colorfulness of this tree is 2.
This is actually the optimal solution. There are four leaves, so we should print 2 and 4.

Sample Input 2

8
1 2
2 3
4 3
5 4
6 7
6 8
3 6

Sample Output 2

3 4

Sample Input 3

10
1 2
2 3
3 4
4 5
5 6
6 7
3 8
5 9
3 10

Sample Output 3

4 6

Sample Input 4

13
5 6
6 4
2 8
4 7
8 9
3 2
10 4
11 10
2 4
13 10
1 8
12 1

Sample Output 4

4 12

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        public int N, M;
        public Graph G;

        public void Run()
        {
            N = Input.ReadInt();
            G = new Graph(N);
            for (int i = 0; i < N - 1; i++)
            {
                var line = Input.ReadIntArray();
                int a = line[0] - 1;
                int b = line[1] - 1;
                G[a].Edges.Add(new Edge(a, b, 0));
                G[b].Edges.Add(new Edge(b, a, 0));
            }


            // それぞれ、一番遠い葉への距離
            var D = new int[N];
            for (int i = 0; i < N; i++)
            {
                D[i] = Dist(i);
            }

            // 色は最大距離に同じ
            int colors = D.Max() - D.Min() + 1;

            // 中心の候補（１か２種類）
            var cand = new List<int>();
            for (int i = 0; i < N; i++)
            {
                if(D[i] == D.Min()) cand.Add(i);
            }

            if (cand.Count == 2)
            {
                int leaves = Math.Max(LeavesEq(cand[0], cand[1]), LeavesEq(cand[1], cand[0])) * 2;
                Console.WriteLine("{0} {1}", colors, leaves);
            }
            else
            {
                // N >= 2

                // 自分から対称に広げる
                int leaves = LeavesEq(cand[0], -1);

                // 自分ともう一つから対称に広げる
                foreach (var e in G[cand[0]].Edges)
                {
                    int l = Math.Max(LeavesEq(cand[0], e.To), LeavesEq(e.To, cand[0])) * 2;
                    leaves = Math.Min(leaves, l);
                }
                Console.WriteLine("{0} {1}", colors, leaves);
            }

        }

        // 一番遠い葉への距離
        public int Dist(int x)
        {
            return DfsDist(x, -1);
        }

        public int DfsDist(int x, int fr)
        {
            int ret = 0;
            foreach (var e in G[x].Edges)
            {
                if(fr != e.To) ret = Math.Max(DfsDist(e.To, e.From) + 1, ret);
            }
            return ret;
        }

        // 片方をカットした場合、対称になるための葉の数（最低でも１）
        public int LeavesEq(int x, int cut)
        {
            return DfsLeavesEq(x, cut);
        }

        public int DfsLeavesEq(int x, int fr)
        {
            var lst = new List<int>();
            foreach (var e in G[x].Edges)
            {
                if (fr != e.To) lst.Add(DfsLeavesEq(e.To, e.From));
            }

            if (lst.Count == 0) return 1;
            return lst.Max() * lst.Count;
        }
    }

    // libs ----------
    internal class Graph
    {
        public List<Node> Nodes;

        public Node this[int i]
        {
            set { Nodes[i] = value; }
            get { return Nodes[i]; }
        }

        public Graph(int N)
        {
            Nodes = new List<Node>();
            for (int i = 0; i < N; i++)
            {
                Nodes.Add(new Node(i));
            }
        }

    }

    internal class Node
    {
        public List<Edge> Edges;
        public int Dist;
        public int No;

        public Node(int no)
        {
            this.No = no;
            Dist = int.MaxValue;
            Edges = new List<Edge>();
        }
    }

    internal class Edge
    {
        public int From;
        public int To;
        public int Cost;

        public Edge(int fr, int to, int cost = 0)
        {
            From = fr;
            To = to;
            Cost = cost;
        }

    }

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}