BZOJ1051 [HAOI2006] Popular Cattle

Source: Internet
Author: User

Description the desire of every cow is to become one of the most popular cows. Now there are n cows, give you m-pairs of integers (a, a, b), indicating that cow A is considered to be popular. This relationship is transitive, and if a thinks B is popular, B thinks C is popular, then bull a also thinks that Ox C is popular. Your task is to find out how many cows are considered popular by all cows. Input first row two number n,m. Next m line, two numbers per line, A, B, meaning that A is considered a welcome (the information given may be repeated, that is, there may be multiple, b) Output

A number, that is, how many cows are considered popular by all cows.

Sample Input3 3
1 2
2 1
2 3Sample Output1HINT100% data n<=10000,m<=50000 positive solution: Tarjan Problem Solving report: With POJ on the same topic, previously wrote the problem, Portal:http://www.cnblogs.com/ljh2000-jump/p/5628445.html

BZOJ1051 [HAOI2006] Popular Cattle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.