#P3183. [HAOI2016] 食物链

    ID: 2232 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划,dp搜索2016河南各省省选记忆化搜索

[HAOI2016] 食物链

Description

The figure shows a schematic food web of an ecosystem. You are given nn species and mm energy-flow relations; compute the number of food chains. Species are labeled from 11 to nn. The mm energy-flow relations are given as pairs $a_1, b_1, a_2, b_2, a_3, b_3, \ldots, a_{m-1}, b_{m-1}, a_m, b_m$, where aia_i and bib_i mean that energy flows from species aia_i to species bib_i. Note that a single isolated species does not count as a food chain.

Input Format

The first line contains two integers n,mn, m. The next mm lines each contain two integers aia_i and bib_i describing the mm energy-flow relations.

Output Format

Output a single integer: the number of food chains in the food web.

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
9

Hint

The testdata guarantee that the input conforms to biological properties, and there are no duplicate energy-flow relations. The answer is guaranteed not to overflow a 32-bit signed int.

Constraints: for 100%100\% of the testdata, 1n1000001 \leq n \leq 100000, 0m2000000 \leq m \leq 200000.

Translated by ChatGPT 5