Hongjun and the Tree 2
Time limit2sMemory limit512 MB
Count the ways to cut edges of a tree so every remaining component has exactly one black vertex, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Tree, DFS, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
You are given a tree with vertices numbered from 0 to .
Each vertex is painted white or black, and at least one vertex of each color is guaranteed to exist.
You can choose edges of the tree () and delete them. The vertices then split into sets. Count the ways to split the tree so that every resulting set contains exactly one black vertex. The value can grow very large, so print it modulo .
Input
The first line contains the number of vertices ().
The second line contains integers (). This means there is an edge between vertex and vertex .
The third line contains integers giving the color of each vertex. If is 0, vertex is white; if it is 1, vertex is black.
Output
Print the number of valid splittings modulo on one line.