22833_PopularCows

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

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

Pro.ID

22833

Title

Popular Cows

Title链接

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

AC

23

Submit

109

Ratio

21.10%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 ≤ N ≤ 10,000) cows, you are given up to M (1 ≤ M ≤ 50,000) ordered pairs of the form (A, B) that tell you that cow A thinks that cow B is popular. Since popularity is transitive, if A thinks B is popular and B thinks C is popular, then A will also think that C is popular, even if this is not explicitly specified by an ordered pair in the input. Your task is to compute the number of cows that are considered popular by every other cow.

    输入

    Multiple test case. For each case :

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

    Lines 2..1+M:  Two space-separated numbers A and B, meaning that A thinks B is popular.

    输出

    Description

    Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 ≤ N ≤ 10,000) cows, you are given up to M (1 ≤ M ≤ 50,000) ordered pairs of the form (A, B) that tell you that cow A thinks that cow B is popular. Since popularity is transitive, if A thinks B is popular and B thinks C is popular, then A will also think that C is popular, even if this is not explicitly specified by an ordered pair in the input. Your task is to compute the number of cows that are considered popular by every other cow.

    Input

    Multiple test case. For each case :

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

    Lines 2..1+M:  Two space-separated numbers A and B, meaning that A thinks B is popular.

    Output

    For each case, output one line :  A single integer that is the number of cows who are considered popular by every other cow.

    Sample Input

    3 3
    1 2
    2 1
    2 3

    Sample Output

    1

    Hint

    Cow 3 is the only cow of high popularity.

    Source

    样例输入

    3 3
    1 2
    2 1
    2 3

    样例输出

    1

    提示

    Cow 3 is the only cow of high popularity.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部