21655_RankingtheCows

2022-5-16 18:20| 发布者: Hocassian| 查看: 35| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505730607099-Problem List-采集的数据-后羿采集器.html

Pro.ID

21655

Title

Ranking the Cows

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21655

AC

2

Submit

6

Ratio

33.33%

时间&空间限制

  • Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Each of Farmer John's N cows ( 1 ≤ N ≤ 1,000 ) produces milk at a different positive rate, and FJ would like to order his cows according to these rates from the fastest milk producer to the slowest.

    FJ has already compared the milk output rate for M ( 1 ≤ M ≤ 10,000 ) pairs of cows. He wants to make a list of C additional pairs of cows such that, if he now compares those C pairs, he will definitely be able to deduce the correct ordering of all N cows. Please help him determine the minimum value of C for which such a list is possible.

    输入

    Multiple test cases. For each case:

    Line 1:   Two space-separated integers: N and M

    Lines 2..M+1:   Two space-separated integers, respectively: X and Y. Both X and Y are in the range 1...N and describe a comparison where cow X was ranked higher than cow Y.

    输出

    Description

    Each of Farmer John's N cows ( 1 ≤ N ≤ 1,000 ) produces milk at a different positive rate, and FJ would like to order his cows according to these rates from the fastest milk producer to the slowest.

    FJ has already compared the milk output rate for M ( 1 ≤ M ≤ 10,000 ) pairs of cows. He wants to make a list of C additional pairs of cows such that, if he now compares those C pairs, he will definitely be able to deduce the correct ordering of all N cows. Please help him determine the minimum value of C for which such a list is possible.

    Input

    Multiple test cases. For each case:

    Line 1:   Two space-separated integers: N and M

    Lines 2..M+1:   Two space-separated integers, respectively: X and Y. Both X and Y are in the range 1...N and describe a comparison where cow X was ranked higher than cow Y.

    Output

    For each case, output one line :   A single integer that is the minimum value of C.

    Sample Input

    5 5
    2 1
    1 5
    2 3
    1 4
    3 4

    Sample Output

    3

    Hint

    From the information in the 5 test results, Farmer John knows that since cow 2 > cow 1 > cow 5 and cow 2 > cow 3 > cow 4, cow 2 has the highest rank. However, he needs to know whether cow 1 > cow 3 to determine the cow with the second highest rank. Also, he will need one more question to determine the ordering between cow 4 and cow 5. After that, he will need to know if cow 5 > cow 3 if cow 1 has higher rank than cow 3. He will have to ask three questions in order to be sure he has the rankings: "Is cow 1 > cow 3? Is cow 4 > cow 5? Is cow 5 > cow 3?"

    Source

    样例输入

    5 5
    2 1
    1 5
    2 3
    1 4
    3 4

    样例输出

    3

    提示

    From the information in the 5 test results, Farmer John knows that since cow 2 > cow 1 > cow 5 and cow 2 > cow 3 > cow 4, cow 2 has the highest rank. However, he needs to know whether cow 1 > cow 3 to determine the cow with the second highest rank. Also, he will need one more question to determine the ordering between cow 4 and cow 5. After that, he will need to know if cow 5 > cow 3 if cow 1 has higher rank than cow 3. He will have to ask three questions in order to be sure he has the rankings: "Is cow 1 > cow 3? Is cow 4 > cow 5? Is cow 5 > cow 3?"


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部