#graph102. 受欢迎的牛

受欢迎的牛

Popular Cows

Problem Source

HAOI 2006

Problem Description

Every cow's dream is to become the most popular cow.

Now there are NN cows. You are given MM pairs of integers (A,B)(A, B), meaning cow AA thinks cow BB is popular. This relation is transitive: if AA thinks BB is popular and BB thinks CC is popular, then AA also thinks CC is popular. Your task is to find out how many cows are considered popular by all the cows.

Input Format

The first line contains two integers N,MN, M (1≤N≤104, 0≤M≤5×1041 \leq N \leq 10^4,\ 0 \leq M \leq 5 \times 10^4). The next MM lines each contain two integers A,BA, B, meaning AA thinks BB is popular. (The information may be repeated, i.e. the same pair (A,B)(A, B) may appear multiple times.)

Output Format

Output one number: how many cows are considered popular by all the cows.

Sample Input

3 3
1 2
2 1
2 3

Sample Output

1

Constraints

  • 1≤N≤1041 \leq N \leq 10^4
  • 0≤M≤5×1040 \leq M \leq 5 \times 10^4