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 Scala (2.11.7) (judge verdict: Accepted)

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val (from, to) = na2(N - 1, -1)
    val g = packUGraph(N, from, to)
    val (c, diameter, radius) = centerOfTree(g)

    def calcTwoCenter(c1: Int, c2: Int): Long = {
      val depthMaxChildren = mutable.Map[Int, Long]().withDefaultValue(0)
      calcFrom(c1, depthMaxChildren, c2)
      calcFrom(c2, depthMaxChildren, c1)
      depthMaxChildren.values.product * 2
    }

    def calcOneCenter(c: Int): Long = {
      val depthMaxChildren = mutable.Map[Int, Long]().withDefaultValue(0)
      calcFrom(c, depthMaxChildren, INF)
      depthMaxChildren.values.product
    }

    def calcFrom(c: Int, depthMaxChildren: mutable.Map[Int, Long], blocked: Int): Unit = {
      val (depth, _, _) = traceBfs(g, c, blocked)
      rep(N) { i =>
        val d = depth(i)
        if (d != INF) {
          // 葉の数はノード毎に子供の数をかけていったもの
          val size = if (g(i).length == 1) 1
          else {
            // 葉でなければ子の数を数える
            var size = g(i).length
            if (d != 0) size -= 1  // ルートでなければ親の分を引く
            if (g(i).contains(blocked)) size -= 1 // blockされてるエッジを引く
            size
          }

          depthMaxChildren(d) = max(depthMaxChildren(d), size)
        }
      }
    }

    val colors = diameter / 2 + 1
    if (c.length == 2) {
      out.println(s"$colors ${calcTwoCenter(c(0), c(1))}")
    } else {
      val ms = min(g(c(0)).map(calcTwoCenter(c(0), _)).min, calcOneCenter(c(0)))
      out.println(s"$colors $ms")
    }
  }

  /**
    * すでに直径、直径のノードがわかっている場合は、直径の半分だけ親をたどればいいのでもっと楽にできる
    * @return (木の中心１こor２個, 直径, 半径)
    */
  def centerOfTree(t: Array[Array[Int]]): (Array[Int], Int, Int) = {
    val n = t.length

    var cur = 0
    var p = 0
    val queue = Array.ofDim[Int](n)
    val degree = Array.ofDim[Int](n)
    val lvl = Array.ofDim[Int](n)
    rep(n) { i =>
      degree(i) = t(i).length
      if (degree(i) == 1) {
        queue(p) = i
        p += 1
      }
    }

    while(cur < p) {
      val v = queue(cur)
      cur += 1
      rep(t(v).length) { i =>
        val u = t(v)(i)

        // parentを探す
        if (degree(u) > 0) {
          degree(u) -= 1
          if (degree(u) == 1) {
            lvl(u) = lvl(v) + 1
            queue(p) = u
            p += 1
          }
        }
      }
      degree(v) -= 1
    }

    val c1 = queue(n - 1)
    if (n >= 2 && lvl(c1) == lvl(queue(n - 2))) {
      val c2 = queue(n - 2)
      (Array(c1, c2), lvl(c1) * 2 + 1, lvl(c1) + 1)
    } else {
      (Array(c1), lvl(c1) * 2, lvl(c1))
    }
  }

  /**
    * @param n ノード数
    */
  def packUGraph(n: Int, from: Array[Int], to: Array[Int]): Array[Array[Int]] = {
    val t = new Array[Array[Int]](n)
    val p = new Array[Int](n)
    val m = from.length
    rep(m)(i => p(from(i)) += 1)
    rep(m)(i => p(to(i)) += 1)
    rep(n)(i => t(i) = new Array(p(i)))
    rep(m) { i =>
      p(from(i)) -= 1
      t(from(i))(p(from(i))) = to(i)
      p(to(i)) -= 1
      t(to(i))(p(to(i))) = from(i)
    }
    t
  }

  val INF = 1e9.toInt + 10

  /**
    * @return (depth, parent, queue)
    */
  def traceBfs(g: Array[Array[Int]], rt: Int = 0, blocked: Int): (Array[Int], Array[Int], Array[Int]) = {
    val n = g.length
    val q, p = Array.ofDim[Int](n)
    q(0) = rt
    p(rt) = -1
    val d = Array.fill[Int](n)(INF)
    d(rt) = 0
    var cur = 0
    var last = 1
    while (cur < last) {
      val v = q(cur)
      rep(g(v).length) { i =>
        val u = g(v)(i)
        if (d(u) == INF && u != blocked) {
          d(u) = d(v) + 1
          p(u) = v
          q(last) = u
          last += 1
        }
      }
      cur += 1
    }
    (d, p, q)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    rep(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    rep(n) { i =>
      rep(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    rep(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}