Simple Tree Decomposition Problem
InterviewTime limit3sMemory limit1024 MB
Count the edge subsets of a tree whose removal leaves every connected component with exactly A or B vertices, modulo 10^9+7.
- Level
Medium6 of 10
- Topics
- Tree, Dynamic programming
- Solved
- No attempts yet
Problem
BOOM! Dohoon's head exploded while he was solving the tree decomposition practice problem assigned at the Summer School on Combinatorics and Algorithms at KAIST. His brain could no longer focus on the problem, so it started idling by decomposing a tree instead of doing tree decomposition on general graphs.
Dohoon is given a tree with vertices. He decomposes the tree into a collection of connected components as follows.
- He selects zero or more edges from the tree and removes them. Let be the set of removed edges.
- After the edges in are removed, each connected component must have either or vertices.
Count the number of possible sets of edges that satisfy these conditions.
Input
The first line contains three integers , , , separated by spaces. Each of the following lines contains two integers and , separated by a space, meaning that the -th edge connects vertices and .
Output
Print the number of possible sets modulo .
Constraints
()
The given edges form a tree.