#P2756. 飞行员配对方案问题

    ID: 1763 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>网络流Special JudgeO2优化二分图最大流网络流 24 题

飞行员配对方案问题

Description

There are nn pilots in total, including mm foreign pilots and (nm)(n - m) British pilots. Foreign pilots are numbered from 11 to mm, and British pilots are numbered from m+1m + 1 to nn. Given the cooperation relations between foreign and British pilots, design an algorithm to find the optimal pairing scheme so that the RAF can dispatch the maximum number of aircraft at once.

Input Format

The first line contains two positive integers separated by a space, representing the number of foreign pilots mm and the total number of pilots nn.
From the second line to the second-to-last line, each line contains two integers u,vu, v, meaning foreign pilot uu can cooperate with British pilot vv.
The last line is guaranteed to be -1 -1, indicating the end of input.

Output Format

This problem uses a Special Judge.
Output the maximum number of aircraft that can be dispatched, and provide one feasible pairing scheme.
The first line contains an integer, the maximum number of aircraft that can be dispatched at once; denote this integer by kk.
From line 22 to line k+1k + 1, each line contains two integers u,vu, v, indicating that in your scheme, foreign pilot uu is paired with British pilot vv. The pairs (u,v)(u, v) in these kk lines must be all distinct.

5 10
1 7
1 8
2 6
2 9
2 10
3 7
3 8
4 7
4 8
5 10
-1 -1

4
1 7
2 9
3 8
5 10

Hint

  • 【Constraints and Conventions】
    • For 100%100\% of the testdata, it is guaranteed that 1mn<1001 \leq m \leq n < 100, 1um<vn1 \leq u \leq m < v \leq n.

::anti-ai[The same pairing relation will be given at most once.]

  • 【Hint】
    • Note that the first line reads mm first, then nn.

Translated by ChatGPT 5