#P16312. [ICPC 2023 Jinan R] 我只想要…多一个…
[ICPC 2023 Jinan R] 我只想要…多一个…
Problem Description
After finishing the paper Sandpile Prediction on Structured Undirected Graphs, Xiaoqingyu wants everyone to solve more graph theory problems. “We cannot live without graph theory problems, and everyone should work on sandpile prediction problems!”
A bipartite graph is a graph that satisfies the following condition: its vertices can be divided into two disjoint sets and , such that every edge in the graph connects a vertex in and a vertex in . If the numbers of vertices in and are equal, then the graph is called a balanced bipartite graph.
A matching in an undirected graph is a set of edges in which no two edges share a common endpoint. A maximum matching is a matching that contains the largest number of edges. The matching number of a graph is the number of edges in a maximum matching of the graph.
Now, Xiaoqingyu gives you a balanced bipartite graph. You need to add exactly one edge, connecting one vertex in and one vertex in , so that the matching number of the graph increases. Find the number of ways.
Input Format
There are multiple test cases. The first line contains an integer indicating the number of test cases. For each test case:
The first line contains two integers and (), representing the number of vertices in and , and the number of edges.
In the next lines, the -th line contains two integers and (), indicating that the -th edge connects the -th vertex in and the -th vertex in . The graph may contain multiple edges.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, output one line containing one integer, representing the answer.
3
4 3
1 2
3 2
4 3
3 3
1 3
2 2
3 1
3 2
1 2
1 2
6
0
4
Hint
For the first sample test case, the matching number of the original graph is . By adding the edge , , , , , or , we can increase the matching number to . So the answer is .
For the second sample test case, the matching number of the original graph is . Clearly, we cannot increase the matching number, because all vertices are already in the matching, so the answer is .
For the third sample test case, the matching number of the original graph is . By adding the edge , , , or , we can increase the matching number to . So the answer is .
Translated by ChatGPT 5