#P7516. [省选联考 2021 A/B 卷] 图函数
[省选联考 2021 A/B 卷] 图函数
Description
For a directed graph with vertices and edges (vertices are numbered from to ), define the function :
- Initialize the return value , and set .
- Enumerate vertices from to in order. If, in the current graph , there exists a path from to and also a path from to , then increase by , and delete vertex from together with all edges incident to it.
- After step 2 ends, return as the function value.
Now you are given a directed graph . Compute .
Furthermore, let () be the graph after deleting edges through (in the input order). Compute all values .
Input Format
The first line contains two integers , denoting the number of vertices and the number of edges in the graph.
The next lines each contain two integers. The two integers on line represent a directed edge .
The data guarantees that , and no edge is given more than once.
Output Format
Output one line with integers. The first integer is for the complete graph . The -th integer () is .
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 :
- , and vertex is deleted during the process.
- , and vertex is deleted during the process.
- , and vertices are deleted during the process.
- , and vertices are deleted during the process.
[Constraints]
For all testdata: , , .
The specific limits for each test point are shown in the table below:
| Test Point ID | ||
|---|---|---|
Translated by ChatGPT 5
京公网安备 11011102002149号