#P4740. [CERC2017] Embedding Enumeration

[CERC2017] Embedding Enumeration

题目描述

As you probably know, a tree is a graph consisting of nn nodes and n1n - 1 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 11 and nn. In general, it may be hard to visualize trees nicely, but some trees can be neatly embedded in rectangular grids.

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

  • Node 11 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 22 by nn embeddings of a given tree, modulo 109+710^9 + 7.

输入格式

The first line contains an integer n(1n300000)n(1 \le n \le 300 000) — the number of nodes in GG. The jthj-th of the following n1n - 1 lines contains two different integers aja_j and bj(1aj,bjn)b_j(1 \le a_j,b_j \le n) — the endpoints of the jthj-th edge.

输出格式

Output the number of 22 by nn embeddings of the given tree, modulo 109+710^9 + 7.

题目大意

输入一棵树,求把这棵树放入 2n2*n 的网格图中的方案数,对 109+710^9+7 取模。

要求: 11 必须放在 (1,1)(1,1),有边连接的节点必须相邻,两个节点不能放在同一个格子。

5
1 2
2 3
2 4
4 5
4

提示

PZgNB8.png

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