#P6799. 「StOI-2」独立集

「StOI-2」独立集

Problem Description

Given an unrooted tree with nn nodes and mm paths on the tree, find the total number of "independent set" selections formed from these mm paths.

Since the answer may be very large, you only need to output it modulo 998,244,353998,244,353.

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 nn and mm, representing the number of nodes and the number of paths.
The next n1n - 1 lines each contain two positive integers uiu_{i} and viv_{i}, describing each edge of the tree.
The next mm lines each contain two positive integers aia_{i} and bib_{i}, 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 10%10\% of the testdata: 1n101 \leq n \leq 10, 1m101 \leq m \leq 10.
For 20%20\% of the testdata: 1n1001 \leq n \leq 100, 1m1001 \leq m \leq 100.
For another 30%30\% of the testdata: 1m151 \leq m \leq 15.
For another 10%10\% of the testdata: 1n,m1051 \leq n, m \leq 10^{5}.
For another 20%20\% of the testdata: ui=i,vi=i+1u_{i} = i, v_{i} = i + 1.
For 100%100\% of the testdata: 1n,m5×1051 \leq n, m \leq 5 \times 10^{5}.

Translated by ChatGPT 5