#P2863. [USACO06JAN] The Cow Prom S

[USACO06JAN] The Cow Prom S

Description

Given a directed graph with nn vertices and mm edges, find the number of strongly connected components that contain more than 1 vertex.

Input Format

The first line contains two integers nn and mm.

Lines 2 through m+1m+1, each line contains two integers aa and bb, indicating a directed edge from aa to bb.

Output Format

Output a single line containing the number of strongly connected components with more than 1 vertex.

5 4
2 4
3 5
1 2
4 1
1

Hint

Constraints

For all test points, it is guaranteed that 2n1042 \le n \le 10^4, 2m5×1042 \le m \le 5 \times 10^4, 1a,bn1 \le a, b \le n.

Translated by ChatGPT 5