import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  val mod = 1000000
  val n = readInt()
  val combination = Array.tabulate(n + 1){i ⇒ Array.fill(i + 1){1}}
  for (i ← 2 to n) {
    for (j ← 1 until i) {
      combination(i)(j) = (combination(i - 1)(j - 1) + combination(i - 1)(j)) % mod
    }
  }
  val winCount = Array.fill(n){0}
  val loseBy = Array.fill(n){-1}
  for (_ ← 1 until n){
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt - 1)
    winCount(a) += 1
    loseBy(b) = a
  }
  val pattern = Array.fill(n){1L}
  val matchCount = Array.fill(n){0}
  val queue = mutable.Queue[Int](winCount.indices.filter(i ⇒ winCount(i) == 0):_*)
  while(queue.nonEmpty) {
    val i = queue.dequeue()
    if (loseBy(i) != -1) {
      matchCount(i) += 1
      pattern(loseBy(i)) = pattern(loseBy(i)) * pattern(i) % mod * combination(matchCount(i) + matchCount(loseBy(i)))(matchCount(i)) % mod
      matchCount(loseBy(i)) += matchCount(i)
      winCount(loseBy(i)) -= 1
      if (winCount(loseBy(i)) == 0) {
        queue.enqueue(loseBy(i))
      }
    }
  }
  println(pattern(loseBy.indexOf(-1)))
}
