QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#12095. Acyclic Decomposition

统计

Byteman is studying directed graphs. He especially likes graphs which do not contain cycles, since this is a class of graphs in which many problems can be solved easily and effectively. Now he is trying to find a method of representing any directed graph as a sum of acyclic graphs.

For a given directed graph he is trying to find a way to divide the set of its edges into a minimal number of subsets in such a way that the graphs constructed using the respective subsets of edges do not contain cycles. Could you write a program which solves Byteman's problem?

Input Format

The first line of the standard input contains two integers $n$ and $m$ ($1 ≤ n, m ≤ 100\,000$), denoting the number of vertices and the number of edges in the graph, respectively. The vertices are numbered from $1$ to $n$. Each of the following $m$ lines contains a description of one edge of the graph as a pair of integers $a_{i}$, $b_{i}$ ($1 ≤ a_{i}, b_{i} ≤ n$, $a_{i} ≠ b_{i}$). Such a pair denotes a directed edge of the graph from the vertex $a_{i}$ to the vertex $b_{i}$. You may assume that the graph does not contain multiple edges.

Output Format

The first line of the standard output should contain a single integer $k$ - the minimal number of acyclic graphs in any decomposition of the graph. Each of the following $k$ lines should contain a description of one element of the decomposition, starting with an integer $l_{i}$ denoting the number of edges in the ith element. It should be followed by an increasing sequence of $l_{i}$ numbers of edges belonging to the ith element of the decomposition. The edges are numbered from $1$ to $m$ in the order in which they appear in the input. Each edge should be present in exactly one element of the decomposition.

If there are multiple correct solutions, your program should output any one of them.

Example

Input

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

Output

2
2 3 5
3 1 2 4
problem_12095_1.gif

Illustration of the example from the task statement. The circles represent the vertices, while the lines and arcs (continuous and dashed) represent the edges of the graph. The numbers next to the circles are the numbers of the vertices, and the numbers next to the lines/arcs are the numbers of edges. This graph can be decomposed into two acyclic graphs: the edges of the first one are denoted by continuous lines/arcs and the edges of the second one - by dashed lines/arcs.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.