Messy Kevin X
Kevin's been studying hard to go from being messy and clumsy to being knowledgeable and organised. He's been grinding data structures and algorithms study and has been diligently practicing LeetCodes every day. He's even participated in a few AUCPL rounds!
Feeling more confident about his ability to get (and retain) a job, he has started looking at job openings. All of the jobs he is applying to seem to have some requirements for applying, so Kevin decides to create a directed acyclic graph of different things he needs to learn and also achieve before he can apply. Each node of the graph represents a task that must be achieved and each task has some prerequisites.
Given the starting point, what is the minimum of tasks he needs to complete to reach the end goal?
Input
The first line contains integers
and
, the nodes and directed edges of the graph.
The next lines contain two integers
and
, a directed edge that goes from node
to node
. Note that the nodes are numbered
through
.
The last two lines consist of and
, the start and end node.
Output
Output the minimum number of tasks Kevin must complete to reach the goal. If there is no valid path from the start to the end, output .
Example
Input 1
5 4
1 2
1 3
2 4
3 5
1
5
Output 1
3
Kevin starts at task and wants to reach task
. A valid progression path is
. Kevin therefore completes
tasks.
Input 2
4 2
1 2
2 3
1
4
Output 2
-1
There is no way to get from task to task
.
Comments