#P6799. 「StOI-2」独立集
「StOI-2」独立集
Problem Description
Given an unrooted tree with nodes and paths on the tree, find the total number of "independent set" selections formed from these paths.
Since the answer may be very large, you only need to output it modulo .
An "independent set" here means a set of paths such that there does not exist a pair of paths in the set that intersect (share at least one common node) on the tree. In particular, the empty set and any set containing only one path are also independent sets.
Input Format
The first line contains two positive integers and , representing the number of nodes and the number of paths.
The next lines each contain two positive integers and , describing each edge of the tree.
The next lines each contain two positive integers and , describing each given path.
Output Format
Output one positive integer, representing the final answer.
5 3
1 2
2 3
2 4
1 5
1 5
2 3
2 4
6
Hint
Please pay attention to the impact of constant factors on the program's running time.
Constraints
For of the testdata: , .
For of the testdata: , .
For another of the testdata: .
For another of the testdata: .
For another of the testdata: .
For of the testdata: .
Translated by ChatGPT 5