Match
Time limit1sMemory limit512 MB
Given a tree with n nodes, count the edge subsets whose remaining forest has a maximum matching size divisible by m, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, DFS, Math
- Solved
- No attempts yet
Problem
Yuta has a connected undirected graph with nodes and edges. Yuta can choose some subset of the edges in and remove them. There are possible subsets to remove.
Yuta wants to count the ways to remove edges so that the maximum matching size of the remaining graph is divisible by . The answer can be very large, so print it modulo .
An edge set is a matching if each node in is connected to at most one edge in . The maximum matching of is the matching of with the largest size.
Input
The first line contains two integers and (, ). Then lines follow, each containing two integers and that describe an edge of .
Output
Print a single integer: the answer modulo .