Each turn the opponent picks a step count from three values and you walk exactly that many directed edges, racing to end a turn on node N in the fewest turns.
Medium7Game theoryGraphDynamic programmingNo attempts yetTime limit2sMemory limit256 MBHyeonseong plays a game with his older brother Hyeonmin. The game runs on a fixed map.
The map has N circles and M arrows drawn on it. Each arrow joins two different circles, and the piece may pass along an arrow only in the direction it points.
At the start the piece sits on circle 1. On every turn Hyeonmin says one integer that is at least 1, and Hyeonseong moves the piece that many times. A single move takes the piece along one arrow to the circle at its head.
Hyeonseong wins if the piece stands on circle N once all moves of that turn are done. Passing through circle N while moves are still left does not end the game. If the piece runs out of arrows to follow before the moves are done, Hyeonmin wins. Hyeonmin also wins if the game goes on forever.
Hyeonmin is smart enough to have finished second on a brain survival show, so he kept winning every game. To spare his brother, he decided to go easy: at the start of each turn he now picks the number he says from a, b, and c only. Even then Hyeonseong never beat him.
Hyeonseong has run out of confidence and asks you for a strategy that beats Hyeonmin. Each turn Hyeonmin looks at the position of the piece and says the number that is best for himself, and Hyeonseong decides how to move only after hearing that number. Assuming both play as well as possible, decide whether Hyeonseong can win, and if he can, find the smallest number of turns needed to finish the game.
The first line contains N, M, a, b, and c. Here N is the number of circles, M is the number of arrows, and a, b, c are the numbers Hyeonmin may say. (2≤N≤50, 0≤M≤N(N−1), 1≤a,b,c≤100)
Each of the next M lines contains the tail u and the head v of one arrow. (1≤u,v≤N, u=v) No two arrows share both their tail and their head.
Print IMPOSSIBLE if Hyeonseong cannot beat Hyeonmin. Otherwise print the smallest number of turns he needs to win.
In the first example Hyeonmin says 1 and 2 in turn, the game never ends, and Hyeonmin wins.
In the second example this strategy works.

The map of the second example