#P11073. Duel of Reachability

    ID: 13129 Type: Default 1000ms 256MiB

Duel of Reachability

Duel of Reachability

You have traversed into the world of Duel Monsters, and now you find yourself dueling your opponent – a directed graph with \(n\) vertices and \(m\) edges. In this duel, every move is fated.

To better prepare for the duel, you must count how many vertices \(x\) satisfy the following condition:

  • For every vertex \(y\) (we consider a vertex can reach itself), either there is a directed path from \(x\) to \(y\) or from \(y\) to \(x\).

In other words, vertex \(x\) is comparable with every vertex \(y\) in terms of reachability.

inputFormat

The first line of input contains two integers \(n\) and \(m\) \((1 \leq n, m \leq 10^5)\) representing the number of vertices and the number of directed edges, respectively.

Each of the following \(m\) lines contains two integers \(u\) and \(v\) (\(1 \leq u, v \leq n\)), indicating a directed edge from vertex \(u\) to vertex \(v\).

outputFormat

Output a single integer: the number of vertices \(x\) that satisfy the stated reachability condition.

sample

3 3
1 2
2 3
1 3
3

</p>