301345: CF251E. Tree and Table

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Tree and Table

题意翻译

小彼佳非常喜欢树。最近,他的母亲给了他一棵有 $2n$ 个节点的树。Petya立即决定将这棵树放置在一个2行n列的矩形表上,以满足以下条件: 表的每个单元格对应一个树节点,反之亦然,每个树节点对应一个表单元格。 如果两个树节点由一条边连接,则相应的单元格有一条公共边。 现在彼佳想知道有多少方法可以把他的树放在桌子上。如果在这两个位置中有一个树节点对应于不同的表格单元格,那么他就称这两个位置是不同的。因为大的数字会吓到Petya,所以打印出对 $1000000007$ 取模的答案。 第一行包含一个整数 $n (1 <=n <= 105)$。下一行$(2n - 1)$包含两个整数,每个$a_i$ 和 $b_i$ ;$(1 < = ai, b;< = 2 n)$ 为相应边连接的顶点的数量。考虑用从1到2n的整数对树顶点进行编号。保证输入中给定的图是树,即连通无环无向图。数据保证$A_i$ 不等于 $b_i$。

题目描述

Little Petya likes trees a lot. Recently his mother has presented him a tree with $ 2n $ nodes. Petya immediately decided to place this tree on a rectangular table consisting of 2 rows and $ n $ columns so as to fulfill the following conditions: 1. Each cell of the table corresponds to exactly one tree node and vice versa, each tree node corresponds to exactly one table cell. 2. If two tree nodes are connected by an edge, then the corresponding cells have a common side. Now Petya wonders how many ways are there to place his tree on the table. He calls two placements distinct if there is a tree node which corresponds to distinct table cells in these two placements. Since large numbers can scare Petya, print the answer modulo $ 1000000007 $ $ (10^{9}+7) $ .

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1<=n<=10^{5} $ ). Next $ (2n-1) $ lines contain two integers each $ a_{i} $ and $ b_{i} $ $ (1<=a_{i},b_{i}<=2n; a_{i}≠b_{i}) $ that determine the numbers of the vertices connected by the corresponding edge. Consider the tree vertexes numbered by integers from $ 1 $ to $ 2n $ . It is guaranteed that the graph given in the input is a tree, that is, a connected acyclic undirected graph.

输出格式


Print a single integer — the required number of ways to place the tree on the table modulo $ 1000000007 $ $ (10^{9}+7) $ .

输入输出样例

输入样例 #1

3
1 3
2 3
4 3
5 1
6 2

输出样例 #1

12

输入样例 #2

4
1 2
2 3
3 4
4 5
5 6
6 7
7 8

输出样例 #2

28

输入样例 #3

2
1 2
3 2
4 2

输出样例 #3

0

说明

Note to the first sample (all 12 variants to place the tree on the table are given below): `<br></br>1-3-2 2-3-1 5 4 6 6 4 5<br></br>| | | | | | | | | | | |<br></br>5 4 6 6 4 5 1-3-2 2-3-1<br></br><br></br>4-3-2 2-3-4 5-1 6 6 1-5<br></br> | | | | | | | |<br></br>5-1 6 6 1-5 4-3-2 2-3-4<br></br><br></br>1-3-4 4-3-1 5 2-6 6-2 5<br></br>| | | | | | | |<br></br>5 2-6 6-2 5 1-3-4 4-3-1<br></br>`

Input

题意翻译

小彼佳非常喜欢树。最近,他的母亲给了他一棵有 $2n$ 个节点的树。Petya立即决定将这棵树放置在一个2行n列的矩形表上,以满足以下条件: 表的每个单元格对应一个树节点,反之亦然,每个树节点对应一个表单元格。 如果两个树节点由一条边连接,则相应的单元格有一条公共边。 现在彼佳想知道有多少方法可以把他的树放在桌子上。如果在这两个位置中有一个树节点对应于不同的表格单元格,那么他就称这两个位置是不同的。因为大的数字会吓到Petya,所以打印出对 $1000000007$ 取模的答案。 第一行包含一个整数 $n (1 <=n <= 105)$。下一行$(2n - 1)$包含两个整数,每个$a_i$ 和 $b_i$ ;$(1 < = ai, b;< = 2 n)$ 为相应边连接的顶点的数量。考虑用从1到2n的整数对树顶点进行编号。保证输入中给定的图是树,即连通无环无向图。数据保证$A_i$ 不等于 $b_i$。

加入题单

算法标签: