#P4802. Longest Path

    ID: 18046 Type: Default 1000ms 256MiB

Longest Path

Longest Path

This problem is adapted from CCO 2015 Day1 T2, Artskjid.

Troy loves to travel leisurely during his vacations. Instead of finding the shortest route via GPS, he wants to take the longest possible route from his starting city 11 to his destination city nn so that he can discover many new and interesting places.

A valid path is a sequence of distinct cities c1,c2,,ckc_1, c_2, \ldots, c_k such that for each 1i<k1 \leq i < k, there exists a road from cic_i to ci+1c_{i+1}.

Your task is to find the longest such path. If no valid path exists, output "IMPOSSIBLE".

inputFormat

The first line contains two integers nn and mm (2n105, 1m105)(2 \le n \le 10^5,\ 1 \le m \le 10^5), representing the number of cities and the number of roads respectively.

Each of the next mm lines contains two integers aa and bb (1a,bn)(1 \le a, b \le n), indicating a directed road from city aa to city bb.

outputFormat

If there is no valid path from city 11 to city nn, output a single line with the text "IMPOSSIBLE".

Otherwise, the first line should contain an integer representing the number of cities in the longest path, and the second line should list the cities in order, separated by spaces.

sample

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

1 2 3 5

</p>