Connected Subgraph
Time limit1sMemory limit256 MB
Count the ways to delete some edges from a tree plus k extra edges so the remaining graph stays connected, modulo 998244353.
- Level
Hard9 of 10
- Topics
- Tree, Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
Rikka draws a tree with vertices labeled and adds extra edges to it. Count the ways she can remove zero or more edges so that the remaining graph stays connected, modulo .
Input
The first line contains two integers and (, ). Each of the next lines contains two integers and , a tree edge between vertices and (). Each of the last lines contains two integers and , an extra edge between vertices and (). The tree edges form a tree. The resulting graph has no self-loops and no parallel edges.
Output
Print one integer: the number of ways to remove zero or more edges so that the graph remains connected, modulo .