#P6134. [JSOI2015] 最小表示

[JSOI2015] 最小表示

Description

Given a directed graph with NN vertices (each vertex is numbered from 11 to NN) and MM edges, JYY found that if some edges are deleted from the graph, the connectivity of the original graph may change; meanwhile, there are also some edges such that deleting them will not change the connectivity of the graph.

JYY wants to know: if we want to keep the connectivity between any two vertices in the original graph unchanged, what is the maximum number of edges we can delete?

To simplify the workload, this time JYY guarantees that the given directed graph is a directed acyclic graph (DAG) (JYY: after last year’s problem, everyone knows that problems on arbitrary directed graphs can eventually be transformed into problems on DAGs, so this year JYY simply made it easier).

Input Format

The first line contains two positive integers NN and MM.

The next MM lines each contain two positive integers xix_i and yiy_i between 11 and NN, indicating that there is a directed edge from xix_i to yiy_i in the graph.

The input guarantees that between any two vertices, there is at most one edge.

Output Format

Output one line containing one integer, which is the maximum number of edges that JYY can delete.

5 6
1 2
2 3
3 5
4 5
1 5
1 3
2

Hint

Sample Explanation

One valid plan is to delete 151\rightarrow 5 and 131\rightarrow 3. It is easy to prove that there is no better answer than 22.

Constraints

For 100%100\% of the data, 1N3×1041 \leq N\leq 3\times 10^4, 0M1050 \leq M\leq 10^5.

Translated by ChatGPT 5