Matchings
Time limit3sMemory limit128 MB
Given a tree, compute the size of its maximum matching and count how many maximum matchings exist, modulo m.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Tree, DFS, Combinatorics
- Solved
- No attempts yet
Problem
In an undirected graph, a matching is a subset of the edges such that every vertex is incident to at most one selected edge. A maximum matching is a matching that contains as many edges as possible.
You are given a tree with nodes. Find the size of its maximum matching and the number of maximum matchings. The count must be reported modulo .
Input
The first line contains an integer , the number of nodes in the tree (). The nodes are numbered from to .
Each of the next lines describes one edge of the tree with two integers and , meaning there is an edge connecting nodes and ().
The last line contains an integer ().
Output
On the first line, print the size of a maximum matching of the tree.
On the second line, print the number of maximum matchings modulo .