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 Haskell (GHC 7.10.3) (judge verdict: Wrong Answer)

import Control.Applicative
import Data.List
import Data.Maybe
import Data.Ord
import qualified Data.Map as M
import qualified Data.Set as S

import Debug.Trace

type NodeMap = M.Map Int (S.Set Int)

-- pairのリストを整理する
-- [[x, y],...] 
normalize_pair :: [[Int]] -> [(Int, Int)]
normalize_pair [] = []
normalize_pair ([x,y]:rest) = (x, y):(y,x):(normalize_pair rest)

-- pairのリストを第1要素でソート
sort_pair :: [(Int, Int)] -> [(Int, Int)]
sort_pair l = sortBy (comparing fst) l

-- createTree' はsortされたpairのリストをもらって木を作る前段階の
-- 以下のようなリストに変換します
-- [(x1, y11), (x1, y12),...,  (x2, y21), (x2, y22),...]
-- → [(x1, [y11, y12,...]), (x2, [y21, y22,...]), ...]
createTree' :: [(Int, Int)] -> [(Int, [Int])]
createTree' [] = []
createTree' ((x,y):rest) = ct' x [y] rest 
    where
        ct' x y_list [] = [(x, y_list)]
        ct' x y_list ((x', y'):rest)
            | x == x'   = ct' x (y':y_list) rest
            | otherwise = (x, y_list):(ct' x' [y'] rest)

-- [(x1, [y11, y12,...]),]の形のリストをもらって
-- x1から集合{y1, y2,..}へのマップを作成します
convertTree :: [(Int, [Int])] -> NodeMap
convertTree l = M.fromList $ map (\(x, yl)->(x, S.fromList yl)) l

-- 木はノード番号からつながっているノード番号の集合へのマップで表す
createTree :: [[Int]] -> NodeMap
createTree = convertTree . createTree' . sort_pair . normalize_pair

-- 木から葉のみ残したマップを求める
leafOf :: M.Map Int (S.Set Int) -> NodeMap
leafOf tree = M.filter (\s->(S.size s) == 1) tree

-- マップから隣接したノードのうち自身に含まないインデックスの集合を求める
nextNodeOf :: NodeMap -> S.Set Int
nextNodeOf map = S.filter ((flip M.notMember) map) $ S.unions $ M.elems map

-- 集合から条件を満たす要素を数える
countIf :: (a->Bool) -> S.Set a -> Int
countIf pred set = S.foldl f 0 set
    where
        f count x = if pred x then count + 1 else count

-- 親を指定してxの子を求める
child :: NodeMap -> Int -> Int -> [Int]
child tree parent x = filter (parent /=) $ S.elems (tree M.! x)

-- 与えられたノードから最も遠いノード(の一つ)とそのノードまでの距離を求める
farthest :: NodeMap -> Int -> (Int, Int)
farthest tree x = farthest' (-1) x
    where
        farthest' exclude x =
            case child tree exclude x of
                [] -> (x, 0)
                next_nodes -> (node, distance+1)
                    where
                        (node, distance) = maximumBy (comparing snd) $ map (farthest' x) next_nodes

-- 木の直径を求める
-- もっとも遠い点の組とその距離を返す
diameter :: NodeMap -> (Int, Int, Int)
diameter tree = (x, y, d)
    where
        (x, _) = farthest tree 1
        (y, d) = farthest tree x

findMaybe :: (a -> Maybe b) -> [a] -> Maybe b
findMaybe f [] = Nothing
findMaybe f (head:rest) = maybe (findMaybe f rest) Just (f head)

-- ある点から指定の距離だけ離れた点を求める
findAtDistance :: NodeMap -> Int -> Int -> Maybe Int
findAtDistance tree distance point = findAtDistance' distance (-1) point
    where
        findAtDistance' 0 _ p = Just p
        findAtDistance' d exclude p = 
            case child tree exclude p of
                [] -> Nothing
                next_nodes -> findMaybe (findAtDistance' (d - 1) p) next_nodes

-- 木の中心と中心からの高さを求める
center :: NodeMap -> ([Int], Int)
center tree = case diameter tree of
    (x, y, d) -> (map (fromJust . (findAtDistance tree r)) c, r)
        where
            c = if d `mod` 2 == 0 then [x] else [x, y]
            r = d `div` 2

categorizeWith :: Ord b => (a -> b) -> [a] -> [(b, [a])]
categorizeWith f l = categorizeWith' $ sortBy (comparing f) l 
    where
        categorizeWith' [] = []
        categorizeWith' (x:rest) = cw (f x) [x] rest
        cw f_x l [] = [(f_x, l)]
        cw f_x l (x':r')
                | f_x == f_x' = cw f_x (x':l) r'
                | otherwise   = (f_x, l):(cw f_x' [x'] r')
            where
                f_x' = f x'


radiusNodeListFrom :: NodeMap -> Int -> Int -> Int -> [(Int, Int)]
radiusNodeListFrom tree r parent x = (r, x):rest
    where
        rest = foldl (++) [] $ map (radiusNodeListFrom tree (r+1) x) $ child tree parent x

categorizeByRadius :: NodeMap -> [Int] -> [(Int, [Int])]
categorizeByRadius tree centers = map (\(c, v)->(c, map snd v)) $ categorizeWith fst $ concatMap rf px
    where
        rf (parent, x) = radiusNodeListFrom tree 0 parent x
        px = case centers of
            [x]    -> [(-1, x)]
            [x, y] -> [(x, y), (y, x)]

countLeaf :: NodeMap -> [Int] -> Int
countLeaf tree centers = factor * (foldr (*) 1 $ map max_childs nodes_list)
    where
        factor = case centers of
            [x] -> 1
            _   -> 2
        max_childs (h, l) = maximum $ map f l
            where
                f x' = case S.size (tree M.! x') of
                    1 -> 1
                    n -> if (h == 0) && (factor == 1) then n else n - 1 -- 中心が1つのときだけ特別
        nodes_list = categorizeByRadius tree centers

main :: IO ()
main = do
    n <- readLn
    pairs <- mapM (\_ -> map read . words <$> getLine) [1..n-1] :: IO [[Int]]
    let
        tree = createTree pairs
        (centers, r) = center tree
    let
        leaf_count = minimum $ map (countLeaf tree) centers_list
            where
                centers_list = case centers of
                    [x] -> [x] : (map ((flip (:)) [x]) (S.elems (tree M.! x)))
                    _   -> [centers]
    putStrLn $ (show (r + 1)) ++ " " ++ (show leaf_count)