logo AlgoBeat OnlineJudge
登录 注册

#203721. [CERC2017] Embedding Enumeration

内存限制:500 MiB 时间限制:4000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

As you probably know, a tree is a graph consisting of nodes and undirected edges in which any two nodes are connected by exactly one path. In a labeled tree each node is labeled with a different integer between and . In general, it may be hard to visualize trees nicely, but some trees can be neatly embedded in rectangular grids.

Given a labeled tree with nodes, a by embedding of is a mapping of nodes of to the cells of a rectangular grid consisting of rows and columns such that:

  • Node is mapped to the cell in the upper-left corner.
  • Nodes connected with an edge are mapped to neighboring grid cells (up, down, left or right).
  • No two nodes are mapped to the same cell.

Find the number of by embeddings of a given tree, modulo .

输入格式

The first line contains an integer — the number of nodes in . The of the following lines contains two different integers and — the endpoints of the edge.

输出格式

Output the number of by embeddings of the given tree, modulo .

样例

样例输入 1

5
1 2
2 3
2 4
4 5

样例输出 1

4

数据范围与提示

PZgNB8.png

All embeddings of the tree in the example input are given in the figure above.