Fight in Friends

5

1 votes
Problem

In a parallel world,there is an peaceful college, where everyone is united to everyone. But in recent times due to some unseen circumstances, there has been fights between some friends and due to this the college is no more that united.

In the college, an announcement need to be made. But due to the fights some students do not talk to each other. Announcement will be told to one student and will be asked to deliver to all other students, but since he does not talk to one or many students, he will not be deliver the announcement to every student in the college.He will deliver the announcement to all his friends and then ask them to tell the announcement to their friends, In this way it will take some time for the announcement to get delivered to some other person.

Consider that if a student gets a announcement at time t then all his friends will get the announcement at time t+1.

Given two students, if news is given to student a at time 0, calculate the time at which the student b will get the news for the first time.

Constraints :

1 < n <= 10^3

0 <= m <= 10^6

1<= i,j,a,b <=N

Input :

First line contain n, m, a, b denoting

n : number of students

m: number of pairs not talking to each other

Student a whom the news is delivered to

Student b to whom the news need to be delivered to.

M lines follow each containing a pair of integers i, j such that i and j are not talking to each other.

Output :

A single integer t the time at which the news gets delivered to the Student b.

If the news does not gets delivered at any time output -1.

To be eligible for prizes you have to register for AlgoXtreme at the Zeitgeist site. To register visit Zeitgeist. Only those candidates who have registered on the Zeitgeist website for the AlgoXtreme contest will be eligible to avail the Prizes.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?