Maximum Matching of a Cactus
Time limit0.3sMemory limit1024 MB
Given a cactus graph as a list of edge sets (cycles or paths), find the size of its maximum matching. Each edge set is a chain of vertices.
- Level
Medium6 of 10
- Topics
- Tree, Dynamic programming, Graph
- Solved
- No attempts yet
Problem
In a graph, a matching is a subset of edges in which no two edges share an endpoint. The maximum matching is a matching with the largest number of edges.
An undirected simple connected graph is called a cactus graph if any two distinct simple cycles share at most one common vertex.
Compute the size of the maximum matching of a cactus graph.
Input
The first line contains the number of vertices () and the number of edge sets ().
Each of the next lines describes one edge set. The first number () on line is the number of vertices in the -th edge set. The next numbers are vertex numbers. Each pair of consecutive vertices in the list has an edge that belongs to the set.
Output
Print the size of the maximum matching of the cactus graph.