2186 POJ Popular Cows

Popular Cows
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 34191 Accepted: 13925

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

* 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

* Line 1: A single integer that is the number of cows who are considered popular by every other cow.

Sample Input

Sample Output

Hint

Cow 3 is the only cow of high popularity.

Source

找一遍强连通子图,然后染色,一个图至多有一个颜色出度为零的点,所以要特殊判断一次,
此外,对于每个点,若是它所到达的点与它不是同一色,就给这个点所属颜色的出度+1,最后根据颜色的出度进行答案的统计,只有出度为零才ans++;

 

9 + 3 =