
You have been given a perfect model of the botanic garden, consisting of $$$n$$$ intersections (numbered from $$$1$$$ to $$$n$$$) and $$$m$$$ footpaths going between those. To keep order, each footpath can only be used in the given direction. Currently, the plants are exhibiting $$$k$$$ different colours (numbered from $$$1$$$ to $$$k$$$) and for each footpath, you are given a list of all the colours that are visible along it when viewed from the intersection where it starts. A user is currently at intersection $$$1$$$ and wants to navigate to intersection $$$n$$$. You can assume that the user will follow the app's directions perfectly, but whenever faced with multiple options (because the given colour is visible along multiple footpaths), you have to assume they will make the worst possible choice. How long will it take to reach the target when your app gives the best possible instructions?
The input consists of:
The sum of $$$\ell$$$ over all footpaths does not exceed $$$5 \cdot 10^5$$$. Note that, as you would imagine in a botanic garden, a footpath can lead back to the intersection it started from and multiple footpaths can exist between a pair of intersections. Moreover, it is not guaranteed that each intersection can be reached via the footpaths.
If it is impossible to lead the user to intersection $$$n$$$, output impossible. Otherwise output a single integer, the time it will take to reach the target in seconds. We are only considering the time spent walking along the footpaths.
4 6 21 2 61 11 3 31 22 3 51 22 4 81 13 1 42 1 23 4 31 1
14
3 4 31 2 3002 1 22 1 20002 3 11 3 802 2 12 2 421 2
impossible
| Название |
|---|


