#P2170. 选学霸

    ID: 1152 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划,dp并查集洛谷原创背包概率论,统计

选学霸

Description

The teacher wants to select mm students out of nn to be top students, but there are kk pairs of students who are equally strong. If, among students of equal strength, some are selected while others are not, the class will protest. Therefore, the teacher asks you to determine how many top students he should select so that there is no protest and the number is as close as possible to the original mm.

Input Format

The first line contains three positive integers n,m,kn, m, k.

The next kk lines each contain 22 numbers, representing the IDs of a pair of equally strong students (IDs are 1,2,,n1, 2, \cdots, n).

Output Format

Output a single line: the number of top students to select such that there is no protest and the number is as close as possible to the original mm.

If there are two options whose absolute difference from mm is the same, choose the smaller one.

4 3 2
1 2
3 4
2

Hint

For 100%100\% of the testdata, it holds that $1 \le n \le 2 \times 10^4, 0 \le m \le n, 0 \le k \le 2 \times 10^4$.

Translated by ChatGPT 5