#P7516. [省选联考 2021 A/B 卷] 图函数

[省选联考 2021 A/B 卷] 图函数

Description

For a directed graph GG with nn vertices and mm edges (vertices are numbered from 11 to nn), define the function f(u,G)f(u, G):

  1. Initialize the return value cnt=0cnt = 0, and set G=GG' = G.
  2. Enumerate vertices vv from 11 to nn in order. If, in the current graph GG', there exists a path from uu to vv and also a path from vv to uu, then increase cntcnt by 11, and delete vertex vv from GG' together with all edges incident to it.
  3. After step 2 ends, return cntcnt as the function value.

Now you are given a directed graph GG. Compute h(G)=f(1,G)+f(2,G)++f(n,G)h(G) = f(1, G) + f(2, G) + \cdots + f(n, G).

Furthermore, let GiG_i (1im1 \le i \le m) be the graph after deleting edges 11 through ii (in the input order). Compute all values h(Gi)h(G_i).

Input Format

The first line contains two integers n,mn, m, denoting the number of vertices and the number of edges in the graph.
The next mm lines each contain two integers. The two integers xi,yix_i, y_i on line ii represent a directed edge xiyix_i \to y_i.

The data guarantees that xiyix_i \neq y_i, and no edge is given more than once.

Output Format

Output one line with m+1m + 1 integers. The first integer is h(G)h(G) for the complete graph GG. The ii-th integer (2im+12 \le i \le m + 1) is h(Gi1)h(G_{i-1}).

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

6 5 5 4 4 4 4

见附件中的 graph/graph2.in。
见附件中的 graph/graph2.ans。

Hint

[Sample #1 Explanation]

For the complete graph GG:

  1. f(1,G)=1f(1, G) = 1, and vertex 11 is deleted during the process.
  2. f(2,G)=1f(2, G) = 1, and vertex 22 is deleted during the process.
  3. f(3,G)=2f(3, G) = 2, and vertices 2,32, 3 are deleted during the process.
  4. f(4,G)=2f(4, G) = 2, and vertices 1,41, 4 are deleted during the process.

[Constraints]

For all testdata: 2n1032 \le n \le {10}^3, 1m2×1051 \le m \le 2 \times {10}^5, 1xi,yin1 \le x_i, y_i \le n.

The specific limits for each test point are shown in the table below:

Test Point ID nn \le mm \le
141 \sim 4 1010
5115 \sim 11 100100 2×1032 \times {10}^3
122012 \sim 20 103{10}^3 5×1035 \times {10}^3
212521 \sim 25 2×1052 \times {10}^5

Translated by ChatGPT 5