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: Accepted)

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)
            {
                long leaves = CountLeaves.Run(G, cand[0], cand[1]);
                Console.WriteLine("{0} {1}", colors, leaves);
            }
            else
            {
                // N >= 2

                // 自分から対称に広げる
                long leaves = CountLeaves.Run(G, cand[0]);

                // 自分ともう一つから対称に広げる
                foreach (var e in G[cand[0]].Edges)
                {
                    long l = CountLeaves.Run(G, cand[0], e.To);
                    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;
        }

    }

    internal class CountLeaves
    {
        public Graph G;
        public long[] Degrees;

        public static long Run(Graph G, int c)
        {
            var CL = new CountLeaves();
            CL.G = G;
            CL.Degrees = new long[100];
            CL.Count(c, -1, 0);

            long ret = 1;
            for (int i = 0; i < CL.Degrees.Length; i++)
            {
                if (CL.Degrees[i] != 0) ret *= CL.Degrees[i];
            }
            return ret;
        }

        public static long Run(Graph G, int c1, int c2)
        {
            var CL = new CountLeaves();
            CL.G = G;
            CL.Degrees = new long[100];
            CL.Count(c1, c2, 0);
            CL.Count(c2, c1, 0);

            long ret = 1;
            for (int i = 0; i < CL.Degrees.Length; i++)
            {
                if (CL.Degrees[i] != 0) ret *= CL.Degrees[i];
            }

            ret *= 2;
            return ret;
        }

        public void Count(int x, int cut, int d)
        {
            var edges = G[x].Edges.Where(e => e.To != cut).ToArray();
            Degrees[d] = Math.Max(Degrees[d], edges.Length);

            foreach (var e in edges)
            {
                Count(e.To, e.From, d+1);
            }
        }
    }

    // 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();
        }
    }
}