Problem I
3019

The year is 3019, and the world is experiencing a pandemic named COVID-19 (which, for some reason, sounds hauntingly familiar). Tragically, it is transmitted through tropospheric air and very potent, so the various communities of the world have transitioned to living underground in $n$ underground bases, conveniently named using the integers from 1 to $n$. In order to share resources between each other, humanity has developed $m$ one-way portals, which each have a start point in one base and an endpoint in a different base.
Fortunately, it was recently made public that a brilliant scientist has created a cure for COVID-19! Although the cure has not started being industrially manufactured as of yet, it is a product of such importance that the plan for its distribution is already known: autonomous drones will begin at each production facility and will travel from base to base, delivering the cure. In fact, the first facility for its mass-production is already underway as well. More will inevitably come later, but it would be preferable for the first one to be located at a base which allows a single drone that starts there to reach a maximal number of bases in a single trip (by transporting the cures across bases through some series of portals, possibly passing through some bases or portals more than once). Given the layout of bases and portals, find a set of bases that can all be reached from a single base by going through some route of portals such that this set of bases has maximum size.
Input
The input consists of a single test case. The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100\, 000$) where $n$ denotes the number of bases and $m$ denotes the number of one-way portals. Each of the following $m$ lines contains two integers $a_ i$ and $b_ i$ ($1 \le a_ i, b_ i\le n$), where $i \in \{ 1, 2, \ldots , m\} $, which denote the bases at the start point and endpoint of portal $i$, respectively.
It is guaranteed no ordered pair of two bases is directly connected by more than one portal and that no portal has its start point and endpoint within the same base.
Output
Output three lines. The first line should specify the maximum number of bases that meet the conditions specified in the problem. The second line should print all of those bases in any order, including the start base. Although the drone is allowed to enter the same base multiple times during its trip, each should be printed only a single time. Leave spaces between all integer numbers on the same line. The third line should specify the base at which the production facility should be located.
If there are multiple possible solutions, you may print any of them.
Sample Input 1 | Sample Output 1 |
---|---|
4 3 2 1 2 3 2 4 |
2 2 3 2 |
Sample Input 2 | Sample Output 2 |
---|---|
5 4 1 2 1 3 1 4 4 5 |
3 1 4 5 1 |
Sample Input 3 | Sample Output 3 |
---|---|
6 6 1 2 2 3 3 4 4 5 5 6 6 1 |
6 2 3 4 6 1 5 4 |
Sample Input 4 | Sample Output 4 |
---|---|
19 23 1 10 10 9 9 8 8 7 7 3 3 1 10 2 8 12 11 6 11 12 6 11 17 4 4 5 17 16 13 14 14 15 13 19 2 12 16 15 19 6 15 13 13 17 17 18 |
9 6 11 12 13 14 15 16 17 19 13 |