AlgoUniversity
  • Go Back
Avoid Cities :

Author

admin

Difficulty Level : Easy

Submissions : 9000

Asked In :

Marks :10

: 68 | : 19

There are $$$N$$$ cities with $$$M$$$ bi-directional roads between them. You want to travel from a given source city to target city. But there are some cities that you cannot visit because they are cursed.

Find the smallest number of roads that you should take to complete your travel and output it. If it is not possible to do so output $$$-1$$$.

$$$1 \leq N \leq 10^5$$$ $$$0 \leq M \leq 2 \times 10^5$$$

Input

The first line contains two integers $$$N$$$ and $$$M$$$ denoting the number of cities and the number of roads respectively.

The second line contains two integers: source and target.

The third line contains $$$N$$$ integers which are either $$$0$$$ or $$$1$$$ denoting whether each city is cursed or not. ($$$1$$$ means that the city is cursed.)

Finally, there are $$$M$$$ lines containing $$$2$$$ integers each $$$u$$$ and $$$v$$$ denoting that there is a road between city $$$u$$$ and city $$$v$$$.

Output

Output the smallest number of roads that you should take to complete your travel and output it. If it is not possible to do so output $$$-1$$$.

Example

Input
5 5
0 2
0 1 0 0 0
0 1
1 2
0 3
3 4
4 2
Output
3

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.