QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB 总分: 100

#8603. Food Chain

统计

The figure below shows a food web of an ecosystem.

Figure 1: A food web diagram.

Given $n$ species and $m$ energy flow relationships, calculate the total number of food chains in the ecosystem.

Species are numbered from $1$ to $n$.

The $m$ energy flow relationships are given as: $a_1 \ b_1$ $a_2 \ b_2$ $a_3 \ b_3$ ... $a_{m-1} \ b_{m-1}$ $a_m \ b_m$

Where $a_i \ b_i$ indicates that energy flows from species $a_i$ to species $b_i$.

Input

The first line contains two integers $n$ and $m$.

The next $m$ lines each contain two integers $a_i$ and $b_i$, describing the $m$ energy flow relationships.

(The data is guaranteed to follow biological characteristics, and there will be no duplicate energy flow relationships.)

Output

A single integer representing the number of food chains in the food web.

Constraints

$1 \le N \le 100000$ $0 \le m \le 200000$ The answer is guaranteed to fit within a standard 32-bit signed integer.

Examples

Input 1

10 16
1 2
1 4
1 10
2 3
2 5
4 3
4 5
4 8
6 5
7 6
7 9
8 5
9 8
10 6
10 7
10 9

Output 1

9

Note

The example refers to the diagram in Figure 1. The species are numbered as follows: Grass: 1, Rabbit: 2, Fox: 3, Mouse: 4, Owl: 5, Insectivorous bird: 6, Spider: 7, Snake: 8, Frog: 9, Herbivorous insect: 10.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.