#P7251. [JSOI2014] 强连通图

[JSOI2014] 强连通图

Description

JYY has recently become obsessed with strong connectivity in graphs. For any directed graph, JYY wants to add some edges to make the graph strongly connected. Now JYY is given a directed graph with nn vertices and mm edges, where the vertices are numbered from 11 to nn.

JYY wants to know:

  • In the given graph, what is the maximum number of vertices that can be chosen such that every pair of these vertices is mutually reachable in the original graph?

  • In the given graph, what is the minimum number of edges that need to be added to make the graph strongly connected?

A directed graph G(V,E)G(V,E) is strongly connected if and only if for any two distinct vertices a,bV,aba,b\in V, a\neq b, there exist paths aba\to b and bab\to a.

Input Format

The first line contains two integers nn and mm.

The next mm lines each contain two integers xx and yy, indicating that there is a directed edge from xx to yy in the graph.

Output Format

Output two lines. The first line is the answer to the first question, and the second line is the answer to the second question.

4 3
1 4
2 3
2 4
1
2

Hint

Sample Explanation 1

For the first question, it is impossible to choose two vertices that are mutually reachable, so the answer is 11.

For the second question, one optimal way with the minimum number of added edges is (3,1)(3,1) and (4,2)(4,2), so the answer is 22.

Constraints

For 100%100\% of the testdata, 1n105,1m3×1051\leq n\leq 10^5,1\leq m\leq 3\times 10^5.

Translated by ChatGPT 5