#P15787. [JAG 2025 Summer Camp #3] Flight Planning 2
[JAG 2025 Summer Camp #3] Flight Planning 2
题目描述
There are airports in a certain country, and the Jag Airlines Group operates flights connecting these airports. To reduce the number of airplanes required, they choose to rearrange the order of flights.
In each flight, an airplane departs from one airport and arrives at another, and each flight must be operated by exactly one airplane. We denote by a flight that departs from airport and arrives at airport .
An airplane can operate a flight only if one of the following holds:
- The airplane was initially placed at airport and has not yet operated any flight.
- The destination of its most recent operation was airport .
For example, suppose there are three flights: , , and . If they are ordered as , , and , then and can be operated by the same airplane, so the three flights can be operated by two airplanes.
You may reorder the flights arbitrarily and choose the initial placements of the airplanes arbitrarily. What is the minimum number of airplanes required to operate all the flights?
输入格式
The input consists of multiple test cases.
The first line contains an integer (), representing the number of test cases.
test cases follow. Each test case is given in the following format.
$$\begin{aligned} & N \ M \\ & a_{1} \ b_{1} \\ & \vdots \\ & a_{M} \ b_{M} \end{aligned}$$For each test case, the first line contains integers () and (), representing the number of airports and the number of flights, respectively.
The following lines each contain integers and , satisfying and . Each line describes the -th flight .
Additionally, the sum of over all test cases does not exceed , and the sum of over all test cases does not exceed .
输出格式
For each of the test cases, output the minimum number of airplanes required, one per line.
2
5 3
2 3
5 4
1 2
5 6
2 3
3 5
5 1
4 2
2 3
1 4
2
1