Street Racing
The organizing committee of the Azure Coast-99 cycling race has approached the Saint-Tropez gendarmerie with a request to hold the race through the streets of this resort town, allowing each participant some freedom in choosing their path to the finish line. In response, the gendarmerie provided the committee with a race plan. This plan marks intersection points with circles, numbered with natural numbers from 1 to a certain number n, and indicates one-way streets with arrows. On this plan:
The start is a point from which any point in the race can be reached, but it cannot be reached from any other point.
The finish is a point that can be reached from any other point, but no other point can be reached from it.
Some points are unavoidable on the path from start to finish, excluding the final ones.
Certain unavoidable points on the path from start to finish can divide the race plan into two separate plans. Specifically:
Each newly formed plan contains points different from the start and finish of that plan.
The newly formed plans do not share any arrows but have a single common point, which serves as the finish for one plan and the start for another. This common point cannot be reached by moving along the arrows starting from itself.
Create a program to assist the organizing committee in analyzing the submitted plan.
Input
The number of rows equals the total number of race points n (n ≤ 222). For each j from 1 to n, the j-th row lists the endpoint numbers of the arrows originating from the j-th point.
Output
The first row should list, in order, the numbers of the points that are the start and finish.
The second row should include the number of points that cannot be avoided on the path from start to finish, followed by these points' numbers in ascending order.
The third row should state the number of points by which the race plan can be divided into separate plans, followed by these points' numbers in ascending order.